Skip to content

Unsloth Studio installer (AMD/Windows): don't mistake ZLUDA for an NVIDIA GPU - #11736

Merged
danielhanchen merged 4 commits into
unslothai:mainfrom
LeoBorcherding:zluda-nvcuda-not-nvidia
Sep 27, 2026
Merged

danielhanchen merged 4 commits into
unslothai:mainfrom
LeoBorcherding:zluda-nvcuda-not-nvidia

Conversation

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

Why this PR (the short version)

Some AMD users on Windows get the wrong version of PyTorch from our installer: the NVIDIA one. Unsloth Studio then shows their AMD card as "detected, but PyTorch cannot use it", and training can't use the GPU at all.

The cause is a tool called ZLUDA. People install it to run NVIDIA-only apps (ComfyUI, Stable Diffusion) on AMD cards. It works by pretending to be an NVIDIA driver. Our installer asks Windows "is there an NVIDIA driver here?", ZLUDA says yes, and we install NVIDIA PyTorch on an AMD machine.

What changed

On Windows, the installer's NVIDIA driver-library probe (the fallback for when nvidia-smi is missing) loaded nvcuda.dll by bare name, and fell back to a bare nvml.dll. A bare name makes Windows search PATH, where ZLUDA puts its own nvcuda.dll and nvml.dll, and those answer as an NVIDIA driver. The installer then printed NVIDIA GPU found through the driver library, picked cu118, and installed torch 2.7.1+cu118 on an AMD-only machine.

Reported in the Discord help thread: RX 6800, Windows 11, with an old ZLUDA folder on PATH from before a reinstall. Taking it off PATH and rerunning the installer fixed it.

  • nvcuda.dll is loaded from %SystemRoot%\System32 by full path. The NVIDIA driver always installs it there, and with a bare name the loader already checked System32 before PATH, so real NVIDIA hosts load the same file as before.
  • When no nvml.dll exists, the fallback is now the System32 path instead of the bare name. The NVSMI location for older drivers is unchanged.
  • The emitted P/Invoke type goes from UnslothNvidiaProbeV2 to V3. Under irm | iex, a session that already built V2 would otherwise keep reusing its bare-name bindings.
  • The shared block is kept identical in install.ps1 and studio/setup.ps1. studio/nvidia_probe.py needs no change, because ctypes.CDLL on Python 3.8+ doesn't search PATH (checked: a bare nvcuda.dll placed only on PATH fails to load there).

Before / after

Same box, same command. A stand-in nvcuda.dll (a small Rust cdylib reporting one CUDA 11.8 device, the way ZLUDA answers) is prepended to PATH, and Get-NvidiaLibraryInventory is run from each tree's studio/setup.ps1:

Windows PowerShell 5.1 (the reporter's shell)
before, upstream/main cc33d51 {"Source":"cuda","CudaMajor":11,"CudaMinor":8,"Count":1}, so the installer picks cu118
after, this branch bb998ec null: it tries C:\WINDOWS\System32\nvcuda.dll, finds nothing, and the host stays AMD

Healthy direction: the same stand-in, placed in <SystemRoot>\System32 with nothing on PATH, is still found on PowerShell 7.6 ({"Source":"cuda","CudaMajor":11,...}, measured at c2ad507, before the merge of main, which didn't touch these functions). On 5.1, cuInit loads and returns 0 from the System32 path. The full 5.1 inventory couldn't be checked that way, because overriding SystemRoot breaks 5.1's child runspace (unmodified main returns null under the same override).

Run on an R9700, Windows 11 24H2, Windows PowerShell 5.1.26100 and PowerShell 7.6.6. This box has no NVIDIA driver, so a real NVIDIA host running through this branch hasn't been tested. A run on one (any driver, with nvidia-smi renamed so the library path is taken) is the missing row.

Tests

  • tests/studio/test_nvidia_library_inventory.ps1: the new helper joins the shared-block parity check. "No nvml.dll keeps the bare name" is now "names the System32 path", and a new check pins nvcuda.dll to the System32 path. All checks pass at bb998ec.
  • test_nvidia_smi_discovery.ps1 passes at bb998ec. test_windows_installer_native_type_fallback.py, test_nvidia_library_probe.py and test_installer_av_shapes.py at c2ad507: 366 pass. The same 7 fail on unmodified upstream/main on this machine (symlink sweep and compile-watcher tests), so they don't come from this change.

…en for an NVIDIA GPU

The Windows driver-library probe bound nvcuda.dll by bare name and fell back to a bare
nvml.dll, so the loader searched PATH. ZLUDA ships both DLLs and answers them as an NVIDIA
driver, which made an RX 6800 host install torch 2.7.1+cu118. Name both by full path and bump
the emitted type so a session that already built the bare-name one does not reuse it.

@LeoBorcherding LeoBorcherding left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Codex findings, via a mirror

Codex does not answer on this repository, so it ran against a copy of this pull request's commits at LeoBorcherding/unsloth-staging-review#18. It looked at 908be23cc6 there, which is this PR's 04169ebb6 replayed onto main 1ecc01a30. Nothing was reviewed or resolved on the copy: the findings are here, in Codex's words, to be worked through on this pull request.

Codex found no major issues. Its comment: https://github.com/LeoBorcherding/unsloth-staging-review/pull/18#issuecomment-5824889361

@LeoBorcherding LeoBorcherding changed the title Unsloth Studio Installer (AMD/Windows): stop taking ZLUDA's nvcuda.dll for an NVIDIA GPU Unsloth Studio installer (AMD/Windows): don't mistake ZLUDA for an NVIDIA GPU Sep 25, 2026
@danielhanchen danielhanchen self-assigned this Sep 26, 2026
@shimmyshimmer

shimmyshimmer commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Review record for #11736, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#148.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror 14ca16918c (this PR's 99f65c1cf)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 14ca16918c

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 14ca16918c (this PR's 99f65c1cf).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 26, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 27, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 27, 2026
@danielhanchen
danielhanchen merged commit ecbb0d9 into unslothai:main Sep 27, 2026
52 of 59 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…IDIA GPU (unslothai#11736)

* Load the NVIDIA driver libraries by System32 path so ZLUDA is not taken for an NVIDIA GPU

The Windows driver-library probe bound nvcuda.dll by bare name and fell back to a bare
nvml.dll, so the loader searched PATH. ZLUDA ships both DLLs and answers them as an NVIDIA
driver, which made an RX 6800 host install torch 2.7.1+cu118. Name both by full path and bump
the emitted type so a session that already built the bare-name one does not reuse it.

* Trim comments on the System32-pinned NVIDIA library probe

---------

Co-authored-by: Daniel Han <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants