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.

CUDA spoof: cover CUDA wheels on GPU-less runners, not only CPU wheels (#14056)

Daniel Hane0dc2843d765
diff --git a/tests/_zoo_aggressive_cuda_spoof.py b/tests/_zoo_aggressive_cuda_spoof.py
index 9e900ab45fb..53be1f82328 100644
--- a/tests/_zoo_aggressive_cuda_spoof.py
+++ b/tests/_zoo_aggressive_cuda_spoof.py
@@ -35,9 +35,15 @@ def apply() -> None:
torch.cuda.is_bf16_supported = lambda *a, **k: True
torch.cuda._is_in_bad_fork = lambda *a, **k: False # type: ignore[attr-defined]
- # CPU-only wheels lack _cuda_getCurrentRawStream, which unsloth/kernels/utils.py reads at import.
- # 0 is the default stream; set only when absent so real CUDA keeps its own.
- if not hasattr(torch._C, "_cuda_getCurrentRawStream"):
+ # unsloth/kernels/utils.py reads _cuda_getCurrentRawStream at import. CPU-only wheels lack it,
+ # and a CUDA wheel on a runner with no driver has it but raises (a notebook install cell that
+ # pulls vLLM brings in such a wheel). 0 is the default stream; a working handle is kept.
+ _raw_stream = getattr(torch._C, "_cuda_getCurrentRawStream", None)
+ try:
+ _raw_stream_works = _raw_stream is not None and _raw_stream(0) is not None
+ except Exception:
+ _raw_stream_works = False
+ if not _raw_stream_works:
torch._C._cuda_getCurrentRawStream = lambda index = 0: 0 # type: ignore[attr-defined]
class _Props:
diff --git a/tests/test_cuda_spoof_supplies_the_raw_stream.py b/tests/test_cuda_spoof_supplies_the_raw_stream.py
index b82a09c16b0..4b029aba752 100644
--- a/tests/test_cuda_spoof_supplies_the_raw_stream.py
+++ b/tests/test_cuda_spoof_supplies_the_raw_stream.py
@@ -84,3 +84,37 @@ def test_the_spoof_leaves_a_real_raw_stream_alone():
assert (
"VALUE 4242" in out.stdout
), f"the spoof overwrote a raw-stream handle that was already there: {out.stdout}\n{out.stderr}"
+
+
+def test_the_spoof_replaces_a_raw_stream_that_has_no_driver_behind_it():
+ """A CUDA wheel on a GPU-less runner carries the symbol, but calling it raises.
+
+ The notebooks smoke leg for Llama3.1 GRPO installs vLLM, which brings in torch 2.13.0+cu130,
+ and importing unsloth then died in kernels/utils.py with "CUDA driver version is insufficient
+ for CUDA runtime version". The spoof has to cover that wheel the same way it covers a CPU one.
+ """
+ script = textwrap.dedent(
+ f"""
+ import ctypes, sys
+ sys.path.insert(0, {str(_TESTS)!r})
+ import torch
+
+ def driverless(index = 0):
+ raise RuntimeError("CUDA error: CUDA driver version is insufficient for CUDA runtime version")
+
+ torch._C._cuda_getCurrentRawStream = driverless
+ import _zoo_aggressive_cuda_spoof as spoof
+ spoof.apply()
+ try:
+ handle = ctypes.c_void_p(torch._C._cuda_getCurrentRawStream(0))
+ except Exception as e:
+ print("POST raised", type(e).__name__)
+ else:
+ print("POST ok", handle.value)
+ """
+ )
+ out = subprocess.run([sys.executable, "-c", script], capture_output = True, text = True)
+ assert "POST ok None" in out.stdout, (
+ "the spoof kept a raw-stream handle that raises without a driver, so importing unsloth "
+ f"under a CUDA wheel on a GPU-less runner still fails: {out.stdout}\n{out.stderr}"
+ )