Skip to content

[BUG] Model defs: Instella/K2-Horizon AWQ trees fold across residual (PPL 14616/1100), TeleChat2 q/kv never quantized, AWQ stale position kwargs (EXAONE/DeciLM/Nanbeige), PanGu top-query + looped decoders mis-calibrated, MiniCPM/MobileLLM/ChatGLM load+generate failures #4093

Closed

Description

@Qubitium

Model-definition sweep of remote-code families that earlier sweeps didn't cover, on main @ a15e6bf with transformers 5.22.1 and an RTX 4090. Each finding is confirmed on the real checkpoint where one is noted, otherwise on a tiny random-weight model built from the checkpoint's own config.json and remote code. Real-checkpoint PPL is wikitext-2 40×512 with 64 C4 calibration docs.

1. Instella: tree uses Llama norm names that don't exist, so AWQ folds the MLP scale into o_proj across the residual (high, PPL 14616)

definitions/instella.py:9: InstellaQModel(LlamaQModel) inherits input_layernorm / post_attention_layernorm. The real layer has pre_attention_layernorm / pre_feedforward_layernorm (modeling_instella.py:663-664). The result:

  • q/k/v get no scale group.
  • mlp.gate/up get prev_op=self_attn.o_proj. That fold crosses the residual add, and the fold test shows a 0.31 relative logit change.
Instella-3B-Instruct:  RTN 27.71 | GPTQ 26.04 | AWQ 14616 | AWQ with the real norm names (+ fix 4) 27.77

Fix: give Instella its own tree with the real norm names, and add it to FAMILY_MODEL_TYPES in tests/test_awq_scaling_groups.py.

2. K2-Horizon: each attention projection is its own tree node, so AWQ builds chained single-module groups (high, PPL 1100)

definitions/k2_horizon.py:140-157 declares "q_proj": ("q_proj:0",), "k_proj": ... and so on as separate dicts. AWQ then builds:

  • input_layernorm → [q_proj] alone (0.27–0.36 fold error);
  • q_proj → k_proj (0.02);
  • gate_proj → o_proj when the attention gate is on (0.20).
K2-Horizon-0.9B:  RTN 21.03 | AWQ 1100.2 | AWQ with flat ("q_proj:0","k_proj:0","v_proj:0","gate_proj:0:nosrc","o_proj:1") 19.87     (GPTQ unaffected)

Fix: use a flat self_attn tuple, and keep the v_experts node only for MoVA layers.

3. TeleChat2: query / key_value are never quantized, and AWQ crashes (high for the family)

definitions/telechat2.py:25 has only "self_attention": {"dense": ("dense",)}. The attention's query and key_value Linears (modeling_telechat.py:358-359) stay fp16. Only an INFO log mentions it, and coverage reports "all 4 specs matched".

tiny TeleChat2: remaining_linear = [h.*.self_attention.query, h.*.self_attention.key_value]
AWQ fold test: bogus input_layernorm -> dense group (0.32-0.34)
AWQ: TypeError: TelechatAttention.forward() missing 'residual' and 'attention_mask' (awq_processor.py:3043)

Fix: use ("query:0","key_value:0","dense:1"). For AWQ, supply residual / attention_mask to the module replay, or skip attention-module replay for this family. tests/models/test_telechat2.py only checks ARC accuracy.

4. AWQ scale search reuses stale position_ids / position_embeddings from another sample and crashes: EXAONE-3, DeciLM, Nanbeige (high for AWQ on these families)

looper/awq_processor.py:2905-2945 (_prepare_module_forward) and :324-330 (_get_root_rotary) rebuild position kwargs only when they find a root rotary at model.model.rotary_emb or through rotary_embedding. Otherwise the elif adds position_ids only when the key is absent. So the captured kwargs from a different-length sample get passed along with x.

EXAONE-3.0-7.8B-Instruct AWQ: RuntimeError: The size of tensor a (522) must match the size of tensor b (430) (modeling_exaone apply_rotary_pos_emb)
tiny DeciLM-7B / Nanbeige AWQ: same, 48 vs 20

This isn't a regression: the pre-#4071 tree crashes too.

Fix:

  • When position_ids.shape[-1] != seq_len, rebuild it with arange, and slice or drop mismatched position_embeddings, or use the attention module's own rotary.
  • Set rotary_embedding="transformer.rotary" in exaone.py.

With this fix, AWQ runs on all three.

5. PanGu-α: the last ("top-query") layer is calibrated on the wrong input (medium, silent)

HF applies ln_f before the last block and passes it custom_query = wqe(position_ids), so its q_proj reads query embeddings. definitions/pangu_alpha.py has no replay hook: GPTQModel replays layer 0's kwargs (custom_query=None) and chains the raw output.

layer-replay vs HF forward: last layer arg0 rel diff 0.953 (control model: 0.0056), custom_query: hf=tensor, replay=None
tiny model: GPTQ error 0.114 vs RTN 0.097 (worse than RTN)

Fix: override prepare_layer_replay_kwargs for the last layer to apply ln_f and pass custom_query.

6. Looped decoders are calibrated on loop 0 only: Ouro and Nanbeige 4.2 (medium, silent; same class as #4040 item I, which #4055 fixed only for HRM-Text)

  • Ouro (total_ut_steps=4): the inputs of steps 1–3 have cosine −0.03 to 0.42 against the only captured input.
  • Nanbeige 4.2 (num_loops=2): loop 2 has cosine 0.54 / 0.68.

Fix: reuse the HRM-style full-forward capture, which accumulates Hessians over every invocation.

7. Spark-X2.5: GPTQ crashes under the default auto_dtype_cast=auto_nf12 (high for the family)

The remote layer forward reads self.mlp.gate_proj.weight.dtype (modeling_spark.py:244), but AutoNF12HookedLinear (utils/auto_dtype_cast.py:270) has no .weight:

Spark-X2.5-4B GPTQ default: AttributeError: 'AutoNF12HookedLinear' object has no attribute 'weight' (forward_executor.py:431)
auto_dtype_cast="off": OK (tiny: err 0.071 vs RTN 0.0996)

Fix: expose a weight stand-in, e.g. a meta tensor with the source dtype, shape and device, on the hooked linear.

8. .bin-only checkpoints whose remote class has a list _tied_weights_keys can't be quantized: MiniCPM-2B-128k, which tests/models/test_minicpm.py uses (high for that model)

LazyTurtle's .bin → safetensors conversion (utils/structure.py:1198) calls save_pretrained without _normalize_legacy_tied_weights_keys, so it fails with AttributeError: 'list' object has no attribute 'keys'. That error is swallowed at structure.py:1082, and the user sees a misleading loader.py:1861 "can't open model path ... for offload_to_disk".

Fix: normalize the tied keys before that save, as writer.py:2176 already does. Verified: the model then loads.

9. MiniCPM-2B (rope_scaling: null) and MobileLLM fail at load with KeyError: 'type' (medium-high)

utils/hf.py:1689-1696 sets rope_scaling=None. In transformers 5.22, rope_scaling is an alias of rope_parameters (configuration_utils.py:718), so the later _normalize_rope_parameters_config_compat (hf.py:1775) refills it with a default dict. The remote _init_rope then indexes ["type"]. Only Nanbeige is special-cased (hf.py:1512).

Fix: generalize the Nanbeige branch (null both fields for unscaled RoPE), or run it after the normalization.

10. Native (unquantized) remote-code models loaded through GPTQModel get garbage RoPE (medium)

The native eval branch models/loader.py:1714 (HF from_pretrained) never runs the non-persistent buffer restore that the quantize path does (LazyTurtle._restore_missing_nonpersistent_buffers, structure.py:3624). inv_freq is computed in __init__ and is left near zero. Wikitext PPL:

as loaded with inv_freq restored
Instella-3B 692 19.3
EXAONE-3.0-7.8B 243 9.0
DeciLM-7B 574 5.48

Quantize and quantized reload are correct. Anyone evaluating native baselines through GPTQModel is affected, including tests/models/model_test.py's "Baseline fallback", which can then accept degraded results. Fix: apply the same restore after native loads.

11. ChatGLM / GLM-4 (remote): generate() crashes on both native and quantized models (medium)

hf.py:1446-1447 maps attribute_map["max_length"]="seq_length". transformers 5's _prepare_generation_config then raises You have modified the pretrained model configuration ... {'max_length': 8192} (seen with chatglm3-6b native, and with a tiny quantized model through both gm.generate and model.generate). Without the shim, model init fails. Fix: expose max_length to the remote code only, e.g. a property on the remote config class, or move it into generation_config instead of attribute_map.

12. Klear fails to import (low)

hf.py:982 shims check_model_inputs but not OutputRecorder, and modeling_klear.py imports both, which raises ImportError.

Checked, no defect found

  • Tree coverage and AWQ fold test: Baichuan2, EXAONE-3, DeciLM, Nanbeige, MiMo and Dream (bidirectional mask OK).
  • Real-weight AWQ groups: HunyuanOCR and DeepSeek-OCR-2 fold exactly (~1e-6).
  • Layer replay matches HF: Baichuan2, EXAONE-3, Instella, K2-Horizon and Dream.

Plausible, not verified

  • Natively loaded EXAONE-3 and DeciLM fail in model.generate (remote cache_position=None; DynamicCache not subscriptable). Quantized gm.generate works.
  • Phi-4-MM's tree puts every base_layer in subset 0, mixing consumers with their producers. Not run: backoff isn't installed.

🤖 Generated with Claude Code

Activity

  1. added
    bug
    on Nov 15, 2026
  2. Qubitium commented on Nov 15, 2026

    @Qubitium
    CollaboratorAuthor

    All 12 items are now on main, landed in two parts:

    Headline result on the native-RoPE item (PPL, 40×512 wikitext-2, bf16), measured against the issue's numbers:

    Model Issue Fixed
    Instella 692 23.06
    EXAONE 243 10.19
    DeciLM 574 7.54

    Each item carries a regression test that fails on the parent commit and passes on the fix, verified on both an RTX 4090 and an R9700 gfx1201.

    Closing as resolved. Two follow-ups are recorded rather than silently dropped:

    • ChatGLM generate was verified without KV cache; long-context cache reuse is untested.
    • Native rotary buffers are restored from the constructor template, which covers classes that build rotary in __init__; classes building it lazily elsewhere keep the previous behavior (documented in docs/transformers-5-compat.md).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions