Skip to content

fix(models): declare every decoder leaf for issue #4174 (#4174) - #4245

Merged
Qubitium merged 2 commits into
mainfrom
fix/issue-4174-module-trees
Nov 16, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/issue-4174-module-trees

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4174

TL;DR

Model definitions could silently leave checkpoint-owned decoder weights in the source dtype because the plan tests only proved that declared specs resolved; a Linear/Conv/expert leaf that the tree never mentioned was invisible. This PR fixes the affected trees, adds the missing pre-head norms and Phi-3 remote-code split, and adds an always-run registry sweep that fails when any decoder leaf is neither declared nor tagged :!/:? (including 3-D expert parameters). Net: 22 files, +927/-36.

Root causes and before/after

Model Root cause Before -> after
Voxtral definitions/voxtral.py declared language_model.model.layers; 5.22 builds model.language_model.layers decoder layers 0 -> 30
Nemotron-H MoE no mixer.experts.#, mixer.shared_experts or router entries, dynamic_expert_index unset, layer_modules_strict=False 19 undeclared leaves -> 0 (4-layer default); real checkpoints now expand all routed experts
Ling 2.0 bailing_moe attention.query_key_value/attention.dense dropped by #4080; remote code still uses them 20 attention layers FP -> declared; synthetic remote layout test
Llama-4 Maverick feed_forward:moe lacked the "" dense fallback; MoE is every other layer 3 dense-layer leaves undeclared -> 0 (4-layer mixed config); 24/48 real layers now covered
Gemma-4 MoE no router/expert entries; experts are a 3-D Gemma4TextExperts parameter and Defuser has no gemma4 entry 2 undeclared owners (experts, router.proj) -> 0; generic Defuser pass splits all 8 experts
Phi-3 128k longrope remote Phi3MLP class path bypasses Defuser's native registration, leaving fused mlp.gate_up_proj under a strict gate/up tree strict resolution failed -> after_defuser_conversion splits into gate/up
Zamba / Zamba2 pre_lm_head_norm_module="lm_head" ran the head on its own input; mamba.conv1d and shared transformer subtree undeclared 9 / 27 undeclared leaves -> 0; norm now model.final_layernorm
Jamba mamba.dt_proj and mamba.conv1d undeclared 2 -> 0
Falcon-H1 mamba.conv1d undeclared; no pre-head norm 1 -> 0; norm now model.final_layernorm
PhiMoE / HRM-Text / Nemotron-H no pre-head norm model.norm / model.H_module.final_norm / model.norm_f
Kimi-Linear native rotary_embedding pointed at nonexistent model.rotary_emb; self_attn.conv1d undeclared 1 -> 0; phantom path removed
GRIN-MoE block_sparse_moe.gate undeclared gate declared :!

The durable test

tests/module_tree/test_registry_leaf_coverage.py builds every locally constructible MODEL_MAP entry on meta, runs _convert_model_with_defuser, resolves extract_layers_node(), and inventories every SUPPORTS_MODULE_TYPES leaf plus direct expert parameters (2-D and 3-D). It fails with the leaf path and layer count when ModulePlan.find() misses and no ancestor carries :!/:?.

Fail-before on parent 7c7d70439 (same test file, target subset):
12 failed, 5 passed, 118 deselected — the 12 are bailing_hybrid, falcon_h1, gemma4, gemma4_text, jamba, kimi_linear, llama4, llama4_text, nemotron_h, voxtral, zamba, zamba2.

Pass-after on this branch:
114 passed, 16 skipped, 5 xfailed on CUDA and ROCm. Skips are configs that need network (e.g. bailing_moe, grinmoe) or optional deps; xfails are reviewed, documented cases (mllama cross-attention TODO, unlimited_ocr, granitemoehybrid outside this issue's ownership, and glm4v only while installed Defuser < 0.0.31).

Flow

Old: only declared specs entered the plan, so an undeclared leaf never reached a warning.

flowchart TD
    A["MODEL_MAP entry"] --> B["simple_layer_modules"]
    B --> C["declared spec list"]
    C --> D["create_named_modules"]
    D -->|"match"| E["quantize"]
    D -->|"miss"| F["warning or strict error"]
    G["layer Linear/Conv/expert leaf"] --> H{"declared?"}
    H -->|"no"| I["silently stays in source dtype"]
    H -->|"yes"| C
    style I fill:#f8d7da,stroke:#b02a37
Loading

New: the registry test independently inventories the real layer tree.

flowchart TD
    A["MODEL_MAP model_type"] --> B["AutoConfig.for_model"]
    B --> C{"local config?"}
    C -->|"no"| S["skip: needs network"]
    C -->|"yes"| D["loader.from_config on meta"]
    D --> E["_convert_model_with_defuser"]
    E --> F["get_layers_with_prefixes"]
    F --> G["ModulePlan.from_tree"]
    G --> H["leaf inventory: Linear/Conv/Embedding/expert"]
    H --> I["declared: exact spec or tagged ancestor"]
    I -->|"covered"| J["pass"]
    I -->|"uncovered"| K["fail: path + layer count"]
    style S fill:#fff3cd,stroke:#997404
    style K fill:#f8d7da,stroke:#b02a37
Loading

Phi-3 remote-code conversion:

flowchart LR
    A["remote Phi3ForCausalLM"] --> B["_convert_model_with_defuser"]
    B --> C{"Defuser split Phi3MLP?"}
    C -->|"native class"| D["gate_proj / up_proj"]
    C -->|"remote class"| E["Phi3QModel.after_defuser_conversion"]
    E --> F["chunk gate_up_proj on dim 0"]
    F --> D
    D --> G["ModulePlan resolves gate/up/down"]
    style E fill:#fff3cd,stroke:#997404
Loading

The committed reference page is docs/module-tree-leaf-coverage.md; it is linked from README.md.

Tests run

CPU only, meta-device construction; no GPU used (never the RTX 5090). Thread caps OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 OPENBLAS_NUM_THREADS=4 NUMEXPR_NUM_THREADS=4.

  • /opt/venvs/cu130t/bin/python -m pytest tests/module_tree/test_issue_4174_model_trees.py tests/module_tree/test_registry_leaf_coverage.py tests/module_tree/test_registered_module_plans.py tests/module_tree/test_nemotron_h_model_tree.py tests/module_tree/test_jamba_model_tree_consumption.py tests/module_tree/test_kimi_linear_native_tree.py tests/module_tree/test_gemma_olmo_family_plan_coverage.py tests/test_bailing_hybrid_support.py tests/test_zamba_support.py tests/test_zamba2_support.py tests/test_gemma4_support.py tests/test_falcon_h1_support.py tests/test_hrm_text_support.py -q -> 626 passed, 16 skipped, 5 xfailed.
  • Registry sweep alone on CUDA -> 114 passed, 16 skipped, 5 xfailed.
  • Registry sweep alone on ROCm (/opt/venvs/rocm101t/bin/python, CPU) -> 114 passed, 16 skipped, 5 xfailed.
  • Per-model tests on ROCm -> 17 passed.
  • Parent 7c7d70439 with the same registry file, target subset -> 12 failed, 5 passed.
  • ruff check gptqmodel docs/eora tests setup.py -> All checks passed.

Residual risk / out of scope

  • Zamba/Zamba2 shared transformer subtrees are now explicitly tagged :! (unchanged BF16 behavior) instead of undeclared. Quantizing those shared blocks is a separate behavioral change and is not done here.
  • mllama cross-attention remains FP (known TODO in the issue); the registry test records it as an explicit xfail.
  • unlimited_ocr and granitemoehybrid are xfailed because their definitions are outside this issue's file ownership.
  • glm4v passes on Defuser >= 0.0.31; the local venv has 0.0.29, so it is xfailed only for that version.
  • bailing_moe and grinmoe configs are remote-code only; the registry sweep skips them (no network) and their layouts are pinned by local synthetic module tests.

@Qubitium
Qubitium merged commit 5e8a247 into main Nov 16, 2026
8 of 9 checks passed
@Qubitium
Qubitium deleted the fix/issue-4174-module-trees branch November 16, 2026 05:44
Qubitium added a commit that referenced this pull request Nov 17, 2026
…4846)

Section A of #4769, each item fixed at its test double/oracle/expectation.
No library behaviour was changed.

Fixed:
- test_exl3_workspace_release / test_offload_base_modules_restored: give the
  ModuleLooper doubles the state loop() now reads (_inflight_layer,
  _dangling_threads, Device-SMI handles, and a real model for the success
  path). Before: AttributeError while handling the injected failure; after:
  7 passed.
- test_local_model_paths: the fake loaded models are SimpleNamespace doubles
  with log_kv_cache_estimate, matching GPTQModel.load. Before: AttributeError
  on a bare object(); after: 29 passed.
- test_diffusion_gemma_support: the hand-built DiffusionGemmaQModel double now
  carries quantize_config.activation_mode. Before: AttributeError; after: the
  post-quantize sync test passes.
- test_tenstorrent_support: window starts follow the current
  iter_calibration_windows spacing (0, 18, 37, 56). Before: the stale
  [0, 14, 28, 42] oracle.
- test_model::test_dequantize_model_awq: the fixture packs the real AWQ GEMM
  [0, 2, 4, 6, 1, 3, 5, 7] interleave instead of natural order, which is what
  dequantize_model reverses. Before: 95/128 elements differed.
- test_fallback: the sym=True oracle uses zero = 2 ** (bits - 1) for every
  strategy, not an asymmetric zero point. Before: 32/32 zero mismatches.
- test_gsq_method_adapters: FP8 pack_calibrated keeps the checkpoint bias in
  FP32 on purpose; assert that dtype and value instead of FP16.
- test_serialization: offload_to_disk_path is deliberately absent from the
  checkpoint meta (#4327); assert its absence instead of its presence.
- test_norm_lifecycle: quantize() now materializes the model and keeps the v2
  runtime zero layout (#4380/#4426/#4063); assert no meta/inference parameters
  and validate_tuning_model(model.model) instead of the stale reload-only
  guard.
- test_vptq_memory_4391: the legacy reference allocates >= 2 full-size
  temporaries on torch 2.15, not exactly 3; pin that it is worse than the
  chunked path instead of an exact torch-version-dependent count.
- test_jamba_support: the module tree declares mamba.x_proj (#4245); update
  the simple list and the dense-mixer assertions.
- test_marlin_jit: with desc_act=False and one group, g_idx is all zeros, not
  arange(in_features).
- test_dynamic::test_skip_module: replace brittle paris/king keyword matching
  on greedy output with a coherence check on the continuation.
- test_allspark_awq_cuda: install the checkpoint tensors as buffers, as a real
  load does, instead of Parameters that _kernel_bias caches as a second
  parameter (which leaked _bias_value into state_dict).
- test_bits_new: select the bit width with parameterized.expand([2, 3, 4, 8])
  instead of the BITS environment variable (AGENTS.md: behaviour comes from
  config/API, not env).
- test_checkpoint_method_compatibility: use group_size=128 for the native AWQ
  GEMV/LLM-AWQ formats (GEMV accepts 64/128, LLM-AWQ only 128) and widen the
  fixture to hidden_size=128 for LLM-AWQ, whose in_features must divide 128.
  Gate the ~30-minute subprocess matrix behind the new opt-in
  checkpoint_recovery marker (same mechanism as gptq_cuda_e2e) so the file no
  longer always times out in a 600 s slot. Target cases
  test_format_checkpoint_recovery[awq-gemv], [awq-llm-awq] and both eora
  variants pass with -m checkpoint_recovery.

Skipped because this host is CUDA sm_80, not ROCm:
- every ROCm/gfx1201-only item belongs to #4770 and was not touched.

Deferred:
- tests/test_quant_batch.py::test_diff_batch: an FP32-calibration +
  dequantized-weight rewrite OOMs here (GPU 5 has ~14 GiB free while a shared
  83 GiB process holds the card), so it was not shipped unverified.
- test_bits_new was exercised for bits=2 against a 15M local model only; the
  1B eval of the other widths does not fit the 600 s slot here.

Environment-only failures seen while validating (not changed):
- test_serialization.py::test_gptq_v1_serialization and
  test_save_keeps_live_model_inference: flash_attn_2_cuda undefined symbol.
- test_diffusion_gemma_support.py::test_diffusion_gemma_generic_defusion_preserves_forward:
  defuser 0.0.25 is older than the required 0.0.31.
- test_jamba_support.py::test_tiny_jamba_gptq_quantization_smoke: mamba-ssm is
  not installed.

Validation (CUDA_VISIBLE_DEVICES=5, sm_80):
- 13 touched files in one run: 380 passed, 110 skipped, 4 failed (the three
  environment-only causes above).
- test_model.py -k dequantize_model: 12 passed, 1 skipped.
- test_marlin_jit.py::test_marlin_cuda_smoke_build_and_forward: 1 passed.
- test_dynamic.py::TestDynamic::test_skip_module: 1 passed (flash-attn
  auto-enable disabled locally because the host extension has an undefined
  symbol; the committed test still hits that environment failure).
- test_checkpoint_method_compatibility.py default: 4 passed, 95 skipped;
  -m checkpoint_recovery targeted AWQ GEMV/LLM-AWQ cases: 4 passed.
- test_bits_new.py::Test::test_quant_and_eora_0 (bits=2, 15M model): 1 passed.
Qubitium pushed a commit that referenced this pull request Nov 19, 2026
#4245 declared every decoder leaf, which makes `mamba.x_proj` a quantization
target. The tiny-model smoke test still asserted it stays a dense
`nn.Linear`, so it failed on main.

`conv1d` and `dt_proj` remain dense; only `x_proj` moves.

Red: assert isinstance(modules["model.layers.0.mamba.x_proj"], torch.nn.Linear)
  fails on ddf11fc.
Green: test_jamba_support.py 6 passed.
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.

[BUG][model] Several model definitions silently leave layers unquantized against transformers 5.22

1 participant