Repository navigation
Studio: defer the Windows CUDA Toolkit check so prebuilt users are not blocked - #5912
Conversation
…t blocked setup.ps1 section 1e validated the installed CUDA Toolkit against the driver in Phase 1 and hard-exited when the toolkit was newer than the driver supports. That ran before the prebuilt llama.cpp install (Phase 3.4), which is self-contained and needs no local toolkit. A Blackwell host (sm_120) on a driver that advertises CUDA 13.2 with CUDA Toolkit 13.3 installed was blocked entirely, even though the prebuilt selector would have given it a working GPU build. The toolkit (nvcc) is only consumed by the Phase 4 source build. Move section 1e into a Resolve-CudaToolkit function and call it lazily at the source-compile branch, gated on $HasNvidiaSmi. The prebuilt path no longer touches the toolkit; forced/source builds keep the identical requirement, winget auto-install, and error text via -RequireOrExit. Add a pwsh unit test that extracts the real function and runs it against a spoofed Blackwell sm_120 / driver 13.2 / toolkit 13.3 host: the prebuilt path defers, the forced build still fails fast. Refs #5879.
There was a problem hiding this comment.
Code Review
This pull request refactors the CUDA toolkit resolution logic in studio/setup.ps1 into a lazy-loaded function Resolve-CudaToolkit with a -RequireOrExit switch, allowing the prebuilt path to skip local toolkit requirements while ensuring source builds fail fast if a compatible toolkit is missing. It also introduces a comprehensive unit test suite (tests/studio/test_resolve_cuda_toolkit.ps1) to verify these scenarios. The review feedback suggests backing up and restoring the user's CUDA_PATH environment variable during the unit tests to prevent persistent side effects on the host machine.
| $ErrorActionPreference = "Stop" | ||
| $setupPath = [System.IO.Path]::Combine($PSScriptRoot, "..", "..", "studio", "setup.ps1") |
There was a problem hiding this comment.
To prevent the unit test from persistently modifying the user's registry/environment variables (specifically CUDA_PATH at the User level) during Scenario 3, we should back up the existing CUDA_PATH value at the start of the script and restore it in the finally block.
$ErrorActionPreference = "Stop"
$oldUserCudaPath = [Environment]::GetEnvironmentVariable('CUDA_PATH', 'User')
$setupPath = [System.IO.Path]::Combine($PSScriptRoot, "..", "..", "studio", "setup.ps1")
| finally { | ||
| Remove-Item -Recurse -Force -LiteralPath $work -ErrorAction SilentlyContinue | ||
| } |
There was a problem hiding this comment.
Restore the original CUDA_PATH user environment variable in the finally block to ensure no persistent side effects are left on the host machine after running the tests.
finally {
[Environment]::SetEnvironmentVariable('CUDA_PATH', $oldUserCudaPath, 'User')
Remove-Item -Recurse -Force -LiteralPath $work -ErrorAction SilentlyContinue
}
The deferred Windows CUDA Toolkit check (Resolve-CudaToolkit in setup.ps1) has a pwsh unit test but nothing ran it. Rather than add a separate workflow, fold a fast GPU-free gate into the existing Windows GGUF CI: parse setup.ps1 and run tests/studio/test_resolve_cuda_toolkit.ps1 right after checkout, before the heavy GGUF smoke, so a setup.ps1 regression fails fast on the runner that is already spun up. Refs #5912.
…job (#5921) The deferred Windows CUDA Toolkit check (Resolve-CudaToolkit in setup.ps1) has a pwsh unit test but nothing ran it. Rather than add a separate workflow, fold a fast GPU-free gate into the existing Windows GGUF CI: parse setup.ps1 and run tests/studio/test_resolve_cuda_toolkit.ps1 right after checkout, before the heavy GGUF smoke, so a setup.ps1 regression fails fast on the runner that is already spun up. Refs #5912.
Summary
A Blackwell user hit this on Windows setup:
studio/setup.ps1section "1e. CUDA Toolkit" validates the installed toolkit against the driver in Phase 1 and hardexit 1s when the toolkit is newer than the driver supports and no compatible toolkit is found. That runs before Phase 3.4, which installs a self-contained prebuilt llama.cpp bundle that needs no local CUDA toolkit. So this host is blocked entirely, even though the prebuilt selector would hand it a working GPU build (driver 13.2 can run the pinnedb9360cuda-13.1build, sm_120 covered).nvcc /
CUDA_PATHare only consumed by the Phase 4 source build. This moves section 1e into aResolve-CudaToolkitfunction and calls it lazily only when a source compile is actually about to run.What changed
studio/setup.ps1: section 1e becomesfunction Resolve-CudaToolkit { param([switch]$RequireOrExit) ... }, invoked at the source-compile branch asif ($HasNvidiaSmi) { Resolve-CudaToolkit -RequireOrExit }.-RequireOrExitkeeps the identical behavior - the same driver check, winget auto-install, and the byte-for-byte error text - and still fails fast before compiling.$script:NvccPath/$script:CudaToolkitRoot/$script:CudaArchfor the build (the build reads the bare names, which resolve to script scope).tests/studio/test_resolve_cuda_toolkit.ps1: extracts the real function via AST and runs it against a spoofed Blackwell sm_120 / driver 13.2 / toolkit 13.3 host (no GPU needed). Covers: prebuilt path with a too-new toolkit defers and never calls winget; a forced build with the same toolkit still hard-exits with the preserved error; a compatible toolkit resolves and sets the env; winget runs only for a committed source build. Run withpwsh -File tests/studio/test_resolve_cuda_toolkit.ps1on Windows or Linux.Behavior
UNSLOTH_LLAMA_FORCE_COMPILE=1, too-new toolkitValidation
pwshAST parse ofsetup.ps1: no errors.pwsh -File tests/studio/test_resolve_cuda_toolkit.ps1: all checks pass.studio/**) and cover the real-Windows, no-GPU prebuilt path. Since the function is only called when a GPU is present, those runs confirm the non-GPU path is unchanged.Note: a true GPU end-to-end spoof is not a green-able CI target on the free runners (no real CUDA device for
validate_serverto offload to), so the spoofed Blackwell validation runs at the function level via the pwsh test above.Refs #5879.