Skip to content

Studio: defer the Windows CUDA Toolkit check so prebuilt users are not blocked - #5912

Merged
danielhanchen merged 3 commits into
mainfrom
studio-windows-cuda-toolkit-defer
Jun 1, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-windows-cuda-toolkit-defer

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

A Blackwell user hit this on Windows setup:

GPU Compute Capability = 12.0 (sm_120)
driver supports up to CUDA 13.2
CUDA_PATH (...CUDA\v13.3) has CUDA 13.3 which exceeds driver max 13.2
[ERROR] CUDA Toolkit 13.3 is installed but INCOMPATIBLE ... exit code 1

studio/setup.ps1 section "1e. CUDA Toolkit" validates the installed toolkit against the driver in Phase 1 and hard exit 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 pinned b9360 cuda-13.1 build, sm_120 covered).

nvcc / CUDA_PATH are only consumed by the Phase 4 source build. This moves section 1e into a Resolve-CudaToolkit function and calls it lazily only when a source compile is actually about to run.

What changed

  • studio/setup.ps1: section 1e becomes function Resolve-CudaToolkit { param([switch]$RequireOrExit) ... }, invoked at the source-compile branch as if ($HasNvidiaSmi) { Resolve-CudaToolkit -RequireOrExit }.
    • Prebuilt path: never calls the function, so a too-new or missing toolkit no longer blocks install.
    • Source build: -RequireOrExit keeps the identical behavior - the same driver check, winget auto-install, and the byte-for-byte error text - and still fails fast before compiling.
    • The function publishes $script:NvccPath / $script:CudaToolkitRoot / $script:CudaArch for 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 with pwsh -File tests/studio/test_resolve_cuda_toolkit.ps1 on Windows or Linux.

Behavior

Host Before After
Blackwell, driver 13.2, toolkit 13.3, prebuilt path exit 1 at the toolkit check installs the prebuilt (no toolkit needed)
UNSLOTH_LLAMA_FORCE_COMPILE=1, too-new toolkit exit 1 with the incompatible error exit 1 with the same error (just lazily)
Compatible toolkit, source build resolves, sets CUDA env identical
No GPU unchanged unchanged (function never called)

Validation

  • pwsh AST parse of setup.ps1: no errors.
  • pwsh -File tests/studio/test_resolve_cuda_toolkit.ps1: all checks pass.
  • The existing Windows GGUF smoke jobs run on this PR (they path-trigger on 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_server to offload to), so the spoofed Blackwell validation runs at the function level via the pwsh test above.

Refs #5879.

…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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +11 to +12
$ErrorActionPreference = "Stop"
$setupPath = [System.IO.Path]::Combine($PSScriptRoot, "..", "..", "studio", "setup.ps1")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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")

Comment on lines +115 to +117
finally {
Remove-Item -Recurse -Force -LiteralPath $work -ErrorAction SilentlyContinue
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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
}

@danielhanchen
danielhanchen merged commit fc09d8f into main Jun 1, 2026
33 checks passed
@danielhanchen
danielhanchen deleted the studio-windows-cuda-toolkit-defer branch June 1, 2026 09:55
danielhanchen added a commit that referenced this pull request Jun 1, 2026
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.
danielhanchen added a commit that referenced this pull request Jun 1, 2026
…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.
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.

1 participant