Skip to content

fix(models): transformers 5.22 loader, mixer guards, tree root and META buffers (#4040) - #4049

Merged
Qubitium merged 3 commits into
mainfrom
fix/issue-4040-loader
Nov 14, 2026
Merged

Qubitium merged 3 commits into
mainfrom
fix/issue-4040-loader

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

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:1693 on main) queried the Transformers registry with config.model_type only. Transformers 5.22 registers GPT-NeoX's ^embed_out\. -> lm_head. rename under the class name:

get_checkpoint_conversion_mapping("gpt_neox")            -> None
get_checkpoint_conversion_mapping("GPTNeoXForCausalLM")  -> [WeightRenaming(['^embed_out\.'] -> ['lm_head.'])]

LazyTurtle therefore looked for lm_head.weight and every GPT-NeoX save ended in FileNotFoundError: 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 each config.architectures entry. This is generic, so NemotronH_Omni_Reasoning_V3 and MtpModel are covered without special cases. gptqmodel/models/definitions/gpt_neox.py:11 now declares lm_head = "lm_head"; the conversion map bridges it to embed_out.weight in the checkpoint.

B. monkey_patch installed removed mixer internals

The patches called falcon_mamba_inner_fn, slow_forward, cuda_kernels_forward, and torch_forward, all removed from the 5.22 mixers:

Family Before After
FalconMamba ImportError: cannot import name 'falcon_mamba_inner_fn' (falcon_mamba.py:70 on main) module symbols probed with getattr; patch installed only if the mixer class still has slow_forward + cuda_kernels_forward
Zamba v1 AttributeError: 'ZambaMambaMixer' object has no attribute 'slow_forward' (zamba.py:75 on main) patch installed only if both legacy forward methods exist
Nemotron-H patch walks self.model.backbone.layers and calls torch_forward (nemotron_h.py:75 on main) walks model.layers (native 5.22) or backbone.layers (older remote code) and installs only if both methods exist

In 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:16 declared backbone, but 5.22 maps backbone. -> model.; layer resolution returned None and looper/stage_inputs_capture.py:206 raised TypeError: 'NoneType' object is not subscriptable. The definition now declares model (gptqmodel/models/definitions/nemotron_h.py:23), with the registry fixture updated.

D. Non-persistent buffers stayed on META

  • Falcon-H1: mamba.mup_vector (persistent=False) is computed from config and never checkpointed. FalconH1QModel._restore_falcon_h1_mup_buffers() re-registers compute_mup_vector(config) in after_model_load and pre_quantize_generate_hook_start.
  • FalconMamba: after B, mixer.dt_layernorm.weight (5.22 FalconMambaWeightlessRMSNorm, non-persistent) was still META. _restore_falcon_mamba_rms_buffers() now restores {dt,b,c}_layernorm.weight in addition to the legacy dt_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;
Loading

The committed reference page is docs/transformers-5-compat.md (sections A-D, self-contained), linked from README.md. It carries the per-section before/after diagrams and failure paths.

Before / after

Section Command Before (origin/main) After
A tiny GPT-NeoX GPTQ -> save FileNotFoundError: Offloaded tensor 'lm_head.weight' not found saves and reloads; 4/4 linears quantized
B tiny FalconMamba load ImportError: cannot import name 'falcon_mamba_inner_fn' loads, quantizes, reloads
B tiny Zamba load/quantize AttributeError: 'ZambaMambaMixer' object has no attribute 'slow_forward' loads, quantizes, reloads
C tiny Nemotron-H quantize TypeError: 'NoneType' object is not subscriptable loads, quantizes, reloads; 10/10 linears
D tiny Falcon-H1 quantize RuntimeError: Lazy forward direct-state materialization left META tensors under 'mamba' loads, quantizes, reloads; 18/18 linears

Tests

New regression tests (they fail on origin/main and pass here):

tests/test_lazy_turtle_conversion_mapping.py   (3 new tests: class name, architectures, GPT-NeoX lm_head)
tests/test_falcon_mamba_support.py             (new: patch guard + real model + layernorm restore)
tests/test_zamba_support.py                    (new: patch guard)
tests/test_nemotron_h_support.py               (new: patch guard)
tests/module_tree/test_nemotron_h_model_tree.py (new: real model root + projection coverage)
tests/test_falcon_h1_support.py                (new: mup_vector restore + idempotence)

Fail-before evidence on an origin/main worktree with the same test files: 12 failed, 1 passed. Pass-after:

CUDA venv:
$ PYTHONPATH=$PWD /opt/venvs/cu130t/bin/python -m pytest -q \
    tests/test_lazy_turtle_conversion_mapping.py tests/test_zamba_support.py \
    tests/test_falcon_mamba_support.py tests/test_nemotron_h_support.py \
    tests/test_falcon_h1_support.py tests/module_tree/test_nemotron_h_model_tree.py \
    tests/module_tree/test_registered_module_plans.py tests/test_structure.py
483 passed, 1 warning

ROCm venv:
$ HIP_VISIBLE_DEVICES=2 PYTHONPATH=$PWD /opt/venvs/rocm101t/bin/python -m pytest -q \
    tests/test_lazy_turtle_conversion_mapping.py tests/test_zamba_support.py \
    tests/test_falcon_mamba_support.py tests/test_nemotron_h_support.py \
    tests/test_falcon_h1_support.py tests/module_tree/test_registered_module_plans.py
481 passed, 1 warning

Lint:
$ ruff check gptqmodel docs/eora tests setup.py
All checks passed!

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):

Family CUDA GPTQ / RTN ROCm GPTQ / RTN Coverage
GPT-NeoX 0.069 / 0.096 0.068 / 0.097 4/4
FalconMamba 0.109 / 0.113 0.101 / 0.115 6/6 declared (dt_proj is not declared)
Nemotron-H 0.142 / 0.181 0.143 / 0.179 10/10
Falcon-H1 0.079 / 0.103 0.070 / 0.089 18/18
Zamba v1 0.00115 / 0.00122 0.00115 / 0.00122 18/18 declared (shared_transf is not declared)

Hardware: RTX 4090 GPU-d458708b-c760-bbf1-08fb-8b8803a2157d (CUDA) and the assigned R9700 (HIP_VISIBLE_DEVICES=2). nvidia-smi --query-compute-apps was empty before the runs.

Notes / limitations

  • Zamba's require_pkgs gate (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.
  • Zamba's pre-existing definition does not declare the hybrid layers' shared_transf attention/FFN linears; this PR preserves that declared plan (18 declared modules, all quantized) and does not expand coverage.
  • tests/test_hf_config_compat.py has two failures that also fail on unmodified origin/main; they are unrelated to this change.
  • Never merged, never force-pushed, never touched main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant