Repository navigation
Installer: GPU detection follow-ups after #6174 (poisoned venv repair, llama.cpp routing, probe bounds) - #6183
Conversation
Ports the NVIDIA-priority and /proc/driver/nvidia/gpus hardening from #6174 to the remaining pathways and adds recovery for already-poisoned venvs: - install_python_stack.py: add _ensure_cuda_torch so 'unsloth studio update' force-reinstalls CUDA torch when the venv carries a ROCm build on an NVIDIA Linux host (the pre-#6174 poisoning signature). Honors UNSLOTH_TORCH_BACKEND, UNSLOTH_ROCM_TORCH_INSTALLED, and CUDA_VISIBLE_DEVICES=-1/'' opt-outs; never touches healthy CUDA, deliberate CPU wheels, macOS, or Windows. - install_llama_prebuilt.py: detect_host gains the /proc NVIDIA fallback and skips ROCm probes when NVIDIA is usable; forwarded --rocm-gfx/--has-rocm overrides still win. - setup.sh: GPU summary classifies NVIDIA first through a timeout-bounded probe with the /proc fallback; AMD probes are bounded and gain a KFD vendor_id 4098 fallback; the llama.cpp source build only selects GGML_CUDA/GGML_HIP when the matching GPU is actually detected. - install.sh: bound both nvidia-smi calls with a 10s timeout (no behavior change when healthy or when the timeout binary is absent); classify the exported UNSLOTH_TORCH_BACKEND on the final index path segment so custom mirrors containing 'rocm'/'gfx' in their base path are not mislabeled. - install.ps1 + setup.ps1: NVIDIA probes now require a real 'GPU N:' row from nvidia-smi -L under a 10s bound instead of bare exit code 0; later CUDA version and compute_cap queries are bounded too. Tests: 3 new test files (50+ tests), suite at 788 passed.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5eeb892df9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # host is classified; the AMD probes themselves run under _setup_run_smi. | ||
| if _setup_has_usable_nvidia_gpu; then | ||
| _setup_nvidia_usable=true |
There was a problem hiding this comment.
Honor hidden NVIDIA devices before preferring CUDA
On mixed AMD+NVIDIA hosts that set CUDA_VISIBLE_DEVICES='' to hide all NVIDIA devices, this new NVIDIA-first check still marks NVIDIA usable because nvidia-smi -L is not filtered by that env var. That skips the AMD probes below and later routes llama.cpp toward CUDA/source-build instead of ROCm; this repo's Python detector already treats both empty and -1 as hidden, so the setup helper/branch should do the same before suppressing AMD detection.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch. Fixed in 0e0739c. The hidden-device policy now lives inside the usable-NVIDIA helpers themselves instead of at individual gates, so every consumer agrees:
install.sh: new_cvd_hides_nvidiachecked first in_has_usable_nvidia_gpustudio/setup.sh: same via_setup_cvd_hides_nvidia; the two ad-hoc-1gate conditions are now redundant and removedstudio/install_python_stack.py:_has_usable_nvidia_gpureturns False whenCUDA_VISIBLE_DEVICESis set to""or-1(whitespace tolerated), matchinginstall_llama_prebuilt.py
Both forms now suppress NVIDIA before the AMD probes are gated, so a mixed host steered to its AMD card keeps the ROCm route end to end: torch index selection, llama.cpp repo routing, and the source-build backend. Covered by new shell scenarios in tests/sh/test_get_torch_index_url.sh (including the mixed host with hidden NVIDIA restoring rocm6.4) and the TestHiddenCvdNotUsable class driving all three implementations.
tests/studio/test_resolve_cuda_toolkit.ps1 extracts Resolve-CudaToolkit alone into a child pwsh and stubs nvidia-smi with a .ps1 script. The bounded runner is not in scope there (and ProcessStartInfo cannot dispatch .ps1 stubs), so the DriverMaxCuda parse silently returned nothing and the major-mismatch scenarios failed. Fall back to direct invocation when Invoke-NvidiaSmiBounded is unavailable; production setup.ps1 always has it defined and keeps the 10s bound.
The NVIDIA-first guards added in this branch only special-cased CUDA_VISIBLE_DEVICES=-1 at two setup.sh gates and ignored the empty-string form entirely, while the Python detector (install_llama_prebuilt.py) already treats both as hidden. On a mixed AMD+NVIDIA host steered to the AMD card via CUDA_VISIBLE_DEVICES, the guards suppressed the AMD probes, so setup.sh fell to a CPU llama.cpp build and install.sh picked CUDA wheels instead of ROCm. Move the policy into the helpers so every consumer agrees: - install.sh: new _cvd_hides_nvidia checked first in _has_usable_nvidia_gpu - studio/setup.sh: same via _setup_cvd_hides_nvidia; the two ad-hoc CUDA_VISIBLE_DEVICES=-1 gate conditions are now redundant and removed - studio/install_python_stack.py: _has_usable_nvidia_gpu returns False when CUDA_VISIBLE_DEVICES is set to or -1 (whitespace tolerated) Tests: 5 new sh scenarios (hidden via , -1, padded -1, visible device, and mixed host with hidden NVIDIA restoring the ROCm route) plus a pytest class covering all three implementations behaviourally. Addresses the review comment on the NVIDIA-first setup.sh block.
Summary
Follow-up to #6174 (#6172). That fix hardened the two torch-installer detectors; this PR ports the same hardening to the remaining GPU-detection pathways and adds recovery for venvs already poisoned by the original bug.
Changes
1. Poisoned venv repair (
studio/install_python_stack.py)A venv that got ROCm torch on an NVIDIA Linux host before #6174 stayed broken on
unsloth studio update: atorch+rocmwheel satisfies the version constraint, so nothing reinstalled CUDA torch (a fullinstall.shrerun rebuilds the venv and was the only recovery). New_ensure_cuda_torchdetects the poisoning signature (torch links HIP/ROCm while NVIDIA is the usable GPU) and force-reinstalls CUDA torch from the rightcu*index, resolved with the same driver-version ladder asinstall.sh. Opt-outs respected:UNSLOTH_TORCH_BACKEND=rocm/cpu,UNSLOTH_ROCM_TORCH_INSTALLED=1, andCUDA_VISIBLE_DEVICES=-1or empty (deliberately hidden GPU on mixed AMD+NVIDIA hosts). Healthy CUDA torch, deliberate CPU wheels, missing torch, macOS, and Windows are untouched.2. llama.cpp prebuilt routing (
studio/install_llama_prebuilt.py)detect_host()was nvidia-smi-only; with smi missing or wedged, an NVIDIA host degraded to a CPU llama.cpp build, and with ROCm tools co-installed it could route to ROCm assets. It now has the/proc/driver/nvidia/gpusfallback and skips ROCm probes when NVIDIA is usable. Forwarded--rocm-gfx/--has-rocmoverrides still win.3. Studio setup routing (
studio/setup.sh)The GPU summary now classifies NVIDIA first through a timeout-bounded probe with the
/procfallback, and AMD probes (also bounded now) are skipped on usable-NVIDIA hosts. The AMD detection gains the KFDvendor_id 4098sysfs fallback so AMD hosts without rocminfo/amd-smi are still recognized. The llama.cpp source-build fallback no longer picksGGML_CUDA/GGML_HIPfrom toolkit presence alone (nvcc in a CPU container, leftover hipcc) -- it requires the matching GPU to actually be detected.4. Probe bounds (
install.sh,install.ps1,studio/setup.ps1)Every nvidia-smi invocation in
install.shand both PowerShell installers is now bounded (10s); a wedged driver can no longer hang the installer before the fallbacks run. The Windows probes additionally require a realGPU N:row fromnvidia-smi -Linstead of accepting bare exit code 0. Behavior is unchanged when probes are healthy or where thetimeoutbinary is absent (macOS).5. Backend export robustness (
install.sh)UNSLOTH_TORCH_BACKENDis now classified from the final path segment ofTORCH_INDEX_URL, so a customUNSLOTH_PYTORCH_MIRRORwhose base path containsrocmorgfxcannot mislabel acu*/cpuindex as ROCm.Test plan
test_cuda_repair.py(repair fires only on the poisoning signature; full index ladder; every opt-out),test_gpu_detection_followups.py(proc fallback, NVIDIA precedence, override interplay, setup.sh gating, backend leaf classification driven throughshwith adversarial mirror URLs),test_probe_timeouts.py(source-level bounds plus a live hung-smi test)tests/studio/install/suite: 788 passed, 1 skippedtests/sh/test_get_torch_index_url.sh: 32 passed.ps1files plus behavioral simulation: exit-0-no-GPU rejected, MIG output still detected, hung smi killed at 10sinstall.shbackend export reaches a childinstall_python_stack.pyand gates the repair correctly for cuda/cpu/rocmunsloth studio updatenow restores CUDA torch