unsloth/unsloth
Daniel Han 41f8792e7c Honor quantization_config.load_in_4bit for Gemma-4 MoE swap
The Gemma-4 MoE per-expert Linear4bit swap previously gated only on the
positional load_in_4bit argument. loader.py forwards load_in_4bit=False
to FastBaseModel.from_pretrained whenever the caller supplies a
quantization_config (BitsAndBytesConfig), so callers that opt in via
UNSLOTH_GEMMA4_MOE_4BIT=1 plus BitsAndBytesConfig(load_in_4bit=True)
silently bypassed the swap. The adjacent guardrail already normalises
load_in_4bit from quantization_config; the swap gate now does the same
and sources bnb_4bit_compute_dtype from quantization_config when no
local bnb_config is built.

The except branch around the swap also previously stated "Falling back
to BF16 experts", which misrepresents the model state when the helper
fails partway through (already-swapped Gemma4TextExperts modules stay
in 4-bit; only the remainder remain BF16). The warning now counts the
modules marked _unsloth_gemma4_moe_4bit_swapped and reports the partial
state, advising a reload to recover a uniform state.

The comment above the fused-Parameter dels in gemma4_moe_4bit.py
overstated the swap's memory bound; rephrased to describe the actual
per-module peak (fused BF16 plus accumulated per-expert nf4).
2026-05-16 15:46:16 +00:00
..
dataprep Fix raw text paragraph break normalization (#4884) 2026-04-09 04:45:43 -07:00
kernels Fix: Add missing utf-8 encoding to text-mode file operations (#5356) 2026-05-14 18:15:27 +04:00
models Honor quantization_config.load_in_4bit for Gemma-4 MoE swap 2026-05-16 15:46:16 +00:00
optimizers feat: Implement Q-GaLore optimizer and custom embedding learning rate… (#4511) 2026-03-25 01:03:10 -07:00
registry Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks" 2025-12-01 07:24:58 -08:00
utils Add check to disable xformers on newer GPUs (#4342) 2026-03-16 22:42:38 -07:00
__init__.py MLX training support for Studio on Apple Silicon (#5340) 2026-05-14 05:24:20 -07:00
_auto_install.py Add PyTorch 2.10 and xformers 0.0.34 support (#3985) 2026-02-05 05:56:26 -08:00
_gpu_init.py revert: stop touching DEVICE_TYPE == "cuda" branches for CPU CI (#5473) 2026-05-15 19:41:09 -07:00
chat_templates.py Fix/issue 3667 vicuna template (#5357) 2026-05-14 18:49:47 +04:00
device_type.py revert: stop touching DEVICE_TYPE == "cuda" branches for CPU CI (#5473) 2026-05-15 19:41:09 -07:00
import_fixes.py import_fixes + drift detectors: cover transformers 5.x drift (#5423) 2026-05-14 05:14:21 -07:00
ollama_template_mappers.py Re-apply #4939: updated models template mappers (#4950) 2026-04-15 07:52:12 -07:00
save.py Fix: Add missing utf-8 encoding to text-mode file operations (#5356) 2026-05-14 18:15:27 +04:00
tokenizer_utils.py fix: 3 patch_* helpers — fast_lora import, sft_trainer Union, openenv OSError (#5319) 2026-05-07 00:12:09 -07:00
trainer.py Trim trainer.py import-fix comment to one line 2026-05-06 07:22:56 +00:00