Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Make tests/utils runnable again and cover test_packing.py in CI (#7642)
Daniel Han5017a6145c5e
diff --git a/.github/workflows/consolidated-tests-ci.yml b/.github/workflows/consolidated-tests-ci.ymlindex afad1b6c46d..40e39f51a3b 100644--- a/.github/workflows/consolidated-tests-ci.yml+++ b/.github/workflows/consolidated-tests-ci.yml@@ -276,6 +276,7 @@ jobs:tests/saving/test_gguf_single_pass_export.py \tests/saving/test_offline_gguf_vlm_tokenizer_7481.py \tests/utils/test_attention_masks.py \+ tests/utils/test_packing.py \tests/utils/test_trunc_normal_patch.py \tests/python/test_fast_language_model_text_only.pypython -m pytest --collect-only -q "$RUNNER_TEMP/unsloth-zoo/tests/"@@ -368,6 +369,7 @@ jobs:tests/saving/test_gguf_single_pass_export.py \tests/saving/test_offline_gguf_vlm_tokenizer_7481.py \tests/utils/test_attention_masks.py \+ tests/utils/test_packing.py \tests/utils/test_trunc_normal_patch.py \tests/python/test_fast_language_model_text_only.py \tests/test_bad_mappings_redirect.py \diff --git a/tests/utils/test_packing.py b/tests/utils/test_packing.pyindex 3ee4ba5c555..90b06d134d7 100644--- a/tests/utils/test_packing.py+++ b/tests/utils/test_packing.py@@ -38,6 +38,12 @@ from trl import SFTConfig, SFTTrainerfrom trl.trainer.sft_trainer import DataCollatorForLanguageModeling+class _FakeConfig(SimpleNamespace):+ # get_transformers_model_type() resolves through to_dict(), which SimpleNamespace lacks.+ def to_dict(self):+ return dict(self.__dict__)++def _build_packed_training_setup(tmp_path, device):dtype = Noneif device.type == "cuda":@@ -171,15 +177,13 @@ def test_configure_padding_free():def _hybrid_config_model():# Qwen3.5 / Qwen3-Next style: explicit linear_attention layer schedule.- return SimpleNamespace(- config = SimpleNamespace(layer_types = ["linear_attention", "full_attention"])- )+ return SimpleNamespace(config = _FakeConfig(layer_types = ["linear_attention", "full_attention"]))def _gemma3_model():# Has layer_types but no linear_attention -> must NOT be flagged as hybrid.return SimpleNamespace(- config = SimpleNamespace(+ config = _FakeConfig(model_type = "gemma3", layer_types = ["sliding_attention", "full_attention"]),)@@ -187,7 +191,7 @@ def _gemma3_model():def _dense_qwen3_model():return SimpleNamespace(- config = SimpleNamespace(model_type = "qwen3", architectures = ["Qwen3ForCausalLM"])+ config = _FakeConfig(model_type = "qwen3", architectures = ["Qwen3ForCausalLM"]))@@ -500,7 +504,7 @@ def _patch_fake_sft_trainer():def _vlm_model():return SimpleNamespace(- config = SimpleNamespace(+ config = _FakeConfig(architectures = ["Gemma4ForConditionalGeneration"],model_type = "gemma4",vision_config = SimpleNamespace(),@@ -511,7 +515,7 @@ def _vlm_model():def _text_model():return SimpleNamespace(- config = SimpleNamespace(+ config = _FakeConfig(architectures = ["LlamaForCausalLM"],model_type = "llama",),@@ -579,7 +583,7 @@ def test_encoder_decoder_disables_packing(model_type, architecture):fake_trainer = _patch_fake_sft_trainer()config = SimpleNamespace(packing = True, padding_free = None, remove_unused_columns = True)model = SimpleNamespace(- config = SimpleNamespace(+ config = _FakeConfig(model_type = model_type,architectures = [architecture],is_encoder_decoder = True,@@ -598,7 +602,7 @@ def test_decoder_only_conditional_generation_keeps_packing():fake_trainer = _patch_fake_sft_trainer()config = SimpleNamespace(packing = True, padding_free = None, remove_unused_columns = True)model = SimpleNamespace(- config = SimpleNamespace(+ config = _FakeConfig(model_type = "csm",architectures = ["CsmForConditionalGeneration"],is_encoder_decoder = False,@@ -615,7 +619,7 @@ def test_decoder_only_conditional_generation_keeps_packing():def _hybrid_trainer_model():return SimpleNamespace(- config = SimpleNamespace(+ config = _FakeConfig(model_type = "qwen3_next",architectures = ["Qwen3NextForCausalLM"],layer_types = ["linear_attention", "full_attention"],@@ -652,7 +656,7 @@ def test_string_hybrid_model_disables_packing(monkeypatch):monkeypatch.setattr(trainer_module,"_resolve_string_model_config",- lambda name, cfg: SimpleNamespace(+ lambda name, cfg: _FakeConfig(model_type = "qwen3_next",architectures = ["Qwen3NextForCausalLM"],layer_types = ["linear_attention", "full_attention"],@@ -976,6 +980,9 @@ def test_enable_sample_packing():assert torch.equal(batch["position_ids"].view(-1)[:6], expected_positions)+ not torch.cuda.is_available(), reason = "builds a real 4bit model on an accelerator"+)def test_enable_sample_packing_trl_collator(tmp_path):if torch.cuda.is_available():device = torch.device("cuda")@@ -1037,6 +1044,9 @@ def test_enable_padding_free_metadata():assert trainer.args.remove_unused_columns is False+ not torch.cuda.is_available(), reason = "builds a real 4bit model on an accelerator"+)def test_packing_sdpa(tmp_path):if torch.cuda.is_available():device = torch.device("cuda")@@ -1251,15 +1261,9 @@ def test_resolve_string_model_config_merges_top_level_trust_remote_code(monkeypaassert captured.get("trust_remote_code") is False-class _WarnConfig(SimpleNamespace):- # get_transformers_model_type() resolves through to_dict(), which SimpleNamespace lacks.- def to_dict(self):- return dict(self.__dict__)--def _warn_text_model():return SimpleNamespace(- config = _WarnConfig(architectures = ["LlamaForCausalLM"], model_type = "llama"),+ config = _FakeConfig(architectures = ["LlamaForCausalLM"], model_type = "llama"),max_seq_length = 16,)diff --git a/tests/utils/test_qat.py b/tests/utils/test_qat.pyindex 0b942d5c323..ffac9a0a597 100644--- a/tests/utils/test_qat.py+++ b/tests/utils/test_qat.py@@ -5,18 +5,20 @@ from typing import Dictimport pytestimport torch-try:- from torchao.quantization.qat import FakeQuantizedLinear- from torchao.quantization.qat.fake_quantizer import (- FakeQuantizerBase,- Float8FakeQuantizer,- Int4WeightFakeQuantizer,- IntxFakeQuantizer,- )-except ImportError:- print(- "Missing torchao import, please install or upgrade torchao with: pip install 'torchao>=0.15.0'"- )+# torchao is an optional extra. Skip the module instead of printing and then failing+# every test on NameError once the import did not land.+pytest.importorskip(+ "torchao.quantization.qat",+ reason = "install or upgrade with: pip install 'torchao>=0.15.0'",+)++from torchao.quantization.qat import FakeQuantizedLinear+from torchao.quantization.qat.fake_quantizer import (+ FakeQuantizerBase,+ Float8FakeQuantizer,+ Int4WeightFakeQuantizer,+ IntxFakeQuantizer,+)class _CountingFakeQuantizer(torch.nn.Module):