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
Let the composite renaming tests run inside the transformers 5.4 window (#11572)
Daniel Han30868af4559a
diff --git a/tests/test_composite_prefix_renaming.py b/tests/test_composite_prefix_renaming.pyindex 5fa7973bf9d..1b8b4eaf822 100644--- a/tests/test_composite_prefix_renaming.py+++ b/tests/test_composite_prefix_renaming.py@@ -22,6 +22,7 @@ on its version number: on a build that leaks they prove the fix removes the leakbuild that does not leak they prove the fix leaves it alone."""+import osimport sysimport pytest@@ -31,7 +32,9 @@ pytest.importorskip("transformers")from unsloth.import_fixes import ( # noqa: E402_COMPOSITE_PREFIX_RENAMING_FLAG,+ _composite_prefix_renaming_repaired,_leaked_submodule_prefix_renamings,+ _next_in_wrapper_chain,_prefixed_pattern,_renaming_destroys_keys,_renaming_signature,@@ -42,12 +45,27 @@ from unsloth.import_fixes import ( # noqa: E402)+def _skip_a_stand_in(module):+ """transformers 4.x has neither module, and importing unsloth fills the gap with inert+ stand-ins so peft can import (`_make_peft_stub_module` in unsloth/import_fixes.py). Their+ WeightRenaming stores its patterns and renames nothing, and their mapping function returns+ nothing, so a test run against them measures the stand-in rather than transformers. A real+ module is a file on disk; a stand-in's `__file__` is `<unsloth stub: ...>`."""+ path = getattr(module, "__file__", None)+ if not os.path.isfile(path or ""):+ pytest.skip(+ f"{module.__name__} is a stand-in ({path!r}), not a module this transformers ships"+ )++def _weight_renaming():"""transformers 4.x has no `core_model_loading`, and so no pathology to test."""try:+ from transformers import core_model_loadingfrom transformers.core_model_loading import WeightRenamingexcept Exception:pytest.skip("this transformers has no core_model_loading.WeightRenaming")+ _skip_a_stand_in(core_model_loading)return WeightRenaming@@ -56,6 +74,7 @@ def _conversion_mapping():from transformers import conversion_mappingexcept Exception:pytest.skip("this transformers has no conversion_mapping module")+ _skip_a_stand_in(conversion_mapping)if not hasattr(conversion_mapping, "get_model_conversion_mapping"):pytest.skip("this transformers has no get_model_conversion_mapping")return conversion_mapping@@ -360,6 +379,26 @@ def forced_install(monkeypatch):if isinstance(getattr(module, "__dict__", None), dict)and "get_model_conversion_mapping" in module.__dict__]+ # Start from upstream's own function, not from whatever importing unsloth left live. Inside+ # the 5.4.0 to 5.5.4 window the import has already installed this repair and unsloth_zoo's+ # MoE wrapper has gone on top of it, so an install measured from `live` finds the repair in+ # the chain and declines, and the wrapper on top publishes no `__wrapped__`. Every test+ # here was written against a bare upstream function; this states that instead of+ # inheriting it from whichever release the lane happens to pin.+ chain = []+ function = live+ while function is not None and len(chain) < 8:+ chain.append(function)+ function = _next_in_wrapper_chain(function)+ upstream = chain[-1]+ assert not getattr(upstream, _COMPOSITE_PREFIX_RENAMING_FLAG, False)+ # Through monkeypatch, not by assignment: a test that also monkeypatches the function saves+ # `upstream` as the value to restore, and its undo runs after this fixture's `finally`.+ # Registered here, this swap's own undo runs last and leaves `live` in place.+ monkeypatch.setattr(conversion_mapping, "get_model_conversion_mapping", upstream)+ for module, binding in holders:+ if any(binding is link for link in chain):+ monkeypatch.setattr(module, "get_model_conversion_mapping", upstream)monkeypatch.setattr(import_fixes, "_transformers_rescopes_submodule_prefix_renamings", lambda: False)@@ -372,12 +411,14 @@ def forced_install(monkeypatch):def test_installation_is_gated_on_the_probe():- conversion_mapping = _conversion_mapping()+ _conversion_mapping()fix_transformers_composite_prefix_renaming()- installed = getattr(- conversion_mapping.get_model_conversion_mapping, _COMPOSITE_PREFIX_RENAMING_FLAG, False+ # The whole chain, by either link and either package's mark: inside the defect window+ # unsloth_zoo's MoE wrapper sits on top of the repair, so the top object alone reads a+ # live repair as missing.+ assert _composite_prefix_renaming_repaired() == (+ not _transformers_rescopes_submodule_prefix_renamings())- assert installed == (not _transformers_rescopes_submodule_prefix_renamings())def test_the_patch_is_idempotent_and_undoable(forced_install):diff --git a/tests/test_import_fixes_drift.py b/tests/test_import_fixes_drift.pyindex bed27a62494..e324c99e417 100644--- a/tests/test_import_fixes_drift.py+++ b/tests/test_import_fixes_drift.py@@ -1724,18 +1724,35 @@ def test_transformers_scopes_a_submodules_conversion_mapping():merge a submodule's own prefix renaming into the parent's conversion mappingverbatim, which renames a composite model's real weight names into names it doesnot have and throws away the bitsandbytes quant_state sidecars with them."""- pytest.importorskip("transformers")- from unsloth.import_fixes import _transformers_rescopes_submodule_prefix_renamings+ transformers = pytest.importorskip("transformers")+ from packaging.version import Version- if not _transformers_rescopes_submodule_prefix_renamings():+ from unsloth.import_fixes import (+ _composite_prefix_renaming_repaired,+ _transformers_rescopes_submodule_prefix_renamings,+ )++ if _transformers_rescopes_submodule_prefix_renamings():+ return+ # Unscoped. Inside 5.4.0 to 5.5.4 that is the defect the repair exists for, and a lane that+ # pins `transformers<5.5` lands there on purpose, so the drift is not the defect but a+ # defect nobody repaired. On a release that ships upstream's fix, it is the probe that drifted.+ if Version(transformers.__version__) >= Version("5.6.0"):pytest.fail(- "DRIFT DETECTED: this transformers recurses into submodules for "- "conversion mappings without scoping them to where the submodule lives "- "(no model_prefix argument, no PrefixChange.with_submodel_prefix, no "- "scope_prefix field) -- fix_transformers_composite_prefix_renaming would "- "wrap get_model_conversion_mapping. Pre-quantized multimodal checkpoints "- "load with quant_state=None here; install transformers>=5.6.0."+ f"DRIFT DETECTED: transformers=={transformers.__version__} ships the submodule "+ "re-scoping of PR #45567, but the probe finds none of its three spellings (no "+ "model_prefix argument, no PrefixChange.with_submodel_prefix, no scope_prefix "+ "field). fix_transformers_composite_prefix_renaming would wrap "+ "get_model_conversion_mapping on a build that does not need it; teach the probe "+ "the new spelling.")+ assert _composite_prefix_renaming_repaired(), (+ f"DRIFT DETECTED: transformers=={transformers.__version__} recurses into submodules "+ "for conversion mappings without scoping them, and no repair is live -- neither "+ "fix_transformers_composite_prefix_renaming nor unsloth_zoo's copy wrapped "+ "get_model_conversion_mapping. Pre-quantized multimodal checkpoints load with "+ "quant_state=None here."+ )def test_composite_renaming_probe_agrees_with_the_real_mapping():