Skip to content

Studio installers read the NVIDIA driver library when nvidia-smi cannot answer, and setup.ps1 keeps a working GPU prebuilt over a source build - #11007

Merged
danielhanchen merged 18 commits into
mainfrom
bootstrap-selectors-use-nvidia-probe
Sep 15, 2026
Merged

danielhanchen merged 18 commits into
mainfrom
bootstrap-selectors-use-nvidia-probe

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

The bootstrap half of #10985. That PR taught install_llama_prebuilt.py and setup.sh to read the NVIDIA driver's own libraries when nvidia-smi is absent, stale or hangs. The three scripts that choose the torch wheel and decide whether to keep a llama.cpp prebuilt still trusted nvidia-smi alone, and each of them downgrades a working GPU install when it cannot answer.

What was wrong

  • setup.ps1 treated an unknown driver version as cu126. Get-PytorchCudaTag returned cu126 when nvidia-smi was missing or its banner did not parse. The stale check compared that with the installed cu130 wheel, called the venv stale, and force-reinstalled torch cu126 over a working cu130 on every update.
  • setup.ps1 exit 2 always went to the source build. When the prebuilt update failed (rate limit, network), the Windows script fell straight into a source build. That needs MSVC and nvcc, and with no compute capability it configures -DGGML_CUDA=OFF, so a working CUDA prebuilt was replaced by a CPU build. setup.sh has kept the GPU prebuilt in this case since Studio: keep a working GPU llama.cpp prebuilt over a CPU-only source fallback, and say so in the footer #10975; the Windows side had no guard.
  • install.ps1 and install.sh picked the torch index from nvidia-smi only. No nvidia-smi meant the CPU wheel on Windows, and an unreadable banner meant cu126 on both, even on a host whose driver is loaded and whose GPU NVML lists.
  • setup.ps1 read the compute capability from nvidia-smi only, so the source build turned CUDA off (studio/setup.sh: validate source-built llama.cpp and guard empty CUDA arch detection #5854) on a host where the driver library knows it.

The change

  • Get-NvidiaLibraryInventory, shared between install.ps1 and setup.ps1: P/Invoke methods over nvml.dll (System32 or NVSMI), then nvcuda.dll, emitted through New-StudioEmittedNativeType (the installer compiles nothing) and read once in a runspace with a 10 s deadline (a wedged driver leaves that runspace behind instead of hanging the installer). It returns the CUDA driver version and one compute capability per GPU. UNSLOTH_NVIDIA_LIBRARY_PROBE=0 turns it off, as it does the Python probe. On Linux it loads libnvidia-ml.so.1 / libcuda.so.1, which is how the tests run it under pwsh here.
  • install.sh gets the same reader inline as _nvidia_library_inventory (nvidia_probe.py is not on disk yet when the torch index is chosen), and _has_usable_nvidia_gpu consults it last, after nvidia-smi and /proc/driver/nvidia/gpus.
  • Get-PytorchCudaTag and both Get-TorchIndexUrl / get_torch_index_url take the driver version from the inventory when nvidia-smi cannot name it; the pre-Turing cu126 cap reads the inventory capabilities the same way. With nothing answering, Get-PytorchCudaTag now returns "": the stale check treats that as unknown and keeps the venv, and the install arm keeps the installed CUDA family, falling back to cu126 only when none is installed. The installers keep their cu126 default for a present nvidia-smi whose banner does not parse.
  • An NVIDIA GPU the inventory lists counts as detected in both PowerShell scripts, so the ROCm and Intel arms, the torch stale check and the llama.cpp backend expectations all agree with the Python installer.
  • setup.ps1 exit 2 now asks Get-GpuPrebuiltToKeepOverSourceBuild, the twin of setup.sh's _gpu_prebuilt_to_keep_over_cpu_build: same exemptions (forced compile, a PR build, a release or version pin, an explicit backend request), same vendor check on the marker's backend, and the installed tree must pass --check-installed. When it keeps, the update reports update failed (<reason>); keeping the installed cuda prebuilt, the next update will retry, repeats that in the footer, and the source build is not started.
  • Get-CudaComputeCapability falls back to the inventory's first capability.

Measured

On this host (8x B200, driver 590.48.01, CUDA 13.1), pwsh 7.6 and bash:

result
Get-NvidiaLibraryInventory nvml, CUDA 13.1, 8 x 10.0, 572 ms first call, cached after
same with libnvidia-ml unreachable cuda, CUDA 13.1, the one GPU CUDA_VISIBLE_DEVICES allows
UNSLOTH_NVIDIA_LIBRARY_PROBE=0, or no library at all $null
_nvidia_library_inventory (install.sh) 13.1 10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0

Tests

  • tests/studio/test_nvidia_library_inventory.ps1 (new, wired into the parity workflow on pwsh and Windows PowerShell 5.1): the two helper copies are identical; the switch turns the probe off; the real inventory on an NVIDIA host; Get-PytorchCudaTag from the banner, from the inventory, with the cap on inventory capabilities, and "" when nothing answers; Get-CudaComputeCapability from the inventory; the failure-reason wording; every branch of the keep guard; Get-TorchIndexUrl with no nvidia-smi, an unreadable banner, the cap, the cu126 default and a readable banner.
  • tests/sh/test_get_torch_index_url.sh: an unreadable banner with the library naming 13.0 gives cu130; the library's sm_61 caps to cu126; the probe switched off keeps the cu126 default; no nvidia-smi anywhere with a listed GPU gives the driver's family instead of cpu.
  • Existing: test_pre_turing_cap.ps1, every tests/studio/*.ps1 (26 files), the seven tests/sh files that extract the changed functions, test_cross_platform_parity.py, test_installer_interactive_prompts.py, test_cuda_repair.py and test_nvidia_library_probe.py all pass.

…nnot answer; setup.ps1 keeps a working GPU prebuilt over a source build
@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-15T18:12:26.617976Z fdcbe3a 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 shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 15, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…oolkit filter, and probe once per installer invocation for PR #11007
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

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

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

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

This comment was marked as resolved.

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

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 15, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 15, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

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

This comment was marked as resolved.

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

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 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: 8c487c1213

ℹ️ 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 install.ps1
$int = [int]; $uint = [uint32]; $refInt = [int].MakeByRefType()
$refUInt = [uint32].MakeByRefType(); $refPtr = [IntPtr].MakeByRefType()
try {
$null = New-StudioEmittedNativeType -TypeName $name -Imports @(

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 Gate native type emission before probing NVIDIA

When no usable nvidia-smi is detected—including on CPU- and AMD-only systems—Get-NvidiaLibraryInventory reaches this Reflection.Emit call without first checking Test-StudioCanDefineNativeTypes. On hosts enforcing Dynamic Code Security, the existing emitter documentation notes that loading an unsigned emitted assembly can terminate or crash the parent rather than raise a catchable exception, so the installer can be killed during optional GPU detection. Apply the existing native-type capability gate here (and in the identical studio/setup.ps1 copy) and return no inventory when emission is unsafe.

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.

Fixed in b4acb4d: Get-NvidiaLibraryProbeType checks Test-StudioCanDefineNativeTypes before emitting, in both copies, and returns no inventory when it says no. The inventory test checks the gate is consulted; its real-inventory child stands in for the Windows policy probe.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

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

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

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

Copy link
Copy Markdown

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

Reviewed commit: fdcbe3a036

ℹ️ 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 3a0dae2 into main Sep 15, 2026
75 of 76 checks passed
@danielhanchen
danielhanchen deleted the bootstrap-selectors-use-nvidia-probe branch September 15, 2026 18:32
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…ot answer, and setup.ps1 keeps a working GPU prebuilt over a source build (unslothai#11007)

* Bootstrap selectors read the NVIDIA driver library when nvidia-smi cannot answer; setup.ps1 keeps a working GPU prebuilt over a source build

* Reject a failed driver-version read, feed the inventory to the CUDA toolkit filter, and probe once per installer invocation for PR unslothai#11007

* Void a partial capability inventory, initialise the setup.ps1 cache with its script state for PR unslothai#11007

* Read legacy prebuilt marker shapes in the setup.ps1 keep guard, for PR unslothai#11007

* master asks for a source build, so the keep guard does not keep over it, for PR unslothai#11007

* Read the driver library inventory once per run, for PR unslothai#11007

* Read the driver library with the managed venv's interpreter when there is no system python3, and do not remember a missing one, for PR unslothai#11007

* The inline driver-library reader falls through to the CUDA driver API when NVML raises, and the presence check primes its memo in the parent shell, for PR unslothai#11007

* Name nvml.dll by its System32 or NVSMI path in both PowerShell copies, for PR unslothai#11007

* Keep a Vulkan prebuilt for any Intel adapter, as the selector routes them, for PR unslothai#11007

* Emit the driver-library P/Invoke methods instead of compiling them, read them in a runspace under the deadline, and print the inventory notice through Write-StudioLine, for PR unslothai#11007

* Compare the nvml.dll path as returned, for PR unslothai#11007

* Allow the inventory's native imports and stub the keep guard in the routing harness, for PR unslothai#11007

* Skip the NVIDIA prime for a pinned index or no torch, for PR unslothai#11007

* Read the CUDA driver API with the visibility mask lifted, in the shell and PowerShell readers, for PR unslothai#11007

* Do not rediscover a rejected nvidia-smi once the library stood in, for PR unslothai#11007

* Gate the emitted probe type on the native-type capability, for PR unslothai#11007

* Balance the helper-file expression in the inventory test, for PR unslothai#11007

---------

Co-authored-by: danielhanchen <[email protected]>
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