unsloth/unsloth/models
Daniel Han 77e0929735
revert: stop touching DEVICE_TYPE == "cuda" branches for CPU CI (#5473)
#5429 (cb15a7a5) tightened three production-path branches to
DEVICE_TYPE == "cuda" and torch.cuda.is_available() and added a
new else: SUPPORTS_BFLOAT16 = False arm to let `import unsloth.trainer`
survive on a CPU-only CI host. We already ship the package on Intel
XPU / AMD HIP / NVIDIA CUDA and don't want any extra branching in
those hot paths.

Move the entire CPU-CI handling to one place -- the top of
unsloth/device_type.get_device_type() -- so the UNSLOTH_ALLOW_CPU=1
sentinel short-circuits detection and returns "cuda" before any
torch probe runs. Every downstream DEVICE_TYPE == "cuda" branch
then behaves identically to a real CUDA host, with no additional
checks. The two existing duplicate UNSLOTH_ALLOW_CPU returns
later in the function are dropped (the new top-of-function check
covers both).

Revert the three call-site changes:
- unsloth/_gpu_init.py:212  -> back to `if DEVICE_TYPE == "cuda":`
- unsloth/_gpu_init.py:247  -> back to `if DEVICE_TYPE == "cuda":`
- unsloth/models/_utils.py:1207 -> back to `if DEVICE_TYPE == "cuda":`
- unsloth/_gpu_init.py: drop the new `else: SUPPORTS_BFLOAT16 = False`
  branch (dead under the top-of-function short-circuit).

Keep the two env-var gates that are needed for zoo's drift detectors
to inspect pristine TRL source (no behavioural change on production
hosts that never set UNSLOTH_ALLOW_CPU):
- unsloth/_gpu_init.py: `if env != "1": _patch_trl_trainer()`
- unsloth/models/rl.py:PatchFastRL: `if env == "1": return`

Verified:
- CUDA_VISIBLE_DEVICES=5 python -c "import unsloth.trainer" produces
  UnslothSFTTrainer.__init__ (TRL still patched on real hosts).
- UNSLOTH_ALLOW_CPU=1 + aggressive cuda spoof import succeeds and
  trl.SFTTrainer.__init__.__qualname__ stays SFTTrainer.__init__.
- pytest tests/_zoo_compiler_cache_shim.py -> 5 passed, 1 skipped.
2026-05-15 19:41:09 -07:00
..
__init__.py Revert "feat: Add Mixtral model support" 2026-03-13 22:38:49 -07:00
_utils.py revert: stop touching DEVICE_TYPE == "cuda" branches for CPU CI (#5473) 2026-05-15 19:41:09 -07:00
cohere.py Fix forward compatibility with transformers 5.x (#4752) 2026-04-01 06:04:03 -07:00
dpo.py Formatting & bug fixes (#3563) 2025-11-07 06:00:22 -08:00
falcon_h1.py Fix forward compatibility with transformers 5.x (#4752) 2026-04-01 06:04:03 -07:00
gemma.py Fix/pr 3699 leftpad prefill main (#4100) 2026-02-25 07:21:04 -08:00
gemma2.py Fix forward compatibility with transformers 5.x (#4752) 2026-04-01 06:04:03 -07:00
glm4_moe.py [MoE] Improve moe kernels for unsloth fine tuning (#3812) 2026-02-05 06:03:25 -08:00
granite.py Fix forward compatibility with transformers 5.x (#4752) 2026-04-01 06:04:03 -07:00
llama.py fix: multi-GPU inference crash for bnb 4-bit/8-bit models (#5068) 2026-04-16 11:35:02 -07:00
llama4.py Qwen 3 2025-05-02 03:09:44 -07:00
loader.py Restrict flash attn to <=256 head dim. Consolidate attn impl checks (#5051) 2026-04-16 09:00:17 -05:00
loader_utils.py studio: reuse HF cached repo casing to prevent duplicate downloads (#4822) 2026-04-03 05:48:24 -07:00
mapper.py Re-apply #4939: updated models template mappers (#4950) 2026-04-15 07:52:12 -07:00
mistral.py Fix Mistral DPO/preference training crash on non-xformers platforms (e.g. Intel XPU) (#4889) 2026-04-09 04:38:44 -07:00
qwen2.py Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks" 2025-12-01 07:24:58 -08:00
qwen3.py Fix forward compatibility with transformers 5.x (#4752) 2026-04-01 06:04:03 -07:00
qwen3_moe.py Fix correctness bugs across multiple model files (#3813) 2026-01-01 02:36:33 -08:00
rl.py add UNSLOTH_ALLOW_CPU=1 path for CPU-only CI (#5429) 2026-05-14 20:27:14 -07:00
rl_replacements.py security: NOT affected by Mini Shai-Hulud (May-12 wave) -- forward-looking hardening only (#5397) 2026-05-13 04:58:12 -07:00
sentence_transformer.py Fix: Add missing utf-8 encoding to text-mode file operations (#5356) 2026-05-14 18:15:27 +04:00
vision.py fix: multi-GPU inference crash for bnb 4-bit/8-bit models (#5068) 2026-04-16 11:35:02 -07:00