Skip to content

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.

Refuse K-EXAONE 2.0 on a transformers that ignores its config (#12128)

Daniel Han030913313bd2
diff --git a/tests/test_modeling_only_config_fields.py b/tests/test_modeling_only_config_fields.py
new file mode 100644
index 00000000000..70a733a55ff
--- /dev/null
+++ b/tests/test_modeling_only_config_fields.py
@@ -0,0 +1,102 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
+
+"""K-EXAONE 2.0 fields (`swiglu_limits`, per-layer `sliding_windows`) ignored by transformers without huggingface/transformers#47802."""
+
+import inspect
+
+import pytest
+
+transformers = pytest.importorskip("transformers")
+if getattr(transformers, "ExaoneMoeConfig", None) is None:
+ pytest.skip("this transformers has no exaone_moe", allow_module_level = True)
+
+from unsloth.models import loader # noqa: E402
+
+N = 8
+
+
+def _k2():
+ lt = ["full_attention" if i % 4 == 0 else "sliding_attention" for i in range(N)]
+ return transformers.ExaoneMoeConfig(
+ num_hidden_layers = N,
+ layer_types = lt,
+ sliding_windows = [
+ 0 if t == "full_attention" else (4096 if i == 1 else 128) for i, t in enumerate(lt)
+ ],
+ swiglu_limits = [0.0] * (N - 2) + [7.0, 7.0],
+ )
+
+
+def _k1():
+ lt = ["full_attention" if (i + 1) % 4 == 0 else "sliding_attention" for i in range(N)]
+ return transformers.ExaoneMoeConfig(
+ num_hidden_layers = N,
+ layer_types = lt,
+ sliding_window = 128,
+ sliding_windows = [0 if t == "full_attention" else 128 for t in lt],
+ )
+
+
+def _modeling_supports():
+ import transformers.models.exaone_moe.modeling_exaone_moe as m
+ src = inspect.getsource(m)
+ return "swiglu_limits" in src and "sliding_windows" in src
+
+
+def test_k_exaone_2_refused_when_transformers_ignores_its_fields(monkeypatch):
+ if _modeling_supports():
+ pytest.skip("this transformers implements K-EXAONE 2.0")
+ monkeypatch.delenv("UNSLOTH_ALLOW_IGNORED_CONFIG", raising = False)
+ config = _k2()
+ assert config.sliding_window == 4096
+ with pytest.raises(RuntimeError, match = "swiglu_limits, sliding_windows"):
+ loader._raise_if_modeling_ignores_config(config, ["exaone_moe"])
+
+
+def test_override_only_warns(monkeypatch):
+ monkeypatch.setenv("UNSLOTH_ALLOW_IGNORED_CONFIG", "1")
+ loader._raise_if_modeling_ignores_config(_k2(), ["exaone_moe"])
+
+
+def test_k_exaone_1_still_loads(monkeypatch):
+ monkeypatch.delenv("UNSLOTH_ALLOW_IGNORED_CONFIG", raising = False)
+ loader._raise_if_modeling_ignores_config(_k1(), ["exaone_moe"])
+
+
+def test_supported_transformers_is_not_refused(monkeypatch):
+ monkeypatch.delenv("UNSLOTH_ALLOW_IGNORED_CONFIG", raising = False)
+ real = inspect.getsource
+ monkeypatch.setattr(
+ inspect, "getsource", lambda obj: real(obj) + "\n# swiglu_limits sliding_windows\n"
+ )
+ loader._raise_if_modeling_ignores_config(_k2(), ["exaone_moe"])
+
+
+def test_other_model_types_untouched():
+ loader._raise_if_modeling_ignores_config(_k2(), ["llama"])
+ loader._raise_if_modeling_ignores_config(None, ["exaone_moe"])
+
+
+def test_adapter_base_config_is_checked():
+ import ast
+
+ tree = ast.parse(inspect.getsource(loader))
+ checked = set()
+ for cls in (n for n in tree.body if isinstance(n, ast.ClassDef)):
+ for fn in (
+ n for n in cls.body if isinstance(n, ast.FunctionDef) and n.name == "from_pretrained"
+ ):
+ for node in ast.walk(fn):
+ if (
+ isinstance(node, ast.If)
+ and isinstance(node.test, ast.Name)
+ and node.test.id == "is_peft"
+ ):
+ if any(
+ isinstance(c, ast.Call)
+ and getattr(c.func, "id", None) == "_raise_if_modeling_ignores_config"
+ for c in ast.walk(node)
+ ):
+ checked.add(cls.name)
+ assert {"FastLanguageModel", "FastModel"} <= checked
diff --git a/tests/test_optimized_precision_conflicts.py b/tests/test_optimized_precision_conflicts.py
index 629fb93ad4e..ac7759863d5 100644
--- a/tests/test_optimized_precision_conflicts.py
+++ b/tests/test_optimized_precision_conflicts.py
@@ -71,6 +71,7 @@ def loader():
patch_compiling_bitsandbytes = lambda: None,
_get_dtype = lambda dtype: dtype,
_revision_for_tokenizer_repo = lambda *args: None,
+ _raise_if_modeling_ignores_config = lambda *args: None,
)
exec(compile(ast.Module(body = [helper, method], type_ignores = []), str(path), "exec"), env)
return env, captured
diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py
index aae7b25eb5d..82b2ed62524 100644
--- a/unsloth/models/loader.py
+++ b/unsloth/models/loader.py
@@ -525,6 +525,62 @@ FLA_MODEL_TYPE_PREFIXES = ("qwen3_next", "qwen3_5", "kimi_linear", "olmo_hybrid"
_fla_advised = False
+def _exaone_moe_windows_need_support(config, windows):
+ layer_types = getattr(config, "layer_types", None) or []
+ single = getattr(config, "sliding_window", None)
+ for layer_type, window in zip(layer_types, windows or []):
+ if layer_type == "sliding_attention" and window and window != single:
+ return True
+ return False
+
+
+# Config fields only modeling code reads; transformers without them silently builds another network (huggingface/transformers#47802).
+_MODELING_ONLY_CONFIG_FIELDS = {
+ "exaone_moe": (
+ ("swiglu_limits", lambda config, v: any(float(x or 0) for x in (v or []))),
+ ("sliding_windows", _exaone_moe_windows_need_support),
+ ),
+}
+
+
+def _raise_if_modeling_ignores_config(config, model_types):
+ """Refuse a checkpoint whose config needs modeling features this transformers lacks."""
+ if config is None:
+ return
+ for model_type in model_types or []:
+ fields = _MODELING_ONLY_CONFIG_FIELDS.get(model_type)
+ if not fields:
+ continue
+ needed = [
+ name
+ for name, needs in fields
+ if getattr(config, name, None) is not None and needs(config, getattr(config, name))
+ ]
+ if not needed:
+ continue
+ try:
+ import importlib, inspect as _inspect
+ source = _inspect.getsource(
+ importlib.import_module(f"transformers.models.{model_type}.modeling_{model_type}")
+ )
+ except Exception:
+ continue
+ missing = [name for name in needed if name not in source]
+ if not missing:
+ continue
+ message = (
+ f"Unsloth: this {model_type} checkpoint sets {', '.join(missing)}, which the installed "
+ f"transformers {transformers_version} ignores, so it would load and train a different "
+ "network than the one released (for K-EXAONE 2.0: no SwiGLU clamp and a 4096 window on "
+ "every sliding layer instead of 128). Install a transformers that supports it "
+ "(huggingface/transformers#47802), or set UNSLOTH_ALLOW_IGNORED_CONFIG=1 to load anyway."
+ )
+ if os.environ.get("UNSLOTH_ALLOW_IGNORED_CONFIG", "0") == "1":
+ logger.warning(message)
+ return
+ raise RuntimeError(message)
+
+
def _maybe_advise_fla_install(model_types):
"""One-time note when a gated-deltanet model loads without the fast kernels. They ship with Unsloth, so this fires only when they could not be enabled on this platform (no CUDA, torch < 2.7 or triton < 3.3) or when Unsloth deliberately disabled them as known-broken on this GPU / Triton combination, i.e. exactly when transformers uses the slow pure PyTorch path."""
global _fla_advised
@@ -1013,6 +1069,7 @@ class FastLanguageModel(FastLlamaModel):
peft_config if peft_config is not None else model_config,
trust_remote_code = trust_remote_code,
)
+ _raise_if_modeling_ignores_config(model_config, model_types)
if len(model_types) == 1:
model_type = model_types[0]
else:
@@ -1078,6 +1135,7 @@ class FastLanguageModel(FastLlamaModel):
trust_remote_code = trust_remote_code,
local_files_only = local_files_only,
)
+ _raise_if_modeling_ignores_config(model_config, model_types)
if not was_disabled:
enable_progress_bars()
@@ -1830,6 +1888,7 @@ class FastModel(FastBaseModel):
)
model_types_all = ",".join(model_types) + ","
_maybe_advise_fla_install(model_types)
+ _raise_if_modeling_ignores_config(model_config, model_types)
# Text-diffusion models (DiffusionGemma) take a transformers-only slow path: a custom block-diffusion generate over a novel backbone, so Unsloth's autoregressive kernel/compile patching is skipped and the unmodified HF model is loaded, keeping 4bit/8bit and PEFT LoRA.
if is_diffusion_model_type(model_types):
@@ -2032,6 +2091,7 @@ class FastModel(FastBaseModel):
trust_remote_code = trust_remote_code,
local_files_only = local_files_only,
)
+ _raise_if_modeling_ignores_config(model_config, model_types)
if not was_disabled:
enable_progress_bars()