Skip to content

Studio: a masked NVIDIA GPU must not install the CPU bundle over CUDA - #10909

Merged
danielhanchen merged 13 commits into
mainfrom
masked-nvidia-does-not-install-the-cpu-bundle
Sep 14, 2026
Merged

danielhanchen merged 13 commits into
mainfrom
masked-nvidia-does-not-install-the-cpu-bundle

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Problem

On a host with NVIDIA GPUs, an empty CUDA_VISIBLE_DEVICES makes the installer choose the CPU llama.cpp bundle and install it over the CUDA one.

Measured on a 5x B200 box with a healthy driver and a working nvidia-smi, changing nothing but the mask:

$ python studio/install_llama_prebuilt.py --resolve-prebuilt --output-format json
{"asset": "app-b10909-mix-bea84f7-linux-x64-cuda13-newer.tar.gz", "backend": "cuda",
 "install_kind": "linux-cuda", "prebuilt_available": true, ...}

$ CUDA_VISIBLE_DEVICES="" python studio/install_llama_prebuilt.py --resolve-prebuilt --output-format json
{"asset": "app-b10909-mix-bea84f7-linux-x64-cpu.tar.gz", "backend": "cpu",
 "install_kind": "linux-cpu", "prebuilt_available": true, ...}

Note prebuilt_available: true on the second one. This is not a plan that fails and falls back; it is a CPU bundle that gets downloaded and installed, and activate_install_tree replaces the tree in place with no backup of the CUDA build.

An empty mask is routine: schedulers, containers, CI steps and unsloth invocations that want to stay off the GPU all set it. The mask is scoped to one process. The install it triggers is permanent and shared.

Cause

has_usable_nvidia is visible_device_tokens != [] on both probe paths, the nvidia-smi -L one and the /proc/driver/nvidia/gpus rescue. So has_physical_nvidia and not has_usable_nvidia means exactly one thing: the GPU is present and CUDA_VISIBLE_DEVICES is empty.

_linux_published_attempts branches on has_usable_nvidia, so that host lands in the final else and picks up the CPU bundle. The comment there already states the intended rule, it just keys on the wrong flag:

CPU-only host. A usable-NVIDIA host never reaches here -- if its CUDA selection produced nothing we want an empty attempt list so the caller source-builds with CUDA, not a CPU-only binary silently installed on a GPU host (mirrors the ROCm branch, and Windows NVIDIA).

A masked host is not a CPU-only host, but it reaches there all the same.

Change

Select CUDA as if unmasked, rather than the CPU bundle.

nvidia-smi is an NVML tool, not a CUDA application, so it keeps answering under an empty mask and the driver CUDA version is still readable. The compute caps are not, though: select_visible_gpu_rows filters the rows by the mask, so host.compute_caps comes back empty, which is the selector's unknown-SM path and accepts a portable artifact without checking min_sm / max_sm. Measured on the masked B200 host:

mask unset   compute_caps ['100']   physical_compute_caps ['100']
mask ""      compute_caps []        physical_compute_caps ['100']
mask "-1"    compute_caps []        physical_compute_caps ['100']

So HostInfo now carries physical_compute_caps, recorded before the mask filter, and the masked branch selects against those. compute_caps keeps its meaning as the visible set, so nothing else changes. Without this, a masked sm_61 host would accept a bundle whose floor is sm_70 and still have no offload once the mask came off.

The mask still does its job at run time, since the CUDA build simply sees no devices and runs on CPU exactly as the CPU bundle would. The difference is that the install stays correct for the next unmasked run.

The source-build leg

When no CUDA bundle matches, the empty attempt list is meant to hand the caller a CUDA source build. studio/setup.sh gated its nvcc search on _setup_nvidia_usable, which is false under the mask by construction, so it compiled a CPU-only binary and activated it over the tree: slower than the CPU prebuilt and just as permanent.

setup.sh now has _setup_has_physical_nvidia_gpu, which is the old body minus the _setup_cvd_hides_nvidia early return, and _setup_has_usable_nvidia_gpu is written as "not hidden, and physical" so the two cannot drift. The nvcc search gates on _setup_nvidia_physical. A CUDA toolkit with no GPU at all is still refused, which is what that guard was written for; a card hidden by a mask is still a card.

mask=UNSET physical=yes usable=yes
mask=""    physical=yes usable=no
mask=-1    physical=yes usable=no
mask=0     physical=yes usable=yes

usable is unchanged from before the refactor.

A masked card only claims the build when there is no AMD GPU to serve. The AMD probes run whenever NVIDIA is not usable, so a mixed host reaches the gate with _setup_amd_detected set, and the ROCm branch below only fires while GPU_BACKEND is empty; without the carve-out, hiding the NVIDIA card would build CUDA for the card the user hid instead of HIP for the one they left visible. A usable NVIDIA card still wins outright, which is the existing NVIDIA-priority rule. The whole gate expression is extracted from setup.sh and run as a truth table:

The nvcc search is one _select_nvcc function called twice, in the order the decision wants: a usable card takes it first (the original rule, unchanged), then the ROCm block runs, then a physically present card retries while GPU_BACKEND is still empty. So a masked card yields to a visible AMD GPU only when ROCm can really be selected, and reclaims the build when it cannot. Checking AMD detection alone was not enough, because hipcc availability is settled later: a host with an AMD GPU and no hipcc anywhere would otherwise have taken a CPU source build with nvcc sitting right there.

The whole block is extracted and run as a real bash sequence with the two toolchain lookups stubbed:

usable NVIDIA physical NVIDIA AMD detected hipcc backend
yes yes no no cuda
yes yes yes yes cuda
no yes no no cuda
no yes yes yes rocm
no yes yes no cuda
no no yes yes rocm
no no no n/a cpu

The last row is the guard this was written for: a CUDA toolkit with no GPU at all is still refused.

[llama-prebuilt] NVIDIA GPU present but hidden by CUDA_VISIBLE_DEVICES=''; selecting the
                 CUDA bundle for the hardware rather than installing the CPU bundle over it
{"asset": "app-b10909-mix-bea84f7-linux-x64-cuda13-portable.tar.gz", "backend": "cuda",
 "install_kind": "linux-cuda", "prebuilt_available": true, ...}

Placement matters in two directions. The gate sits after the ROCm branch, so a masked NVIDIA host that also has usable ROCm still takes ROCm. It sits after the Vulkan branch, which is already gated on not has_physical_nvidia, so an iGPU next to a masked NVIDIA card does not become a second route to a non-CUDA install. And an explicit CPU request never reaches it at all, because _apply_host_overrides clears has_physical_nvidia first.

There is precedent for this reading elsewhere in the tree: install_python_stack already refuses to conclude a torch flavor from an emptied mask, on the grounds that a mask is a reason not to conclude something from a probe rather than a fact about the hardware.

Verification

On the same B200 host, after the change:

condition before after
unmasked linux-cuda, cuda13-newer unchanged
CUDA_VISIBLE_DEVICES="" linux-cpu linux-cuda, cuda13-newer

The masked pick is now byte-for-byte the unmasked pick. Before the physical-caps commit it resolved cuda13-portable through the unknown-SM path, which is correct on sm_100 and wrong on an sm_61 host.

I also ran the masked CUDA binary for real: it prints ggml_cuda_init: failed to initialize CUDA: no CUDA-capable device is detected and then serves on CPU at 1031 tok/s, against 3839 tok/s on CUDA0 with the mask lifted. So the masked run degrades exactly as the CPU bundle would, and the install is still right afterwards.

Four tests in TestLinuxPublishedAttemptsNvidiaCpuGate in tests/studio/install/test_selection_logic.py: a masked NVIDIA host takes CUDA and not the CPU bundle, a masked NVIDIA host with no CUDA match falls through to the source build rather than the CPU bundle, a masked NVIDIA host with an Intel iGPU alongside it is not rescued onto Vulkan either, and a masked sm_61 host is not handed a bundle whose floor is sm_70. Plus TestSetupShPhysicalNvidiaSurvivesTheMask, which exercises the new shell probe across unset, "", -1 and 0. The existing test_cpu_host_gets_cpu_attempt covers the case that must not change, and still passes.

A 44-scenario base-vs-head selection matrix over [Windows, Linux, WSL, macOS] x [NVIDIA, AMD, Intel, CPU-only], built from the real b10909 asset list, moves exactly 4 rows: the masked Linux and WSL NVIDIA ones. Everything else is byte-identical.

Existing installs are unaffected either way: a host that was already wrongly downgraded recorded backend_request: auto, so the next update re-detects and heals itself, while a deliberate cpu or vulkan choice stays honoured.

tests/studio/, studio/backend/tests/test_install_resolve_prebuilt.py and unsloth_cli/tests, after merging main: 11220 passed, 106 skipped. tests/sh/test_setup_staged_root.sh: 36 passed.

Scope

Linux published-bundle selection. This is one of three separate paths that can end with a GPU machine on CPU; the other two are handled in #10906 and #10908.

Before / after in the UI

Two full Studio installs from this PR's merge base and its head, both run with CUDA_VISIBLE_DEVICES= exported so the installer sees a host whose NVIDIA GPU is present and hidden. Settings > Resources > GGUF inference engine:

Compute backend, before and after

llama.cpp currently runs on CPU. with the picker on Automatic (CPU) becomes llama.cpp currently runs on CUDA. on Automatic (CUDA). Read from the same two servers: backend cpu -> cuda, the auto option's resolved_backend cpu -> cuda, available_backends gains cuda, and backend_request is auto with env_backend null on both sides, so this is the automatic path and not a stored preference.

Settings, before and after

The wider shot is the control. Both sides report No visible GPU detected. CPU-only resources are shown above. under GPU devices and No visible GPU for VRAM, which is the mask doing its job on both halves; the head install selected CUDA anyway. The markers the two installs wrote agree: app-b10909-mix-bea84f7-linux-x64-cpu.tar.gz with backend: cpu against app-b10909-mix-bea84f7-linux-x64-cuda13-newer.tar.gz with backend: cuda, force_cpu: false on both.

Both halves were built at 9f182473a and 996974d46. The commits after that shot are the Torch runtime-preference fix, a main merge and a comment pass; the masked resolve at the current head still selects app-b10909-mix-bea84f7-linux-x64-cuda13-newer.tar.gz, so what these screenshots show is unchanged.

has_usable_nvidia is visible_device_tokens != [] on both probe paths, so a host
with has_physical_nvidia and not has_usable_nvidia is exactly one that has an
NVIDIA GPU and an empty CUDA_VISIBLE_DEVICES. That host reached the CPU branch of
_linux_published_attempts and was handed linux-cpu.

The mask is scoped to one process. The install is not: activate_install_tree
replaces the tree in place with no backup, so a single masked run left a CUDA
machine on the CPU bundle permanently. Return an empty attempt list and let the
caller source-build, which is what the ROCm branch already does, and name the
reason in the log.

Measured on a 5x B200 host: CUDA_VISIBLE_DEVICES='' resolved
app-b10909-mix-bea84f7-linux-x64-cpu.tar.gz with prebuilt_available true; it now
resolves prebuilt_available false with the mask named. Unmasked resolution is
unchanged.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-14T19:15:02.985252Z f130bf3 Manual request
🔒 Security Review ✅ Completed 2026-09-14T05:46:31.024911Z 5399903 PR opened

Security findings

Blocking findings (1)

ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

nvidia-smi -L, --query-gpu=compute_cap and the driver CUDA version are driver
queries and keep answering under an empty CUDA_VISIBLE_DEVICES, so compute_caps
and driver_cuda_version are fully populated and the normal coverage match works.
Installing the CUDA bundle is therefore strictly better than returning an empty
attempt list: no source build, no nvcc requirement, and the mask still does its
job at run time because the CUDA build simply sees no devices and runs on CPU.

ROCm keeps precedence and an explicit CPU request still bypasses this entirely.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛡️ Codex Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: 5399903419

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

"NVIDIA GPU present but hidden by CUDA_VISIBLE_DEVICES="
f"{host.visible_cuda_devices!r}; not installing the CPU bundle over it"
)
return attempts

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛡️ Codex Security Review · Automatically triggered

P0 Badge Security: Verify masked-GPU source fallbacks

When Studio is installed on Linux with a physically present but masked NVIDIA GPU, no reusable source build, and Git/CMake available, this return forces exit 2. setup.sh then clones ggml-org/llama.cpp at a mutable release tag and immediately runs its CMake configuration without verifying a commit, signature, or content hash. An upstream compromise or retag can therefore execute code as the installer user, whereas the parent selected the checksum-approved CPU archive. Resolve and verify the manifest's pinned source commit/archive before entering this fallback.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The description of setup.sh is accurate but the attribution is not, so I am not changing this PR for it.

setup.sh only ever clones by ref. _RESOLVED_SOURCE_REF_KIND is tag or branch on every user-reachable path (studio/setup.sh:2613, :3098, :3119, :3122); the commit and pull arms are gated behind _LLAMA_PR, a developer flag. So an unverified git clone --depth 1 --branch <tag> https://github.com/ggml-org/llama.cpp.git is the shape of the from-scratch source build for every host that reaches it, and has been since long before this branch.

What this PR changes is which hosts count as NVIDIA, not what an NVIDIA host gets. The empty-attempts-then-source-build outcome is the existing deliberate policy for a Linux NVIDIA host whose CUDA selection produced nothing (a3ca5d2a5, #6310, "don't silently fall back to a CPU prebuilt on NVIDIA Linux GPU hosts") and for a ROCm host with no matching gfx bundle, and it is also where any host lands when a prebuilt download or preflight fails. A masked NVIDIA host is the same hardware as a visible one; giving it the CPU archive instead is the bug this PR fixes, because activate_install_tree replaces the tree in place and the mask is scoped to one process.

The residual class is narrow: physically present NVIDIA, hidden by the mask, and a release shipping no CUDA bundle covering its compute cap. nvidia-smi -L, --query-gpu=compute_cap and the driver CUDA version all keep answering under an empty mask, so compute_caps is populated and the normal coverage match applies; every fork release since b9585 ships CUDA bundles for x86_64 and arm64. Making that one sub-case take the CPU archive would leave masked hosts behaving differently from visible ones for no security gain, since the visible host already takes the same clone.

Verifying the pinned source is worth doing, but it belongs in setup.sh and covers every source build, not this branch. The machinery is already there on the Python side: source_build_plan_for_release and preferred_source_archive resolve repo + commit + sha256 from the approved checksum asset, and validate fails closed via require_approved_source_hash and the "exact source archive without a source repo" guard. Tracking that separately rather than widening this PR.

@danielhanchen

Copy link
Copy Markdown
Member Author

Revised after simulating this, and the first version was wrong

The original commit returned an empty attempt list for a masked host, forcing a source build. That is worse than it needed to be, and I only found out by measuring rather than reasoning.

CUDA_VISIBLE_DEVICES is a filter for CUDA applications. nvidia-smi is an NVML tool, not a CUDA application, so it keeps answering under the mask. Measured on the same 5x B200 host:

$ CUDA_VISIBLE_DEVICES="" nvidia-smi -L
GPU 0: NVIDIA B200 (UUID: GPU-78bb7f6d-...)
$ CUDA_VISIBLE_DEVICES="" nvidia-smi --query-gpu=index,compute_cap --format=csv,noheader
0, 10.0
$ CUDA_VISIBLE_DEVICES="" nvidia-smi | grep -o "CUDA Version: [0-9.]*"
CUDA Version: 13.1

So compute_caps and driver_cuda_version are fully populated and the normal coverage match works. The masked host now gets the CUDA bundle its hardware deserves. No source build, no nvcc requirement.

This is safe because the CUDA build degrades to CPU by itself when no device is visible. Verified with the real app-b10909-mix-bea84f7-linux-x64-cuda13-portable bundle and stories260K.gguf, same binary both times:

# masked
$ CUDA_VISIBLE_DEVICES="" ./llama-server --list-devices
ggml_cuda_init: failed to initialize CUDA: no CUDA-capable device is detected
Available devices:
  (none)

$ CUDA_VISIBLE_DEVICES="" ./llama-completion -m stories260K.gguf -p "Once upon a time" -n 24
 Once upon a time, there was a little girl named Lily. She loved to eat paper with her f
eval time = 22.29 ms / 23 runs (1031.67 tokens per second)

# unmasked, same binary
$ ./llama-completion -m stories260K.gguf -p "Once upon a time" -n 24 -ngl 99
resolve_fused_ops: layer 0 is assigned to device CUDA0
eval time = 5.99 ms / 23 runs (3839.73 tokens per second)

Correct output either way. The mask still does its job at run time, and the install is right for the next unmasked run, which a CPU bundle would not have been.

Blast radius

I built a base-vs-head matrix over the cartesian product of [Linux, WSL, Windows, macOS] x [NVIDIA, AMD, Intel, CPU-only] with their sub-conditions (masked, Blackwell sm_120, ancient sm_61, NVIDIA + AMD iGPU, ROCm covered and uncovered, arm64, Apple Silicon, Intel Mac), 44 scenarios, running the real _linux_published_attempts and resolve_release_asset_choice against a fixture built from the real b10909-mix-bea84f7 asset list.

4 of 44 scenarios change, and all four are the masked NVIDIA host:

scenario before after
Linux / NVIDIA masked linux-cpu linux-cuda
Linux / NVIDIA masked + AMD iGPU linux-cpu linux-cuda
WSL / NVIDIA masked linux-cpu linux-cuda
WSL / NVIDIA masked + AMD iGPU linux-cpu linux-cuda

Everything else is byte-identical, including every ROCm, Vulkan, Intel, CPU-only, arm64 and macOS row.

Kept deliberately, and asserted:

  • ROCm keeps precedence. The gate sits after the ROCm branch, so a masked NVIDIA host that also has usable ROCm still takes ROCm.
  • An explicit CPU request never reaches it, because _apply_host_overrides clears has_physical_nvidia.
  • No CUDA match still yields an empty list and a CUDA source build, never the CPU bundle.
  • The Vulkan branch is still gated on not has_physical_nvidia, so an iGPU next to a masked card is not a second route out.

Parser edge cases

parse_cuda_visible_devices decides which hosts reach the new branch at all:

value parsed has_usable_nvidia path
unset None True normal CUDA
"", " ", -1, , [] False new branch, CUDA
0, 0,1, GPU-78bb... tokens True normal CUDA
'""' (Windows quoting artifact) ['""'] True normal CUDA
-1,0 ['-1','0'] True normal CUDA

Every value lands on a CUDA bundle. None regress to CPU.

Existing installs

I wrote real UNSLOTH_PREBUILT_INFO.json markers of several vintages and asked effective_backend_request what the next update does:

existing install marker backend next update
v0.1.701 era, no backend fields none auto, re-detects
healthy CUDA cuda auto, re-detects
wrongly downgraded to CPU cpu auto, self-heals
user deliberately chose cpu cpu cpu, honoured
user deliberately chose vulkan vulkan vulkan, honoured
ROCm gfx1151 rocm auto, re-detects

A wrongly-downgraded install records backend_request: auto, so people already stuck on CPU are repaired by their next update rather than needing a manual reinstall. A deliberate choice is still honoured across updates, per #7213.

tests/studio/install/: 4036 passed, 6 skipped.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
Comment-only pass over what this branch adds. Measured numbers and the mechanism
write-ups move to the PR description, where they belong; what stays is the
invariants the code does not state on its own.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
…source

Two holes in the masked-NVIDIA path, both of which left the machine on CPU by a
different route.

An emptied CUDA_VISIBLE_DEVICES makes select_visible_gpu_rows drop every
nvidia-smi row, so host.compute_caps comes back empty and the selector takes its
unknown-SM path, which accepts a portable artifact without checking min_sm or
max_sm. A masked sm_61 host would install a bundle whose floor is sm_70 and
still have no offload once the mask came off. HostInfo now carries
physical_compute_caps, recorded before the mask filter, and the masked branch
selects against those. Measured on a 5x B200 box: the masked resolve went from
cuda13-portable to cuda13-newer, which is exactly what the same host resolves
unmasked.

When no CUDA bundle matches, the empty attempt list is meant to hand the caller
a CUDA source build. setup.sh gated its nvcc search on _setup_nvidia_usable,
which is false under the mask by construction, so it compiled a CPU-only binary
and activated it over the tree: slower than the CPU prebuilt and just as
permanent. The gate is now _setup_nvidia_physical. A toolkit with no GPU at all
is still refused, which is what that guard was written for; a card hidden by a
mask is still a card. _setup_has_usable_nvidia_gpu is written in terms of the
new physical probe so the two cannot drift.

Tests: a masked sm_61 host is not handed an sm_70 floor (fails without the
change), the masked hosts in the existing tests now look like detect_host really
leaves them, and the physical probe is exercised across unset, "", -1 and 0.
The setup.sh source-level tests follow the gate and the delegation.

tests/studio/install/ + test_install_resolve_prebuilt.py: 4344 passed, 7 skipped.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…D one

Regression from the previous commit. Gating the nvcc search on physical NVIDIA
alone meant a mixed AMD+NVIDIA host that hid NVIDIA via CUDA_VISIBLE_DEVICES
built CUDA for the card the user hid: the AMD probes run whenever NVIDIA is not
usable, so _setup_amd_detected is set on that host, and the ROCm branch below
only fires while GPU_BACKEND is still empty.

The masked arm now also requires that no AMD GPU was detected. A USABLE NVIDIA
card still wins outright, which is the existing NVIDIA-priority rule, and a CUDA
toolkit with no GPU at all is still refused.

TestSetupShSourceBuildBackendChoice runs the gate expression as a truth table
over the six host classes that reach it:

    visible NVIDIA, no AMD              -> cuda
    visible NVIDIA + AMD                -> cuda
    masked NVIDIA, no AMD               -> cuda
    masked NVIDIA + usable AMD          -> rocm
    AMD only                            -> rocm
    no GPU at all                       -> cpu

The source-level assertion in TestSetupShHardening followed: it forbade any
mention of _setup_nvidia_usable in the window, which the correct gate needs.

tests/studio/install/ + test_install_resolve_prebuilt.py: 4350 passed, 7 skipped.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

The AMD carve-out from the previous commit checked DETECTION only, while hipcc
availability is checked later. So a mixed host with NVIDIA hidden, an AMD GPU
detected by rocminfo, and no hipcc anywhere skipped the nvcc search, left
GPU_BACKEND empty in the ROCm block, and took a CPU source build with nvcc
sitting right there, activated over the tree for good.

The carve-out was the wrong shape, so it is gone rather than patched. The nvcc
search is one _select_nvcc function called twice, in the order the decision
wants: usable NVIDIA first (the original rule, restored verbatim), then the ROCm
block unchanged, then a retry for a physically present card while GPU_BACKEND is
still empty. A masked card yields to a visible AMD GPU only when ROCm can really
be selected, and reclaims the build when it cannot. A CUDA toolkit with no GPU at
all is still refused.

TestSetupShSourceBuildBackendChoice now extracts the whole block and runs it as a
real bash sequence with the two toolchain lookups stubbed, rather than testing
one gate expression in isolation:

    usable NVIDIA, no AMD           -> cuda
    usable NVIDIA + AMD + hipcc     -> cuda
    masked NVIDIA, no AMD           -> cuda
    masked NVIDIA + AMD + hipcc     -> rocm
    masked NVIDIA + AMD, no hipcc   -> cuda
    AMD only + hipcc                -> rocm
    nvcc present, no GPU at all     -> cpu

Exactly one row, the fifth, fails on the previous revision.

Merged origin/main: the branch was ~40 commits behind and CI was failing four
staged-root shell checks that pass on main and on the merge.

tests/studio/install/ + test_install_resolve_prebuilt.py: 4701 passed, 19
skipped. tests/sh/test_setup_staged_root.sh: 36 passed.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Both gates in detect_torch_cuda_runtime_preference answer "no GPU" under an
emptied CUDA_VISIBLE_DEVICES: has_usable_nvidia is false by definition, and
torch.cuda.is_available() sees no devices. So the masked branch got no
preference and linux_cuda_choice_from_release fell back to newest-first,
selecting a CUDA 13 bundle for a cu12 venv. That is the stray-runtime mismatch
the unmasked path exists to avoid, reintroduced by the very branch that is
supposed to make a masked host behave like an unmasked one.

detect_torch_cuda_runtime_preference takes a gpu_hidden_by_mask opt-in for a
caller that has already established a physically present card behind the mask.
It bypasses those two gates and nothing else: torch.version.cuda is a build-time
constant no mask touches, and it is exactly the question being asked. Every
other caller is unchanged by default.

Measured on the 5x B200 host, torch 2.11.0+cu128:

    torch_cuda_preference: GPU hidden by CUDA_VISIBLE_DEVICES; reading
                           torch.version.cuda without the availability check
    torch_cuda_preference: selected runtime_line=cuda12 from torch.version.cuda=12.8

and the masked resolve is byte-for-byte the unmasked one.

Two tests: the preference is skipped without the opt-in and returns cuda12 with
it on a masked host whose torch.cuda.is_available() is False, and the masked
branch is pinned to actually pass it.

tests/studio/install/ + test_install_resolve_prebuilt.py: 4703 passed, 19
skipped. tests/sh/test_setup_staged_root.sh: 36 passed.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: f130bf3144

ℹ️ 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".

@danielhanchen
danielhanchen merged commit 9e911ee into main Sep 14, 2026
62 of 65 checks passed
@danielhanchen
danielhanchen deleted the masked-nvidia-does-not-install-the-cpu-bundle branch September 14, 2026 21:35
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