Repository navigation
Give the CUDA spoof the raw-stream handle unsloth reads at import - #11328
Conversation
Dispatching the notebooks smoke matrix on main took it from 0/8 to 7/8. The one
leg still failing, nb/Llama3.1_(8B)-GRPO.ipynb, dies in Verify imports under
spoof:
File "unsloth/kernels/utils.py", line 248, in <module>
torch._C._cuda_getCurrentRawStream(index)
AttributeError: module 'torch._C' has no attribute '_cuda_getCurrentRawStream'
unsloth snapshots each device's raw stream at import, inside
`if DEVICE_COUNT > 0` -- a branch this spoof makes true by answering
device_count() with 1. A CPU-only torch wheel does not export that symbol. The
spoof already knew: it imports bitsandbytes before flipping is_available()
precisely because bitsandbytes reads it. But it worked around that one importer
and never supplied the symbol, so anything reading it afterwards still died.
Why only this leg, from comparing the install sets: GRPO's install cell is the
one pulling vLLM and the CUDA userspace packages (cuda-python, cuda-bindings,
flashinfer, 85 packages the Alpaca leg never installs), which is what carries
unsloth into the DEVICE_COUNT > 0 branch on a CPU-only torch.
Supply it, and only when absent so a real CUDA build keeps its own handle. 0 is
the null (default) stream; callers wrap it in ctypes.c_void_p and no kernel is
ever launched under the spoof, so a handle naming no stream is the honest value.
Verified by staging the absence and evaluating the expression unsloth evaluates:
deleting the symbol reproduces the AttributeError exactly, and after the spoof
ctypes.c_void_p(...) yields the null pointer. Three tests, covering both spoofs
(_zoo_rocm_spoof delegates to this one) and that a real handle is left alone.
Removing the stub fails both spoof rows.
Not verified here: this box cannot run the smoke matrix, so the leg itself is
still unproven. The failure and the install-set comparison both come from the
dispatched run on main (35434257014).
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex security review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Repo tests (CPU, python) caught what I missed:
FAILED tests/python/test_accelerator_skip_guards.py::test_the_spoofed_probe_list_keeps_up_with_the_spoof
AssertionError: the spoof patches these and this file does not say what they are
torch._C._cuda_getCurrentRawStream
That guard requires every name the spoof patches to be classified: _SPOOFED_CALLS
if a skip guard could read it, _SPOOFED_NON_PREDICATES if none would. I added a
patch without declaring it.
It belongs in the non-predicates. It is a stream handle, not a question:
unsloth/kernels/utils.py reads it at import under `if DEVICE_COUNT > 0` and
wraps it in ctypes.c_void_p, and nothing branches on the value, so no skip guard
could consult it.
Removing the declaration fails the guard again, naming the symbol.
test_accelerator_skip_guards, test_cuda_spoof_supplies_the_raw_stream and
test_cuda_spoof_reports_free_memory together: 29 passed.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…slothai#11328) * Give the CUDA spoof the raw-stream handle unsloth reads at import Dispatching the notebooks smoke matrix on main took it from 0/8 to 7/8. The one leg still failing, nb/Llama3.1_(8B)-GRPO.ipynb, dies in Verify imports under spoof: File "unsloth/kernels/utils.py", line 248, in <module> torch._C._cuda_getCurrentRawStream(index) AttributeError: module 'torch._C' has no attribute '_cuda_getCurrentRawStream' unsloth snapshots each device's raw stream at import, inside `if DEVICE_COUNT > 0` -- a branch this spoof makes true by answering device_count() with 1. A CPU-only torch wheel does not export that symbol. The spoof already knew: it imports bitsandbytes before flipping is_available() precisely because bitsandbytes reads it. But it worked around that one importer and never supplied the symbol, so anything reading it afterwards still died. Why only this leg, from comparing the install sets: GRPO's install cell is the one pulling vLLM and the CUDA userspace packages (cuda-python, cuda-bindings, flashinfer, 85 packages the Alpaca leg never installs), which is what carries unsloth into the DEVICE_COUNT > 0 branch on a CPU-only torch. Supply it, and only when absent so a real CUDA build keeps its own handle. 0 is the null (default) stream; callers wrap it in ctypes.c_void_p and no kernel is ever launched under the spoof, so a handle naming no stream is the honest value. Verified by staging the absence and evaluating the expression unsloth evaluates: deleting the symbol reproduces the AttributeError exactly, and after the spoof ctypes.c_void_p(...) yields the null pointer. Three tests, covering both spoofs (_zoo_rocm_spoof delegates to this one) and that a real handle is left alone. Removing the stub fails both spoof rows. Not verified here: this box cannot run the smoke matrix, so the leg itself is still unproven. The failure and the install-set comparison both come from the dispatched run on main (35434257014). * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Declare the raw-stream handle in the spoofed-probe inventory Repo tests (CPU, python) caught what I missed: FAILED tests/python/test_accelerator_skip_guards.py::test_the_spoofed_probe_list_keeps_up_with_the_spoof AssertionError: the spoof patches these and this file does not say what they are torch._C._cuda_getCurrentRawStream That guard requires every name the spoof patches to be classified: _SPOOFED_CALLS if a skip guard could read it, _SPOOFED_NON_PREDICATES if none would. I added a patch without declaring it. It belongs in the non-predicates. It is a stream handle, not a question: unsloth/kernels/utils.py reads it at import under `if DEVICE_COUNT > 0` and wraps it in ctypes.c_void_p, and nothing branches on the value, so no skip guard could consult it. Removing the declaration fails the guard again, naming the symbol. test_accelerator_skip_guards, test_cuda_spoof_supplies_the_raw_stream and test_cuda_spoof_reports_free_memory together: 29 passed. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
#14056) ## Summary The 2026-10-17 06:39 scheduled `Notebooks CI` run on main (`1018ecbf`, run 39010742438) failed the `nb/Llama3.1_(8B)-GRPO.ipynb` install-cell smoke leg, which passed on the previous scheduled run (2026-10-01): ``` unsloth/kernels/utils.py:251: torch._C._cuda_getCurrentRawStream(index) torch.AcceleratorError: CUDA error: CUDA driver version is insufficient for CUDA runtime version ``` The notebook's non-Colab branch runs `pip install unsloth vllm`, which now brings in `torch 2.13.0+cu130`. `tests/_zoo_aggressive_cuda_spoof.py` only supplied `_cuda_getCurrentRawStream` when the symbol was absent, which is the CPU-wheel case from #11328. A CUDA wheel on a GPU-less runner has the symbol, but calling it raises, so `import unsloth` under the spoof died at that line. The product is fine. The spoof did not cover this wheel. ## Change - **`tests/_zoo_aggressive_cuda_spoof.py`:** `_cuda_getCurrentRawStream` is now replaced when it is absent or when calling it raises. A working handle on a real CUDA machine is still kept. - **`tests/test_cuda_spoof_supplies_the_raw_stream.py`:** new `test_the_spoof_replaces_a_raw_stream_that_has_no_driver_behind_it` stages a raw-stream function that raises the driver error and requires the spoof to replace it. The existing `test_the_spoof_leaves_a_real_raw_stream_alone` still passes. ## Testing - **End to end with the same `torch 2.13.0+cu130` and `CUDA_VISIBLE_DEVICES=""`:** applying the spoof and then `import unsloth` fails on main with `AcceleratorError: CUDA error: no CUDA-capable device is detected`, and passes with this change. - **Spoof tests:** `test_cuda_spoof_supplies_the_raw_stream.py` and `test_cuda_spoof_reports_free_memory.py` give 6 passed. With the spoof reverted, the new test fails. - **Every test file that imports the spoof:** this change and main fail on exactly the same test IDs in my local venv, which lacks the pinned TRL / vLLM versions those tests need. This change adds the new passing test. - **`Notebooks CI` with `include_smoke=true` on the first revision of this branch (run 39015954144):** the GRPO leg passes. That revision also set `UV_SYSTEM_PYTHON` on the install step. It turned the Nemotron and Qwen3_5 failures into different ones and broke gpt-oss, so it is not part of this PR (see below). ## Not in this PR The Nemotron-3-Nano and Qwen3_5 Vision legs fail for a different reason, which this PR leaves alone. Their install cells call `!uv pip install`. Colab sets `UV_SYSTEM_PYTHON=true` (checked on a live `release-colab-external-images_20261014` runtime), but the smoke job does not. The job also sets no `COLAB_*` variable, so the notebooks take their non-Colab branch. Setting only `UV_SYSTEM_PYTHON` lets the uv lines run, but without the Colab branch the result is not Colab's environment: - `transformers==4.57.6` is installed with `--no-deps` next to `huggingface_hub` 1.29. - gpt-oss loses `triton`. Making the job match Colab needs both variables together, and it should be a separate change with its own smoke run. The `static + transitive resolve` red (Colab oracle drifted from its committed snapshot) is also untouched. It has failed on every scheduled run since at least 2026-09-27.
Dispatching the notebooks smoke matrix on
mainafter #11325 and #11326 took it from 0/8 to 7/8. The one leg still failing,nb/Llama3.1_(8B)-GRPO.ipynb, dies inVerify imports under spoof:Why
unsloth snapshots each device's raw stream at import, inside
if DEVICE_COUNT > 0-- a branch this spoof makes true by answeringdevice_count()with 1. A CPU-only torch wheel does not export that symbol.The spoof already knew. Its own comment says so, and it imports bitsandbytes before flipping
is_available()precisely because bitsandbytes reads it:It worked around that one importer and never supplied the symbol, so anything reading it afterwards still died.
Why only this leg
From comparing the install sets of the failing leg against a passing one: the GRPO cell is the one pulling vLLM and the CUDA userspace packages --
cuda-python,cuda-bindings,cuda-core,flashinfer-python,compressed-tensorsamong 85 packages the Alpaca leg never installs. That is what carries unsloth into theDEVICE_COUNT > 0branch on a CPU-only torch.The fix
Supply the symbol, and only when absent, so a real CUDA build keeps its own handle.
0is the null (default) stream: callers wrap it inctypes.c_void_pand no kernel is ever launched under the spoof, so a handle that names no stream is the honest value.Verification
Staged the absence and evaluated the expression unsloth evaluates:
AttributeError: module 'torch._C' has no attribute '_cuda_getCurrentRawStream'ctypes.c_void_p(...)yields the null pointerThree tests: both spoofs supply it (
_zoo_rocm_spoofdelegates to this one, so it is covered too), and a real handle is left alone. Removing the stub fails both spoof rows. Run in a subprocess, because applying a spoof mutates the interpreter's torch for good and this host's torch exports the symbol for real.Not verified here
This box cannot run the smoke matrix, so the leg itself is still unproven. The failure and the install-set comparison both come from the dispatched run on
main(35434257014). The matrix iscron/dispatchonly and will not run on this PR; I will dispatch it onmainonce this lands.One related observation from that run, not addressed here: unsloth now logs
torchcodec 0.0.0 is incompatible with torchand disables it. That is #11325's placeholder being correctly detected as unusable -- non-fatal, and on every leg including the seven that pass.