Skip to content

fix(models): share the Nemotron-H layer declaration with Nemotron Omni (#4355) - #4392

Merged
Qubitium merged 1 commit into
mainfrom
fix/4355-nemotron-omni-experts
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/4355-nemotron-omni-experts

Conversation

@ZX-ModelCloud

@ZX-ModelCloud ZX-ModelCloud commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #4355

TL;DR

NemotronOmniQModel subclasses NemotronHQModel but kept a local, mixer-only
copy
of the layer declaration. On the real checkpoint that copy leaves the
routed experts, shared experts, top-k router and SSM convolution undeclared, so
they stay in BF16 while quantization reports success. This PR publishes one
NEMOTRON_H_LAYER_MODULES declaration and mounts it under both decoder
prefixes. Net: 8 files, +398/-38.

Measured against Nemotron-3-Nano-Omni-30B-A3B-Reasoning-BF16 tensor shapes:
29.842B of 31.578B language-model parameters (94.5%) were undeclared, of
which 29.375B are routed experts (2944 up_proj + 2944 down_proj).

1. The problem

5e8a247 (#4245) fixed the Nemotron-H tree and left the Omni tree alone.
NemotronOmniQModel overrode module_tree with the pre-fix tuple, so it
inherited dynamic_expert_index="n_routed_experts" and
layer_modules_strict=False with nothing to expand and nothing to complain
about.

flowchart TD
    CKPT["checkpoint keys<br/>language_model.backbone.layers.N.mixer.experts.0..127"] --> PLAN["ModulePlan.from_tree<br/>NemotronOmniQModel.module_tree"]
    PLAN --> Q{"spec declared?"}
    Q -->|"mixer.q/k/v/o/in/out/gate_up/down only"| MISS["undeclared"]
    Q -->|"no routed expert spec"| MISS
    Q -->|"no shared_experts spec"| MISS
    Q -->|"no gate / conv1d spec"| MISS
    MISS --> BF16["stays in checkpoint dtype<br/>no error, no warning"]
    STRICT["layer_modules_strict = False"] --> BF16
    BF16 --> DONE["quantization reports success"]
    style BF16 fill:#ffa39e,stroke:#a8071a
    style DONE fill:#ffa39e,stroke:#a8071a
Loading
Removed local mechanism Where it lived Replacement
Omni-private mixer-only dict gptqmodel/models/definitions/nemotron_omni.py:38-56 (before this PR) shared NEMOTRON_H_LAYER_MODULES import
duplicated up_proj:3 without :nosrc same block up_proj:3:nosrc from the shared declaration
absent mixer.experts:moe, mixer.shared_experts, mixer.gate, mixer.conv1d same block declared in the shared declaration

The repo's own suite already caught this:
tests/module_tree/test_moe_tags.py::test_registered_moe_model_tree_marks_dynamic_expert_root[NemotronOmniQModel-...]
fails on main with expected one top-level :moe root, found [].

2. The new flow

flowchart TD
    DECL["NEMOTRON_H_LAYER_MODULES<br/>gptqmodel/models/definitions/nemotron_h.py"] --> H["NemotronHQModel.module_tree<br/>model.layers"]
    DECL --> O["NemotronOmniQModel.module_tree<br/>language_model.backbone.layers"]
    H --> HP["ModulePlan.from_tree"]
    O --> OP["ModulePlan.from_tree"]
    HP --> EXP["build_moe_modules_if_need<br/># -> experts.0 .. experts.N"]
    OP --> EXP
    EXP --> LOOP["ModuleLooper subset<br/>routed + shared experts quantized"]
    OP --> ROUTER["mixer.gate / mixer.conv1d<br/>:! keep checkpoint dtype"]
    style DECL fill:#d9f7be,stroke:#237804
    style LOOP fill:#d9f7be,stroke:#237804
Loading

Because the object is shared rather than copied, the AWQ policy cannot drift
either. Declaring the expert leaves exposed one more real defect in the same
declaration: their up_proj looked like a valid fold source.

flowchart LR
    UP["mixer.experts.N.up_proj"] --> ACT["relu2 activation<br/>not positively homogeneous"]
    ACT --> DOWN["mixer.experts.N.down_proj"]
    UP2["mixer.shared_experts.up_proj"] --> ACT
    ACT --> DOWN2["mixer.shared_experts.down_proj"]
    UP -.->|"before: fold source"| BAD["measured 8.7e-3 <br/>layer-output change"]
    UP2 -.->|"before: fold source"| BAD2["measured 2.4e-3<br/>layer-output change"]
    BAD --> DROP["after: :nosrc<br/>group dropped"]
    BAD2 --> DROP
    NORM["layer input norm"] --> GOOD["one group over routed + shared up_proj<br/>1.0e-8 relative"]
    style BAD fill:#ffa39e,stroke:#a8071a
    style BAD2 fill:#ffa39e,stroke:#a8071a
    style DROP fill:#fff3cd,stroke:#997404
    style GOOD fill:#d9f7be,stroke:#237804
Loading

The dense mixer.up_proj already carried :nosrc for exactly this reason
(relu(x)^2 fold 2.2e-2, docs/awq-scaling-groups.md); the expert MLPs are the
same network and now say so too.

3. Failure and ambiguity contract

Situation Before After
Omni layer-level Linear/Conv absent from the tree undeclared, silently BF16 covered by the shared declaration
Unknown leaf under the Omni decoder silent BF16 test_nemotron_omni_real_decoder_leaves_are_declared fails
Someone re-forks the declaration silence object-identity test fails immediately
relu2 expert producer offered as a fold source 8.7e-3 layer drift :nosrc, group dropped, plain quantization
n_routed_experts missing/non-scalar (unchanged) placeholder kept, miss recorded (unchanged)

4. Change inventory

Area File +/- Purpose
definition gptqmodel/models/definitions/nemotron_h.py +33/-20 one NEMOTRON_H_LAYER_MODULES, :nosrc on routed/shared expert up_proj
definition gptqmodel/models/definitions/nemotron_omni.py +12/-10 mount the shared declaration under language_model.backbone
inventory tests/module_tree/fixtures/registered_module_plans.json +7/-1 reviewed ordered blocks for the Omni case
tests tests/module_tree/test_nemotron_h_model_tree.py +294/-0 shared-declaration, real-layout, expansion, fold-preservation
tests tests/test_awq_scaling_groups.py +3/-1 routed/shared up_proj added to the declared non-source list
docs docs/model-tree-resolution.md +52/-0 new "shared decoder declarations" section
docs docs/awq-scaling-groups.md +2/-1 measured fold error and the two test nodes
docs README.md +1/-1 link the resolution page

5. Tests / guarantees

Test node Invariant
test_nemotron_h_model_tree.py::test_nemotron_omni_reuses_the_nemotron_h_layer_declaration both definitions reference the same declaration object
...::test_nemotron_omni_plan_covers_moe_router_conv_and_experts routed/shared experts quantize, router/conv are :!, up_proj is :nosrc
...::test_nemotron_omni_real_decoder_leaves_are_declared builds the checkpoint's own NemotronHForCausalLM, mounts it at language_model.backbone, and walks state_dict() owners
...::test_nemotron_omni_simple_layer_modules_expand_the_routed_experts # expands to experts.0..N; router/conv excluded
...::test_nemotron_omni_awq_groups_preserve_the_real_decoder_layer_output random non-uniform folds on the real remote decoder leave its output within 1e-5 relative
test_awq_scaling_groups.py::test_declared_non_sources_never_become_prev_ops[nemotron_h] routed/shared up_proj never becomes prev_op
test_moe_tags.py::...marks_dynamic_expert_root[NemotronOmniQModel-...] the issue's own failing test now passes
test_registered_module_plans.py::...matches_quantization_consumers[nemotronh_nano_omni_reasoning_v3] pinned blocks match the compiler

Remote-code layout tests skip with a precise reason when the checkpoint's
modeling_nemotron_h.py is unavailable; the registry contract and the
declaration-identity test always run.

6. Validation

Run with the repository's CUDA and ROCm environments against local checkout of
this branch.

pytest tests/module_tree/ -q                      2330 passed, 193 skipped, 4 xfailed, 7 pre-existing failures
pytest tests/module_tree/test_nemotron_h_model_tree.py -q   7 passed
pytest tests/module_tree/test_moe_tags.py::test_registered_moe_model_tree_marks_dynamic_expert_root  74 passed
pytest tests/test_awq_scaling_groups.py tests/module_tree/test_registered_module_plans.py ...  565 passed

The 7 module_tree failures are pre-existing on unmodified main; verified by
running the same nodes in a clean origin/main worktree:

Failing node On clean main
test_awq_relationships.py::...[falcon-ssm-width-collision] fails
test_fusion_kernel_backends.py::...[*-cuda-AwqGEMMTritonLinear-float16] x3 fails
test_moe_expert_coverage.py::...[bailing_hybrid] fails
test_registry_leaf_coverage.py::...[glm4v] fails
test_shared_input_cpu_forward.py::...[jamba] fails
test_awq_scaling_groups.py::...[falcon_h1], [falcon_mamba], [nemotron_h] fails (environment: Triton pointer on CPU tensors)

End-to-end GPTQ quantization of a 4-layer hybrid decoder (mamba, attention,
moe, moe; 8 routed experts) on both accelerator families:
routed experts 0..7, shared experts quantized to a BaseQuantLinear
subclass, router and conv1d untouched, checkpoint state contains
qweight/qzeros/scales/g_idx for experts.0..7. The same run completed on
CUDA and ROCm.

The real checkpoint reports n_routed_experts=128 at
llm_config.n_routed_experts, resolved through
_expert_count_config → text_config; the plan now expands all 128.

7. Reviewer notes

  • I deliberately did not add a "declaration equivalence" runtime check
    between sibling definitions; sharing the object is cheaper and cannot drift.
  • NemotronHPuzzleQModel keeps its own tree on purpose: Puzzle layers are
    heterogeneous (Mamba / attention / MoE with optional latent projections) and
    its mixer.experts/shared_experts were already declared. It therefore does
    not need mixer.gate/mixer.conv1d at the layer root.
  • The nosrc change is a behaviour change for plain nemotron_h too: the
    previous tree only marked the dense up_proj. Expert folds were silently
    wrong before; now those two groups fall back to plain quantization. The block
    input norm still folds routed + shared experts together.
  • docs/model-tree-resolution.md gained a section titled for the mechanism
    ("Shared decoder declarations across variants"), not for this PR.

8. CI status notes

ruff-check currently fails on main as well, with the identical 13 findings
(12 I001 import-sort, 1 F821 in paroquant_triton.py). They come from recent
main commits and touch none of the files in this PR; ruff check on the four
changed Python files is clean:

ruff check gptqmodel/models/definitions/nemotron_h.py \
           gptqmodel/models/definitions/nemotron_omni.py \
           tests/module_tree/test_nemotron_h_model_tree.py \
           tests/test_awq_scaling_groups.py
All checks passed!

AWQ CPU (unit) fails 4 nodes in tests/test_awq_weight_mean.py with
unexpected keyword argument 'sym' / 'syms'. Those come from the AWQ processor
signature, not this change: a clean origin/main worktree fails the same 9
nodes in that file (9 failed, 79 passed), and this branch fails the identical
9 (9 failed, 79 passed). Nothing in the changed paths is involved.

#4355)

NemotronOmniQModel subclasses NemotronHQModel but carried its own mixer-only
layer declaration. The multimodal checkpoint nests the same Nemotron-H decoder
at `language_model.backbone.layers`, so the local copy silently dropped the
routed experts, shared experts, top-k router and SSM convolution: they resolved
as undeclared and stayed in BF16 while quantization reported success.

Publish one `NEMOTRON_H_LAYER_MODULES` declaration from `nemotron_h.py` and
mount it under both decoder prefixes, so the two definitions cannot drift.

Declaring the expert leaves also exposed that their `up_proj` looked like a
valid AWQ fold source. The expert MLP is `down_proj(relu2(up_proj(x)))`, and
`relu2` is not positively homogeneous, so mark routed and shared `up_proj`
`:nosrc` exactly like the dense `mixer.up_proj`. Measured fold error on the
decoder layer output was 2.4e-3 for shared experts and up to 8.7e-3 per routed
expert; the block input norm remains the only source and still folds routed and
shared experts as one group.

Tests:
- pin that both definitions reference the same declaration object
- resolve the real remote decoder layout through the checkpoint's own modeling
  code and check every owned Linear/Conv leaf is declared
- expand the routed experts through `simple_layer_modules`
- re-run the AWQ fold-preservation invariant on the real Omni decoder layers
- update the registry inventory case and the declared non-source list

Fixes #4355
@ZX-ModelCloud

Copy link
Copy Markdown
Collaborator Author

Claim confirmed against current main (9b11fb3). The issue's own repro still fails there:

test_registered_moe_model_tree_marks_dynamic_expert_root[NemotronOmniQModel-...] FAILED
expected one top-level :moe root, found []

Root cause is the local mixer-only module_tree copy in nemotron_omni.py, which shadows the fixed NemotronHQModel tree. Parameter impact from the real checkpoint shapes: 29.842B of 31.578B (94.5%) of the language model is undeclared, 29.375B of it routed experts.

@Qubitium
Qubitium merged commit 0600c0a into main Nov 16, 2026
6 of 9 checks passed
@Qubitium
Qubitium deleted the fix/4355-nemotron-omni-experts branch November 16, 2026 11:32
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] Nemotron-3-Nano-Omni definition still leaves all routed and shared experts unquantized (incomplete fix of #4174)

2 participants