Repository navigation
fix(models): transformers 5.22 loader, mixer guards, tree root and META buffers (#4040) - #4049
Merged
Merged
Conversation
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 covers sections A-D only; sections E-I (LFM2-MoE, GLM-4.x MoE, mllama, Kimi-Linear, HRM-Text, glmasr and the "Also" list) are owned by a separate change.
Root causes and fixes
A. GPT-NeoX / Pythia save crash: class-keyed conversion map
LazyTurtle.infer_hf_conversion_map_reversed()(gptqmodel/utils/structure.py:1693onmain) queried the Transformers registry withconfig.model_typeonly. Transformers 5.22 registers GPT-NeoX's^embed_out\.->lm_head.rename under the class name:LazyTurtle therefore looked for
lm_head.weightand every GPT-NeoX save ended inFileNotFoundError: Offloaded tensor 'lm_head.weight' not found(gptqmodel/utils/model.py:2362).Fix: new
_hf_conversion_lookup_keys()(gptqmodel/utils/structure.py:1693) tries the explicit definition alias,config.model_type,type(model).__name__, and eachconfig.architecturesentry. This is generic, soNemotronH_Omni_Reasoning_V3andMtpModelare covered without special cases.gptqmodel/models/definitions/gpt_neox.py:11now declareslm_head = "lm_head"; the conversion map bridges it toembed_out.weightin the checkpoint.B.
monkey_patchinstalled removed mixer internalsThe patches called
falcon_mamba_inner_fn,slow_forward,cuda_kernels_forward, andtorch_forward, all removed from the 5.22 mixers:ImportError: cannot import name 'falcon_mamba_inner_fn'(falcon_mamba.py:70onmain)getattr; patch installed only if the mixer class still hasslow_forward+cuda_kernels_forwardAttributeError: 'ZambaMambaMixer' object has no attribute 'slow_forward'(zamba.py:75onmain)self.model.backbone.layersand callstorch_forward(nemotron_h.py:75onmain)model.layers(native 5.22) orbackbone.layers(older remote code) and installs only if both methods existIn 5.22 the native mixers select the eager path themselves outside training, so leaving the upstream forward is the correct fallback.
C. Nemotron-H tree root renamed
nemotron_h.py:16declaredbackbone, but 5.22 mapsbackbone.->model.; layer resolution returnedNoneandlooper/stage_inputs_capture.py:206raisedTypeError: 'NoneType' object is not subscriptable. The definition now declaresmodel(gptqmodel/models/definitions/nemotron_h.py:23), with the registry fixture updated.D. Non-persistent buffers stayed on META
mamba.mup_vector(persistent=False) is computed from config and never checkpointed.FalconH1QModel._restore_falcon_h1_mup_buffers()re-registerscompute_mup_vector(config)inafter_model_loadandpre_quantize_generate_hook_start.mixer.dt_layernorm.weight(5.22FalconMambaWeightlessRMSNorm, non-persistent) was still META._restore_falcon_mamba_rms_buffers()now restores{dt,b,c}_layernorm.weightin addition to the legacydt_rms/b_c_rms.New flow
flowchart TD L["LazyTurtle shell load"] --> C["infer_hf_conversion_map_reversed"] C --> K["model_type, class name, architectures"] K --> R{"mapping found?"} R -- No --> X["FileNotFoundError: lm_head.weight"] R -- Yes --> M["materialize decoder from checkpoint"] M --> B{"non-persistent buffer?"} B -- Yes --> H["after_model_load restore hook"] H --> Q["quantize"] B -- No --> Q Q --> P["monkey_patch"] P --> G{"legacy mixer API present?"} G -- No --> U["keep upstream eager forward"] G -- Yes --> I["install GPT-QModel forward"] U --> S["save + reload"] I --> S classDef failure fill:#ffe8e8,stroke:#b30000,color:#111; class X failure;The committed reference page is
docs/transformers-5-compat.md(sections A-D, self-contained), linked fromREADME.md. It carries the per-section before/after diagrams and failure paths.Before / after
FileNotFoundError: Offloaded tensor 'lm_head.weight' not foundImportError: cannot import name 'falcon_mamba_inner_fn'AttributeError: 'ZambaMambaMixer' object has no attribute 'slow_forward'TypeError: 'NoneType' object is not subscriptableRuntimeError: Lazy forward direct-state materialization left META tensors under 'mamba'Tests
New regression tests (they fail on
origin/mainand pass here):Fail-before evidence on an
origin/mainworktree with the same test files: 12 failed, 1 passed. Pass-after:End-to-end tiny-model checks (GPTQ 4-bit, group 32, save -> reload
BACKEND.TORCH, logits vs fp16 and an independent per-group RTN baseline):dt_projis not declared)shared_transfis not declared)Hardware: RTX 4090
GPU-d458708b-c760-bbf1-08fb-8b8803a2157d(CUDA) and the assigned R9700 (HIP_VISIBLE_DEVICES=2).nvidia-smi --query-compute-appswas empty before the runs.Notes / limitations
require_pkgsgate (mamba_ssm,causal_conv1d) is not satisfiable in these venvs. The Zamba end-to-end run used a local harness that bypasses only that package gate so the pure-PyTorch 5.22 fallback could be exercised; no repository behaviour was changed. The patch guard itself is covered by unit tests on both venvs.shared_transfattention/FFN linears; this PR preserves that declared plan (18 declared modules, all quantized) and does not expand coverage.tests/test_hf_config_compat.pyhas two failures that also fail on unmodifiedorigin/main; they are unrelated to this change.main.