Skip to content

Conversation

@avik-pal
Copy link
Member

@avik-pal avik-pal commented Dec 5, 2025

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @avik-pal, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly streamlines the testing infrastructure by consolidating backend-specific package installation and detection logic into the LuxTestUtils library. This refactoring reduces code duplication across various test suites, making the overall testing setup more modular, maintainable, and easier to understand. The change primarily impacts how test environments are configured and how backend-specific dependencies are managed, without altering the core functionality of the tests themselves.

Highlights

  • Centralized Test Package Installation: The logic for determining and installing extra packages required for testing different backends (CUDA, AMDGPU, Metal, oneAPI) has been centralized into new utility functions within LuxTestUtils.
  • Refactored Backend Detection: Conditional checks for backend availability and group-based testing (BACKEND_GROUP == "all" || BACKEND_GROUP == "cuda") have been replaced with calls to new LuxTestUtils.test_backend() functions, improving consistency and readability.
  • New Utility File: A new file, lib/LuxTestUtils/src/package_install.jl, was added to house the new backend detection and package installation logic.
  • Dependency Updates: LuxTestUtils now explicitly depends on Pkg, and its version has been incremented to 2.1.0.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@avik-pal avik-pal force-pushed the ap/test_locally branch 2 times, most recently from 73f838c to ce4b2d0 Compare December 5, 2025 22:40
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the test package installation logic across the repository into a centralized utility within LuxTestUtils. While this is a good step towards streamlining the test setup, the new implementation in package_install.jl contains a couple of critical bugs. The hardware detection for CUDA is logically inverted, and the generated test_* functions for different backends have flawed logic that could lead to installing incorrect packages. Additionally, the refactoring removes the existing functionality for testing against a local development version of LuxCUDA, which could impact developer workflows. I've provided detailed comments and suggestions to fix these issues.

@avik-pal avik-pal force-pushed the ap/test_locally branch 2 times, most recently from 8f8fb4f to 5fa6e2e Compare December 5, 2025 22:46
@avik-pal
Copy link
Member Author

avik-pal commented Dec 5, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great initiative to refactor and centralize the test package installation logic into LuxTestUtils, which significantly reduces code duplication across multiple test suites and improves maintainability. However, the current implementation in the new lib/LuxTestUtils/src/package_install.jl file contains a few critical bugs related to hardware detection and test backend selection logic. I've provided specific comments and suggestions to address these issues. Once these are resolved, this will be a very valuable improvement to the test infrastructure.

Comment on lines +1 to +7
function has_cuda()
try
return run(`nvidia-smi -L`) === nothing ? false : true
catch
return false
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The logic in has_cuda is inverted. run("...") returns nothing on success. nothing === nothing is true, so the ternary expression ... ? false : true evaluates to false on success. This means the function incorrectly reports that CUDA is not available when it is. This should be corrected to return true on success.

function has_cuda()
    try
        run(`nvidia-smi -L`)
        return true
    catch
        return false
    end
end

Comment on lines +24 to +32
for backend_group in ("cuda", "amdgpu", "metal", "oneapi")
fnanme = Symbol(:test_, backend_group)
has_fnname = Symbol(:has_, backend_group)
@eval function $(fnanme)(backend_group::String="all")
backend_group == $(QuoteNode(backend_group)) && return true
$(has_fnname)($(QuoteNode(backend_group))) && return true
return false
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The metaprogramming logic for generating test_* functions has two critical issues:

  1. It calls the has_* functions (e.g., has_cuda) with an argument on line 29, but they are defined without any. This will cause a MethodError.
  2. The logical structure is flawed. For example, test_cuda("amdgpu") will evaluate has_cuda(). This means if you have CUDA hardware but want to run only AMDGPU tests, it will still evaluate to true, causing CUDA packages to be installed. The logic should restrict checks to the specified backend_group or "all".

A corrected implementation is suggested below. I've also taken the liberty to fix a typo (fnanme -> fname) and rename a variable to avoid shadowing.

for backend in ("cuda", "amdgpu", "metal", "oneapi")
    test_fn = Symbol(:test_, backend)
    has_fn = Symbol(:has_, backend)
    @eval function $(test_fn)(backend_group::String="all")
        return backend_group == $(QuoteNode(backend)) ||
               (backend_group == "all" && $(has_fn)())
    end
end

Comment on lines +20 to +22
function has_oneapi()
return isdir("/dev/dri") && any(occursin("render", f) for f in readdir("/dev/dri"))
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The has_oneapi function does not handle potential IOError or SystemError if readdir("/dev/dri") is called without sufficient permissions. This can crash the test setup script. It's safer to wrap this logic in a try-catch block, similar to has_cuda and has_amdgpu.

function has_oneapi()
    try
        return isdir("/dev/dri") && any(occursin("render", f) for f in readdir("/dev/dri"))
    catch
        return false
    end
end

test_cuda(backend_group) && push!(pkgs, PackageSpec(; name="CUDA"))
test_amdgpu(backend_group) && push!(pkgs, PackageSpec(; name="AMDGPU"))
test_metal(backend_group) && push!(pkgs, PackageSpec(; name="Metal", version="1.9"))
test_oneapi(backend_group) && push!(pkgs, PackageSpec("oneAPI"))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with the other PackageSpec creations in this function, it's better to use the keyword argument constructor. This improves readability and maintainability.

    test_oneapi(backend_group) && push!(pkgs, PackageSpec(; name="oneAPI"))

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

Benchmark Results (Julia v1.11)

Time benchmarks
main 4f33a9c... main / 4f33a9c...
basics/MHA 3.51 ± 1.3 μs 3.44 ± 0.27 μs 1.02 ± 0.38
basics/MHA (first run) 3.61 ± 0.65 μs 3.77 ± 1.3 μs 0.959 ± 0.38
basics/MHA reactant 0.0602 ± 0.0085 ms 0.0635 ± 0.0086 ms 0.948 ± 0.18
basics/MHA reactant (comp + run) 0.146 ± 0.0035 s 0.149 ± 0.0042 s 0.981 ± 0.037
basics/conv 15.4 ± 12 μs 14.3 ± 10 μs 1.08 ± 1.1
basics/conv (first run) 12.2 ± 1.9 μs 12.8 ± 8 μs 0.957 ± 0.62
basics/conv reactant 0.0499 ± 0.0024 ms 0.0515 ± 0.0046 ms 0.969 ± 0.099
basics/conv reactant (comp + run) 0.108 ± 0.0039 s 0.108 ± 0.0026 s 0.997 ± 0.043
basics/dense 0.13 ± 0.001 μs 0.131 ± 0.003 μs 0.992 ± 0.024
basics/dense (first run) 0.149 ± 0.012 μs 0.132 ± 0.003 μs 1.13 ± 0.094
basics/dense reactant 0.0463 ± 0.0023 ms 0.0474 ± 0.0023 ms 0.976 ± 0.068
basics/dense reactant (comp + run) 0.0892 ± 0.0024 s 0.0882 ± 0.0022 s 1.01 ± 0.037
time_to_load 0.866 ± 0.011 s 0.873 ± 0.018 s 0.992 ± 0.024
Memory benchmarks
main 4f33a9c... main / 4f33a9c...
basics/MHA 0.087 k allocs: 6.05 kB 0.087 k allocs: 6.05 kB 1
basics/MHA (first run) 0.087 k allocs: 6.05 kB 0.087 k allocs: 6.05 kB 1
basics/MHA reactant 19 allocs: 0.578 kB 19 allocs: 0.578 kB 1
basics/MHA reactant (comp + run) 18 k allocs: 1.37 MB 18 k allocs: 1.37 MB 1
basics/conv 0.038 k allocs: 5.12 kB 0.038 k allocs: 5.12 kB 1
basics/conv (first run) 0.038 k allocs: 5.12 kB 0.038 k allocs: 5.12 kB 1
basics/conv reactant 15 allocs: 0.438 kB 15 allocs: 0.438 kB 1
basics/conv reactant (comp + run) 6.15 k allocs: 0.813 MB 6.14 k allocs: 0.813 MB 1
basics/dense 2 allocs: 0.109 kB 2 allocs: 0.109 kB 1
basics/dense (first run) 2 allocs: 0.109 kB 2 allocs: 0.109 kB 1
basics/dense reactant 15 allocs: 0.422 kB 15 allocs: 0.422 kB 1
basics/dense reactant (comp + run) 5.9 k allocs: 0.796 MB 5.9 k allocs: 0.796 MB 1
time_to_load 0.159 k allocs: 11.2 kB 0.159 k allocs: 11.2 kB 1

@mergify
Copy link

mergify bot commented Dec 6, 2025

🧪 CI Insights

Here's what we observed from your CI run for 4f33a9c.

🟢 All jobs passed!

But CI Insights is watching 👀

@codecov
Copy link

codecov bot commented Dec 6, 2025

Codecov Report

❌ Patch coverage is 0% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 22.92%. Comparing base (e203e27) to head (4f33a9c).

Files with missing lines Patch % Lines
lib/LuxTestUtils/src/package_install.jl 0.00% 25 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (e203e27) and HEAD (4f33a9c). Click for more details.

HEAD has 45 uploads less than BASE
Flag BASE (e203e27) HEAD (4f33a9c)
49 4
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1583       +/-   ##
===========================================
- Coverage   82.50%   22.92%   -59.59%     
===========================================
  Files         171      160       -11     
  Lines        7076     6954      -122     
===========================================
- Hits         5838     1594     -4244     
- Misses       1238     5360     +4122     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants