Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

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

Leo Borcherdingecbb0d9125e6
diff --git a/install.ps1 b/install.ps1
index 50fe47c91b4..bb68eebb042 100644
--- a/install.ps1
+++ b/install.ps1
@@ -8513,8 +8513,7 @@ exit 0
}
# ── BEGIN SHARED WITH studio/setup.ps1 (Get-NvidiaLibraryInventory) ──
- # nvml.dll sits in System32 with current drivers and under NVSMI with older ones; a bare
- # name reaches only the former, so name the file, as studio/nvidia_probe.py does.
+ # Full paths only: a bare name searches PATH, where ZLUDA's nvcuda.dll and nvml.dll pass for NVIDIA.
function Get-NvidiaNvmlLibraryPath {
$dirs = @()
if ($env:SystemRoot) { $dirs += (Join-Path $env:SystemRoot "System32") }
@@ -8523,14 +8522,20 @@ exit 0
$candidate = Join-Path $dir "nvml.dll"
if (Test-Path -LiteralPath $candidate) { return $candidate }
}
- return "nvml.dll"
+ return (Join-Path (Get-NvidiaSystem32Dir) "nvml.dll")
+ }
+
+ function Get-NvidiaSystem32Dir {
+ $root = if ($env:SystemRoot) { $env:SystemRoot } else { "C:\Windows" }
+ return (Join-Path $root "System32")
}
# The driver's libraries as P/Invoke methods, emitted rather than compiled: the installer must
# not spawn csc.exe (New-StudioEmittedNativeType). $null when the type cannot be built. A
# missing library throws at the first call, not here.
function Get-NvidiaLibraryProbeType {
- $name = "UnslothNvidiaProbeV2"
+ # V3: a session that emitted V2 would keep its bare-name bindings.
+ $name = "UnslothNvidiaProbeV3"
$existing = $name -as [type]
if ($existing) { return $existing }
# Dynamic Code Security can kill the process on an emitted load rather than throw: the
@@ -8538,7 +8543,7 @@ exit 0
if (-not (Test-StudioCanDefineNativeTypes)) { return $null }
$windows = ($env:OS -eq "Windows_NT")
$nvml = if ($windows) { Get-NvidiaNvmlLibraryPath } else { "libnvidia-ml.so.1" }
- $cuda = if ($windows) { "nvcuda.dll" } else { "libcuda.so.1" }
+ $cuda = if ($windows) { Join-Path (Get-NvidiaSystem32Dir) "nvcuda.dll" } else { "libcuda.so.1" }
$int = [int]; $uint = [uint32]; $refInt = [int].MakeByRefType()
$refUInt = [uint32].MakeByRefType(); $refPtr = [IntPtr].MakeByRefType()
try {
diff --git a/studio/setup.ps1 b/studio/setup.ps1
index ee29f8b0116..1703eb6c021 100644
--- a/studio/setup.ps1
+++ b/studio/setup.ps1
@@ -1486,8 +1486,7 @@ function Get-CudaFamilyCappedForPreTuring {
}
# ── BEGIN SHARED WITH install.ps1 (Get-NvidiaLibraryInventory) ──
-# nvml.dll sits in System32 with current drivers and under NVSMI with older ones; a bare
-# name reaches only the former, so name the file, as studio/nvidia_probe.py does.
+# Full paths only: a bare name searches PATH, where ZLUDA's nvcuda.dll and nvml.dll pass for NVIDIA.
function Get-NvidiaNvmlLibraryPath {
$dirs = @()
if ($env:SystemRoot) { $dirs += (Join-Path $env:SystemRoot "System32") }
@@ -1496,14 +1495,20 @@ function Get-NvidiaNvmlLibraryPath {
$candidate = Join-Path $dir "nvml.dll"
if (Test-Path -LiteralPath $candidate) { return $candidate }
}
- return "nvml.dll"
+ return (Join-Path (Get-NvidiaSystem32Dir) "nvml.dll")
+}
+
+function Get-NvidiaSystem32Dir {
+ $root = if ($env:SystemRoot) { $env:SystemRoot } else { "C:\Windows" }
+ return (Join-Path $root "System32")
}
# The driver's libraries as P/Invoke methods, emitted rather than compiled: the installer must
# not spawn csc.exe (New-StudioEmittedNativeType). $null when the type cannot be built. A
# missing library throws at the first call, not here.
function Get-NvidiaLibraryProbeType {
- $name = "UnslothNvidiaProbeV2"
+ # V3: a session that emitted V2 would keep its bare-name bindings.
+ $name = "UnslothNvidiaProbeV3"
$existing = $name -as [type]
if ($existing) { return $existing }
# Dynamic Code Security can kill the process on an emitted load rather than throw: the
@@ -1511,7 +1516,7 @@ function Get-NvidiaLibraryProbeType {
if (-not (Test-StudioCanDefineNativeTypes)) { return $null }
$windows = ($env:OS -eq "Windows_NT")
$nvml = if ($windows) { Get-NvidiaNvmlLibraryPath } else { "libnvidia-ml.so.1" }
- $cuda = if ($windows) { "nvcuda.dll" } else { "libcuda.so.1" }
+ $cuda = if ($windows) { Join-Path (Get-NvidiaSystem32Dir) "nvcuda.dll" } else { "libcuda.so.1" }
$int = [int]; $uint = [uint32]; $refInt = [int].MakeByRefType()
$refUInt = [uint32].MakeByRefType(); $refPtr = [IntPtr].MakeByRefType()
try {
diff --git a/tests/studio/test_nvidia_library_inventory.ps1 b/tests/studio/test_nvidia_library_inventory.ps1
index a3bc4b8a277..8377e1f6b97 100644
--- a/tests/studio/test_nvidia_library_inventory.ps1
+++ b/tests/studio/test_nvidia_library_inventory.ps1
@@ -63,7 +63,7 @@ $setupPs1 = Join-Path $root "studio\setup.ps1"
Write-Host ""
Write-Host "=== shared inventory helper ==="
-$blockNames = @("Get-NvidiaNvmlLibraryPath", "Get-NvidiaLibraryProbeType", "Read-NvidiaLibraryRaw", "Get-NvidiaLibraryInventory")
+$blockNames = @("Get-NvidiaNvmlLibraryPath", "Get-NvidiaLibraryProbeType", "Read-NvidiaLibraryRaw", "Get-NvidiaLibraryInventory", "Get-NvidiaSystem32Dir")
$installParts = @(Get-HelperSources $installPs1 $blockNames)
$setupParts = @(Get-HelperSources $setupPs1 $blockNames)
$installBlock = $installParts[3]
@@ -79,6 +79,7 @@ for ($k = 0; $k -lt $blockNames.Count; $k++) {
Check "the inventory compiles nothing" ((($setupParts -join "`n") -notmatch 'Add-Type') -and ($setupParts[1] -match 'New-StudioEmittedNativeType'))
Check "the emission is gated on the native-type capability" ($setupParts[1] -match 'if \(-not \(Test-StudioCanDefineNativeTypes\)\) \{ return \$null \}')
Invoke-Expression $setupPath
+Invoke-Expression $setupParts[4]
$pathRoot = Join-Path ([System.IO.Path]::GetTempPath()) ("unsloth-nvml-" + [guid]::NewGuid().ToString("N"))
$sys32 = Join-Path (Join-Path $pathRoot "root") "System32"
$nvsmi = Join-Path (Join-Path $pathRoot "pf") "NVIDIA Corporation\NVSMI"
@@ -86,7 +87,7 @@ New-Item -ItemType Directory -Path $sys32, $nvsmi -Force | Out-Null
$savedRoot = $env:SystemRoot; $savedPf = $env:ProgramFiles
try {
$env:SystemRoot = Join-Path $pathRoot "root"; $env:ProgramFiles = Join-Path $pathRoot "pf"
- Check "no nvml.dll on disk keeps the bare name" ((Get-NvidiaNvmlLibraryPath) -eq "nvml.dll")
+ Check "no nvml.dll on disk still names the System32 path" ((Get-NvidiaNvmlLibraryPath) -eq (Join-Path $sys32 "nvml.dll"))
Set-Content -Path (Join-Path $nvsmi "nvml.dll") -Value ""
Check "an NVSMI-only nvml.dll is named by its path" ((Get-NvidiaNvmlLibraryPath) -eq (Join-Path $nvsmi "nvml.dll"))
Set-Content -Path (Join-Path $sys32 "nvml.dll") -Value ""
@@ -95,6 +96,7 @@ try {
$env:SystemRoot = $savedRoot; $env:ProgramFiles = $savedPf
Remove-Item -LiteralPath $pathRoot -Recurse -Force -ErrorAction SilentlyContinue
}
+Check "nvcuda.dll is bound by its System32 path" ($setupParts[1] -match '\$cuda = if \(\$windows\) \{ Join-Path \(Get-NvidiaSystem32Dir\) "nvcuda\.dll" \}')
Check "a failed driver-version read is not an inventory" (
$readBlock -match 'nvmlSystemGetCudaDriverVersion_v2\(\[ref\]\$ver\) -ne 0' -and
$readBlock -match 'cuDriverGetVersion\(\[ref\]\$ver\) -ne 0')