unsloth/unsloth
Daniel Han 7b068090b2
Fix bitsandbytes zombie module breaking test collection on CPU runners (#7580)
* Fix bitsandbytes zombie module breaking test collection

A partially failed `import bitsandbytes` leaves the package half-imported:
CPython evicts only the parent from sys.modules and keeps every submodule it
had already loaded. The next import re-executes __init__ but every
`from .x import y` is served from cache, so the submodule attributes are never
rebound. The package imports "successfully" while `bnb.functional` is gone.

Bind the submodule via `import bitsandbytes.functional as bnb_functional`,
which reads sys.modules directly and survives that state, and import
bitsandbytes in tests/conftest.py on the real CPU path before
torch.cuda.is_available() is mocked, so the half-imported state is never
created in the first place.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-07-28 21:18:05 -07:00
..
dataprep Parse a .json dataset file as one JSON document instead of line-by-line (#7422) 2026-07-28 21:40:43 -03:00
kernels Fix bitsandbytes zombie module breaking test collection on CPU runners (#7580) 2026-07-28 21:18:05 -07:00
models Keep import unsloth working when bitsandbytes is absent (#7502) 2026-07-28 08:03:54 -07:00
optimizers Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
registry fix(registry): don't register deepseek models at import time (#7227) 2026-07-19 03:37:23 -07:00
utils fix: enable XPU support and update hardcoded CUDA selections for tests (#7401) 2026-07-28 15:38:57 -07:00
__init__.py fix(mlx): relax context-store timeout by default (#7141) 2026-07-17 17:13:19 -03:00
_auto_install.py Upgrade setuptools and wheel in the auto-install command (#6282) 2026-06-13 03:59:15 -07:00
_compressed_quantize.py Fix export-time trust_remote_code bypass in FP8/INT8/GGUF-LoRA export (#6869) 2026-07-05 05:16:39 -07:00
_gpu_init.py Fix bitsandbytes zombie module breaking test collection on CPU runners (#7580) 2026-07-28 21:18:05 -07:00
bnb_availability.py Clear ALLOW_BITSANDBYTES when the bitsandbytes native kernels are not real (#7578) 2026-07-28 21:17:33 -07:00
chat_templates.py fix(chat_templates): bind loop_messages when default_system_message is None (#7199) 2026-07-19 06:33:48 -07:00
device_type.py Clear ALLOW_BITSANDBYTES when the bitsandbytes native kernels are not real (#7578) 2026-07-28 21:17:33 -07:00
import_fixes.py AMD: enable ROCm torch on gfx906 (MI50 / Radeon VII) on Linux (#7354) 2026-07-27 05:22:19 -07:00
ollama_template_mappers.py Re-apply #4939: updated models template mappers (#4950) 2026-04-15 07:52:12 -07:00
save.py Keep import unsloth working when bitsandbytes is absent (#7502) 2026-07-28 08:03:54 -07:00
tokenizer_utils.py Replace standalone Studio wording with Unsloth (#7221) 2026-07-19 00:47:04 -07:00
trainer.py Experimental: correct varlen sample packing for hybrid linear-attention models (#7249) 2026-07-20 00:57:02 -07:00