Repository navigation
fix(models): support Transformers 5.22 trees and calibration (#4040) - #4055
Merged
Merged
Conversation
…urrent calibration (#4040) Sections E-I and the "Also" list of issue #4040. Part of #4040; the issue closes when both halves land. - lfm2_moe: declare the 5.22 `out_proj` and defused per-expert gate/up/down projections; switch to GateUpDownMoELifecycleHooks and pin expert coverage. 13/51 -> 51/51 decoder linears quantized. - glm4_moe / glm4_moe_lite: add a source-gated Defuser shim that unwraps the 5.22 `(logits, weights, indices)` router tuple before routing. The upstream fix belongs in Defuser. - mllama_text_model: register MllamaTextConfig with AutoModelForCausalLM and resolve the text-only `model.model` layout. - kimi_linear: dispatch native KimiLinearForCausalLM to a native tree and run Defuser's generic experts pass; AttnRes/K3 configs keep the K3 runner. - hrm_text: capture every L/H stack invocation with full-model forward hooks and accumulate the Hessian over the true recurrent inputs. - glmasr: load the complete GlmAsrForConditionalGeneration wrapper and use the model.language_model tree and top-level lm_head. - llama4: resolve lm_head under language_model. - qwen2_5_omni: declare both pre-lm-head norm layouts as candidates. - mimo_v2_flash: register the native MiMo-V2-Flash tree with generic experts. - deepseek_v4: keep the packed lazy boundary only for EXL3/floatx; GPTQ/AWQ/RTN materialize target layers eagerly instead of failing on META projections. Adds docs/transformers-5-compat.md with the resolution and calibration flows.
# Conflicts: # docs/transformers-5-compat.md # tests/test_qwen2_5_omni_lm_head.py
This was referenced Nov 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #4040
This PR implements sections E-I and the Also list of issue #4040. Sections A-D landed separately in #4049. The issue should close when both halves are complete.
Root causes and fixes
gptqmodel/models/definitions/lfm2_moe.py:30declaredself_attn.o_proj, while 5.22 usesout_proj; line 36 declaredexperts.#.w1/w3/w2, while Defuser exposesgate_proj/up_proj/down_proj. 13 of 51 decoder linears were silently skipped.out_projand the defused expert names, and usesGateUpDownMoELifecycleHooks.tests/module_tree/test_moe_expert_coverage.pynow requires every LFM2-MoE quantizable spec to resolve.(logits, weights, indices)intoroute_tokens_to_experts, which calls.sigmoid().gptqmodel/utils/defuser_compat.py:74source-gates a shim that unwraps the tuple and delegates to Defuser's original routing method. Quantize and reload paths install it. The authoritative upstream fix still belongs in Defuser.mllama_text_modelMllamaTextConfigis not registered withAutoModelForCausalLMin 5.22, and the text-only decoder lives atmodel.model.mllama.py:27and resolves the text-only layout inmllama.py:92.kimi_linearquantize()requiresKimiK3Source; nativeKimiLinearForCausalLMhas no AttnRes and usesself_attnplusmlp.experts/shared_experts.auto.py:645dispatches on AttnRes/K3 config fields. Native configs useKimiLinearNativeQModeland Defuser's generic experts pass; K3 configs keep the bounded K3 runner.H_cycles * L_cyclestimes and HH_cyclestimes, with H inputz_H + final_norm(z_L).hrm_text.py:167captures every invocation with full-model forward hooks andpre_quantize()serves each layer its own invocation batches. Captures are released inafter_quantize().AutoModelbuiltGlmAsrModel, whose layers are atlanguage_model.layersand which has nolm_head.GlmAsrForConditionalGeneration, usesmodel.language_model.layers, top-levellm_head, and the matching rotary/norm paths.lm_headpath missedlanguage_model.lm_head.thinker.model.normno longer exists in 5.22.mimo_v2_flash, which had no definition.MimoV2FlashQModel, including generic Defuser expert expansion.Resolution flow
flowchart TD A["Installed Transformers config"] --> B["check_and_get_model_definition"] B --> C{"model_type is kimi_linear"} C -->|"AttnRes or K3 fields"| D["KimiLinearQModel"] C -->|"native config"| E["KimiLinearNativeQModel"] B --> F["mllama_text_model"] F --> G["MllamaForCausalLM"] G --> H["resolve model.model"] B --> I["mimo_v2_flash"] I --> J["MimoV2FlashQModel"] E --> K["generic Defuser experts pass"] J --> K K --> L["module tree resolves every quantizable leaf"] M["glm4_moe / glm4_moe_lite"] --> N["source-gated router tuple shim"] N --> O["original Defuser routing math"] P["HRM-Text"] --> Q["capture every recurrent invocation"] Q --> R["per-layer recurrent Hessians"]Before / after
Tiny random checkpoints, GPTQ 4-bit,
group_size=32,desc_act=False, save, reload withBACKEND.TORCH, logits against fp16 and an RTN baseline. Coverage excludeslm_head, which remains dense under the default configuration.requires KimiK3SourceROCm reproduced the same behavior: LFM2-MoE 0.0837 vs 0.1213, GLM-4 0.0158 vs 0.0603, Mllama 0.0242 vs 0.0555, Kimi-Linear 0.0209 vs 0.0541, HRM 0.0008 vs 0.0016, GLM-ASR 0.0163 vs 0.0507, MiMo 0.0353 vs 0.1133, and DeepSeek-V4 0.0242 vs 0.0286. All outputs were finite and GPTQ was better than RTN.
Validation
ruff check gptqmodel docs/eora tests setup.py-> All checks passed1024 passed, 135 skipped108 passed, 12 skippedtests/test_mllama_support.py tests/test_hrm_text_support.py-> 19 passed on eachGPU-1892aea4-cc09-827c-b9a5-93d4eef7f5aeand AMD R9700 viaHIP_VISIBLE_DEVICES=0. The RTX 5090 was not used.Documentation
docs/transformers-5-compat.mdnow combines the landed A-D flow with these E-I/Also flows and measured evidence, and is linked fromREADME.md. Mermaid fences are validated by GitHub-compatible syntax.Reviewer notes