Repository navigation
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
Conversation
…nnot answer; setup.ps1 keeps a working GPU prebuilt over a source build
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…oolkit filter, and probe once per installer invocation for PR #11007
|
@codex security review |
…ith its script state for PR #11007
…l and PowerShell readers, for PR #11007
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 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".
| $int = [int]; $uint = [uint32]; $refInt = [int].MakeByRefType() | ||
| $refUInt = [uint32].MakeByRefType(); $refPtr = [IntPtr].MakeByRefType() | ||
| try { | ||
| $null = New-StudioEmittedNativeType -TypeName $name -Imports @( |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
|
@codex review |
1 similar comment
|
@codex review |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…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]>
The bootstrap half of #10985. That PR taught
install_llama_prebuilt.pyandsetup.shto 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.ps1treated an unknown driver version as cu126.Get-PytorchCudaTagreturnedcu126when nvidia-smi was missing or its banner did not parse. The stale check compared that with the installedcu130wheel, called the venv stale, and force-reinstalled torch cu126 over a working cu130 on every update.setup.ps1exit 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.shhas 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.ps1andinstall.shpicked 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.ps1read 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 betweeninstall.ps1andsetup.ps1: P/Invoke methods overnvml.dll(System32 or NVSMI), thennvcuda.dll, emitted throughNew-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=0turns it off, as it does the Python probe. On Linux it loadslibnvidia-ml.so.1/libcuda.so.1, which is how the tests run it under pwsh here.install.shgets the same reader inline as_nvidia_library_inventory(nvidia_probe.pyis not on disk yet when the torch index is chosen), and_has_usable_nvidia_gpuconsults it last, after nvidia-smi and/proc/driver/nvidia/gpus.Get-PytorchCudaTagand bothGet-TorchIndexUrl/get_torch_index_urltake 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-PytorchCudaTagnow 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.setup.ps1exit 2 now asksGet-GpuPrebuiltToKeepOverSourceBuild, the twin ofsetup.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 reportsupdate 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-CudaComputeCapabilityfalls 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:
Get-NvidiaLibraryInventorynvml, CUDA 13.1, 8 x10.0, 572 ms first call, cached afterlibnvidia-mlunreachablecuda, CUDA 13.1, the one GPUCUDA_VISIBLE_DEVICESallowsUNSLOTH_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.0Tests
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-PytorchCudaTagfrom the banner, from the inventory, with the cap on inventory capabilities, and""when nothing answers;Get-CudaComputeCapabilityfrom the inventory; the failure-reason wording; every branch of the keep guard;Get-TorchIndexUrlwith 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.test_pre_turing_cap.ps1, everytests/studio/*.ps1(26 files), the seventests/shfiles that extract the changed functions,test_cross_platform_parity.py,test_installer_interactive_prompts.py,test_cuda_repair.pyandtest_nvidia_library_probe.pyall pass.