Repository navigation
tests: import bitsandbytes before the CUDA/ROCm spoof so Repo tests (CPU) is green again - #7461
danielhanchen wants to merge 1 commit into
Conversation
…survive
Repo tests (CPU) is red on main: the 12 tests in
tests/studio/install/test_rocm_rdna_routing.py all error at fixture setup
with "child produced no result".
tests/_zoo_aggressive_cuda_spoof.apply() sets torch.cuda.is_available() to
True, and tests/_zoo_rocm_spoof.apply() layers torch.version.hip on top of
it. bitsandbytes picks its backend at import time:
if torch.cuda.is_available():
from .backends.cuda import ops as cuda_ops
and bitsandbytes/backends/cuda/ops.py binds
torch._C._cuda_getCurrentRawStream, which the CPU-only torch build on the
runner does not have. The routing test spawns a child that applies the spoof
and then imports unsloth_zoo, whose temporary_patches.moe_utils does
"import bitsandbytes as bnb". Under the spoof that import takes the
CUDA/ROCm branch and dies with
AttributeError: module 'torch._C' has no attribute '_cuda_getCurrentRawStream'
before the child can print its RESULT line. The libhipblas.so.2 load error
and the missing rocminfo in the same stderr are logged by bitsandbytes, not
fatal.
tests/conftest.py already gets the safe ordering for free, because it
imports unsloth at collection time, before any fixture spoofs torch.
Subprocess children that apply the spoof standalone do not, so do the same
thing in the spoof itself: import bitsandbytes once while the device probes
are still honest. That pins the CPU backend and every later import reuses
the cached module.
The routing assertions are unchanged and still run for real: the child
resolves device_type "hip", is_hip() True, and ("rocm", gfx) for all 11
RDNA2/3/3.5/4 arches.
Also surface the child's exit code in the fixture assertion so the next
breakage of this shape names itself.
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
|
CI evidence on this PR's own The 12 |
|
Note on the red On this branch the job goes from 12 errors to 1 failure, and passing tests go 2716 -> 2867. All twelve which is the raw px utilities in |
|
Superseded by #7469, which landed the same bitsandbytes pre-import and fixed the ROCm routing errors on main. That PR puts the import inside this test file's child code; this one put it in the shared |
Problem
Backend CI / Repo tests (CPU)is red onmain, so every open PR inherits a red check. The last three completed runs onmainfail identically (runs 30189939987, 30183620518, 30180331443):2716 passed, 72 skipped, 12 errors, with all 12 errors being setup errors in one file,tests/studio/install/test_rocm_rdna_routing.py:Root cause
The
routedmodule fixture runs a child process that appliestests/_zoo_rocm_spoof, importsunsloth_zoo.device_type/unsloth_zoo.llama_cpp, and prints aRESULT {json}line the parent parses. The child dies before printing it._zoo_aggressive_cuda_spoof.apply()(which_zoo_rocm_spoof.apply()delegates to) setstorch.cuda.is_available()toTrue, and the ROCm spoof then layerstorch.version.hipon top.bitsandbytespicks its backend at import time:and
bitsandbytes/backends/cuda/ops.pybindstorch._C._cuda_getCurrentRawStream, which the CPU-only torch build on the runner does not have. The child importsunsloth_zoo, whosetemporary_patches.moe_utilsdoesimport bitsandbytes as bnb, that import takes the CUDA/ROCm branch under the spoof, and the child dies with:The
libhipblas.so.2: cannot open shared object fileline and therocminfo"no such file" line that appear earlier in the same stderr are logged by bitsandbytes and are not fatal: bitsandbytes catches that failure and installs a mock native library. They are the visible symptom of the spoofed HIP identity, not the cause of the crash.The job started failing without a code change on our side because it installs
bitsandbytes>=0.45, which now resolves to 0.50.0, and that release imports the CUDA backend ops module eagerly at package import.Fix
tests/conftest.pyalready gets the safe ordering for free: it importsunslothat collection time, before any fixture spoofs torch, so in-process tests always see a bitsandbytes that was resolved against honest device probes. Subprocess children that apply the spoof standalone do not.So the spoof itself now does the same thing:
_zoo_aggressive_cuda_spoof.apply()imports bitsandbytes once, before it flipstorch.cuda.is_available(). That pins the CPU backend and every laterimport bitsandbytesreuses the cached module. The import is guarded, so a host without bitsandbytes (or with a broken build) is unaffected.This keeps the coverage intact. No test is deleted, xfailed, skipped, or weakened. The child still resolves
get_device_type()to"hip",is_hip()toTrue, andlc._detect_gpu_target()to("rocm", gfx)for all 11 RDNA2 / RDNA3 / RDNA3.5 / RDNA4 arches, against realunsloth_zoocode.The fixture assertion also now reports the child's exit code alongside stdout and stderr, so the next breakage of this shape is obvious from the log.
Verification
Reproduced locally in a venv that mirrors the job (Python 3.12, CPU-only
torch 2.10.0+cpu,bitsandbytes 0.50.0,unsloth_zoofrom git main,pip install -e . --no-deps):11 passed, 12 errorsfortests/studio/install/test_rocm_rdna_routing.py, matching CI exactly (the 11 passes are the pure-mappingtest_rocm_gfx_familycases, which never needed a child).23 passed.DEVICE hip True,TARGET ('rocm', 'gfx1030'), andBNB backend CPU / HIP_ENVIRONMENT False, with the real CPU native library loaded instead of the error mock, so nolibhipblasorrocminfoprobe is attempted at all.tests/studio/install/:1411 passed, 2 skipped(the 3test_managed_node_runtime.pyfailures on my box are a pre-existing local-environment artifact, they fail identically on a clean checkout ofmain).pytest tests/with the workflow's ignores, markers and deselects):2848 passed, 70 skipped, 23 deselected, zero errors. The one failure,tests/studio/test_ui_font_scale_contract.py::test_no_raw_pixel_text_utilities, also fails on a clean checkout ofmainin this environment and is unrelated.test_hardware_dispatch_matrix.py,test_is_mlx_dispatch_gate.py,test_xpu_spoof_pipeline.py):57 passed, 1 skipped.