Skip to content

Studio: read the NVIDIA inventory from NVML or the CUDA driver when nvidia-smi cannot answer - #10985

Merged
danielhanchen merged 5 commits into
mainfrom
nvidia-library-probe
Sep 15, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
nvidia-library-probe

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

The installers ask nvidia-smi three questions: is there a GPU, which compute capabilities, and which CUDA version the driver carries. When nvidia-smi cannot answer, every one of those became "no": a copy absent from PATH (a container with only the driver libraries mounted, a snap, Windows with the utility off PATH), a stale copy that exits non-zero, or one that hangs, left driver_cuda_version unset, and "runnable by this driver=none" then sent a CUDA host to a source build or the CPU bundle. The torch index defaulted to cu126 in the same case, which on Blackwell is a wheel with no kernels, and a CPU torch expectation is what #10906 had to defend against.

Ollama, Jan and lemonade never depend on the utility: Ollama loads libnvidia-ml.so and libcuda.so directly, Jan and lemonade read NVML, and ComfyUI Desktop and LlamaFactory (the two that also install PyTorch) ask torch itself. This adds the same source as the fallback.

The change

studio/nvidia_probe.py, a stdlib-only module:

  • NVML first (libnvidia-ml.so.1 / nvml.dll): the library nvidia-smi is a client of, so the inventory is the physical one and the caller applies CUDA_VISIBLE_DEVICES exactly as it does to nvidia-smi rows. Compute capability, UUID, name, driver version and the packed CUDA driver version (13010 is 13.1).
  • The CUDA driver API second (libcuda.so.1 / nvcuda.dll): cuInit, cuDriverGetVersion, cuDeviceGetCount and the compute-capability attributes. It honours the mask, so an emptied one reads as no devices.
  • Always in a child process with a deadline: these libraries block in-process in exactly the states that make nvidia-smi hang.
  • When even that fails on Linux, /proc/driver/nvidia/version names the kernel module and the release bounds the CUDA major (R580 carries CUDA 13, R525 carries 12, R450 carries 11, from NVIDIA's minor-version-compatibility table).

Consumers, each after its existing probes and only when they came back empty:

  • install_llama_prebuilt.detect_host: presence, physical and visible compute caps, driver CUDA version.
  • install_python_stack._has_usable_nvidia_gpu and _detect_cuda_torch_index_url: the torch family, with the pre-Turing cap reading SMs from the library inventory (_cap_cuda_family_for_pre_turing takes them as an argument). Without SMs the cu126 default stays: a driver version alone cannot rule out Maxwell, Pascal or Volta, which cu128+ drop. The CUDA ladder is one function, _torch_family_for_cuda_version. The /proc release bound feeds detect_host only.
  • A mask the NVML rows cannot name (a MIG UUID) leaves the GPU usable, as the nvidia-smi rows already do.
  • setup.sh _setup_has_physical_nvidia_gpu: runs the module last, bounded by _setup_run_smi.

A working nvidia-smi is never second-guessed. Older checkouts import the module under try, so a newer setup script beside an older tree still runs. UNSLOTH_NVIDIA_LIBRARY_PROBE=0 turns every new source off, the /proc bound included; the test conftests set it so a test that hides nvidia-smi to fake a CPU host does not find the real GPUs through the libraries.

Measured

This host: 8x B200, driver 590.48.01, CUDA 13.1. One variable changed per row, install_llama_prebuilt.py --resolve-prebuilt at main and at this branch.

nvidia-smi main this branch
exits 1 prebuilt_available: false (source build or CPU); torch index cu126 linux-cuda, app-b10909-mix-bea84f7-linux-x64-cuda13-newer.tar.gz; torch index cu130
hangs 45 s prebuilt_available: false, 62 s cuda13-newer, 63 s
absent and no /proc/driver/nvidia/gpus index cu126 index cu130

The probe answers in 0.1 s. The three 20 s nvidia-smi timeouts still run first; shortening them is a visible behaviour change and is left for its own PR.

Tests

tests/studio/install/test_nvidia_library_probe.py: the module (payload parsing, the CUDA packing, the driver-release table against NVIDIA's documented floors, the /proc reader, the child run with its deadline, a hung or broken child, macOS, the CLI exit code, and on a real NVIDIA host the library agreeing with nvidia-smi -L), detect_host (a failing or absent nvidia-smi now reads the inventory; NVML rows are masked like nvidia-smi rows while CUDA driver rows are not; a working nvidia-smi is not probed; the kernel release bounds the driver version; a CPU host stays CPU), the torch index fallbacks, and the setup.sh hook.

…vidia-smi cannot answer, and bound the CUDA version by the kernel module release
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 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-15T07:09:08.060810Z 58794ec Manual request
ℹ️ 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.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026

@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 Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a37ec39685

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

Comment thread studio/install_python_stack.py Outdated
if _nvidia_probe is not None and _nvidia_probe.enabled() and sys.platform != "win32":
bound = _nvidia_probe.cuda_version_for_driver(_nvidia_probe.proc_driver_version())
if bound is not None:
return f"{_PYTORCH_WHL_BASE}/{_torch_family_for_cuda_version(*bound)}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve the pre-Turing cap for the /proc fallback

On a Linux x86_64 host with a Maxwell, Pascal, or Volta GPU, a modern driver, and both nvidia-smi and the library inventory unavailable, this path selects cu128/cu130 solely from /proc. It bypasses _cap_cuda_family_for_pre_turing, even though those PyTorch 2.11 families start at sm_75, so the resulting wheel has no kernels for the GPU. Keep the conservative cu126 default when compute capabilities cannot be read, or otherwise apply the architecture cap before returning.

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.

Right, a driver version alone cannot rule out Maxwell, Pascal or Volta. 7ff997c drops the /proc bound from the torch index (it still feeds detect_host) and keeps cu126 whenever the inventory carries no compute caps; the family is raised only with SMs in hand, through the pre-Turing cap.

Comment thread studio/install_llama_prebuilt.py Outdated
Comment on lines +2715 to +2717
if not has_physical_nvidia:
has_physical_nvidia = True
has_usable_nvidia = bool(visible_rows)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep valid MIG masks usable in the NVML fallback

When NVML is the only successful presence probe and CUDA_VISIBLE_DEVICES contains a valid MIG UUID, the inventory rows contain parent GPU-... UUIDs, so select_visible_gpu_rows returns no rows and this assignment marks the NVIDIA device unusable. This routes an NVML-enabled MIG container without nvidia-smi or /proc/driver/nvidia/gpus to ROCm/CPU even though its CUDA device is visible; recognize MIG UUIDs or retain the existing conservative usable result for mask formats that cannot be matched against physical NVML rows.

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.

Agreed. 7ff997c mirrors the nvidia-smi rows: a mask NVML rows cannot name (a MIG UUID, anything supports_explicit_visible_device_matching rejects) leaves the GPU usable; an explicit index or GPU- UUID that matches nothing stays unusable. Test added.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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 15, 2026

@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 Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ff997c876

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

Comment thread studio/install_python_stack.py Outdated
Comment on lines +2548 to +2549
inventory = _nvidia_library_inventory()
return bool(inventory is not None and inventory.devices)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Apply CUDA visibility to the NVML presence fallback

When nvidia-smi and /proc are unavailable and CUDA_VISIBLE_DEVICES contains an explicit numeric index or GPU-... UUID that matches no NVIDIA device, an NVML inventory is physical and unmasked, so this returns True even though CUDA exposes no NVIDIA GPU. That causes _has_rocm_gpu() to reject a usable AMD device and can route installation or repair to CUDA; filter NVML rows against explicit masks here, while retaining the conservative behavior for MIG or other mask formats that cannot be matched to physical rows.

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.

Agreed. 58794ec filters the NVML rows by an explicit index or GPU- UUID mask in _has_usable_nvidia_gpu (a miss reads as no usable NVIDIA GPU, so ROCm is not blocked); a MIG or other mask NVML rows cannot name stays usable, as the nvidia-smi and /proc probes leave it, and the CUDA driver rows are taken as already masked.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 58794ec5fa

ℹ️ 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 added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
@danielhanchen
danielhanchen merged commit 1e07231 into main Sep 15, 2026
59 of 62 checks passed
@danielhanchen
danielhanchen deleted the nvidia-library-probe branch September 15, 2026 08:45
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
…d on (unslothai#11001)

* Run the chat width presets in CI, and two guards main is currently red on

Three merges left main failing guards that every open PR then inherits. Lint CI's
"Workflow guard suites" step and Repo tests (CPU, studio) are red on main right
now, and six open PRs show the failure as their own.

1. unslothai#10958 added tests/studio/playwright_chat_width.py and no workflow that runs
   it. test_every_playwright_driver_is_invoked_by_ci exists for exactly that and
   says so. It could not be wired as written: it took CHAT_THREAD_ID and no CI
   step can produce a thread id, so the presets shipped with a driver that runs
   nowhere.

   The driver now seeds its own conversation through /api/chat/threads, the way
   playwright_thread_scoped_settings.py does, and CHAT_THREAD_ID stays honoured
   when set. Seeding needs no model: the messages endpoint stores whatever roles
   it is given, and an assistant-role message renders the
   .aui-assistant-message-root every assertion here measures. Verified against a
   real Studio: the seeded thread renders the bubble, and the sweep passes.

   Its sign-in also handled only the already-rotated case, so it could not have
   run against a fresh CI boot even with a thread id. Same two-branch shape as
   its siblings now.

   While making it run, one assertion that could not fail: the preset ordering is
   >=, so three presets pinned to the same width satisfy every line of it. The
   setting could stop working entirely and the driver would pass. At the widest
   viewport the three are separated by construction (48rem / 72rem /
   max(72rem, 100% - 6rem) in appearance-custom-store.ts), so that separation is
   now required. Pinning --custom-chat-max-width in a live browser: the old
   assertions pass, the new one fails with "at 2560px Wide gives message 744px,
   no more than Standard's 744px, so the preset is doing nothing".

2. unslothai#10985 added studio/nvidia_probe.py, imported by both install_llama_prebuilt.py
   and install_python_stack.py, which studio-mac-install-matrix.yml lists as
   inputs. Editing the probe did not run the matrix that depends on it. Added to
   both triggers.

3. unslothai#10988 (mine) added tests/studio/test_core_setup_zoo_revision_notice.py, which
   reads a workflow file but was not in workflow-trigger-lint's guard step, the
   only job with no paths filter. A PR editing only workflow files never
   collected it. Added.

The 1054 tests in the guard step pass, as does tests/studio (9687 passed; the two
failures there are on main already and untouched by this: an mlx import and a
PR-scoped guard).

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Tighten the comments this PR adds

Comment/docstring text only. comment_tools.py check --strict-ext
--allow-docstring-edits: 3/3 OK. The guard step's 1054 tests still pass, and the
driver still runs green end to end against a real Studio.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…vidia-smi cannot answer (unslothai#10985)

* Studio: read the NVIDIA inventory from NVML or the CUDA driver when nvidia-smi cannot answer, and bound the CUDA version by the kernel module release

* Shorten the probe comments for PR unslothai#10985

* Keep cu126 without compute caps, keep MIG masks usable, and skip the bash hook test on Windows for PR unslothai#10985

* Apply an explicit CUDA_VISIBLE_DEVICES mask to the NVML rows in the torch presence check for PR unslothai#10985

* Scan nvidia_probe.py for interactive prompts and add it to the parity path filter for PR unslothai#10985

---------

Co-authored-by: danielhanchen <[email protected]>
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…d on (unslothai#11001)

* Run the chat width presets in CI, and two guards main is currently red on

Three merges left main failing guards that every open PR then inherits. Lint CI's
"Workflow guard suites" step and Repo tests (CPU, studio) are red on main right
now, and six open PRs show the failure as their own.

1. unslothai#10958 added tests/studio/playwright_chat_width.py and no workflow that runs
   it. test_every_playwright_driver_is_invoked_by_ci exists for exactly that and
   says so. It could not be wired as written: it took CHAT_THREAD_ID and no CI
   step can produce a thread id, so the presets shipped with a driver that runs
   nowhere.

   The driver now seeds its own conversation through /api/chat/threads, the way
   playwright_thread_scoped_settings.py does, and CHAT_THREAD_ID stays honoured
   when set. Seeding needs no model: the messages endpoint stores whatever roles
   it is given, and an assistant-role message renders the
   .aui-assistant-message-root every assertion here measures. Verified against a
   real Studio: the seeded thread renders the bubble, and the sweep passes.

   Its sign-in also handled only the already-rotated case, so it could not have
   run against a fresh CI boot even with a thread id. Same two-branch shape as
   its siblings now.

   While making it run, one assertion that could not fail: the preset ordering is
   >=, so three presets pinned to the same width satisfy every line of it. The
   setting could stop working entirely and the driver would pass. At the widest
   viewport the three are separated by construction (48rem / 72rem /
   max(72rem, 100% - 6rem) in appearance-custom-store.ts), so that separation is
   now required. Pinning --custom-chat-max-width in a live browser: the old
   assertions pass, the new one fails with "at 2560px Wide gives message 744px,
   no more than Standard's 744px, so the preset is doing nothing".

2. unslothai#10985 added studio/nvidia_probe.py, imported by both install_llama_prebuilt.py
   and install_python_stack.py, which studio-mac-install-matrix.yml lists as
   inputs. Editing the probe did not run the matrix that depends on it. Added to
   both triggers.

3. unslothai#10988 (mine) added tests/studio/test_core_setup_zoo_revision_notice.py, which
   reads a workflow file but was not in workflow-trigger-lint's guard step, the
   only job with no paths filter. A PR editing only workflow files never
   collected it. Added.

The 1054 tests in the guard step pass, as does tests/studio (9687 passed; the two
failures there are on main already and untouched by this: an mlx import and a
PR-scoped guard).

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Tighten the comments this PR adds

Comment/docstring text only. comment_tools.py check --strict-ext
--allow-docstring-edits: 3/3 OK. The guard step's 1054 tests still pass, and the
driver still runs green end to end against a real Studio.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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