Repository navigation
fix(models): share the Nemotron-H layer declaration with Nemotron Omni (#4355) - #4392
Merged
Merged
Conversation
#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
Collaborator
Author
|
Claim confirmed against current Root cause is the local mixer-only |
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.
Fixes #4355
TL;DR
NemotronOmniQModelsubclassesNemotronHQModelbut kept a local, mixer-onlycopy 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_MODULESdeclaration and mounts it under both decoderprefixes. Net: 8 files, +398/-38.
Measured against
Nemotron-3-Nano-Omni-30B-A3B-Reasoning-BF16tensor shapes:29.842B of 31.578B language-model parameters (94.5%) were undeclared, of
which 29.375B are routed experts (2944
up_proj+ 2944down_proj).1. The problem
5e8a247(#4245) fixed the Nemotron-H tree and left the Omni tree alone.NemotronOmniQModeloverrodemodule_treewith the pre-fix tuple, so itinherited
dynamic_expert_index="n_routed_experts"andlayer_modules_strict=Falsewith nothing to expand and nothing to complainabout.
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:#a8071adictgptqmodel/models/definitions/nemotron_omni.py:38-56(before this PR)NEMOTRON_H_LAYER_MODULESimportup_proj:3without:nosrcup_proj:3:nosrcfrom the shared declarationmixer.experts:moe,mixer.shared_experts,mixer.gate,mixer.conv1dThe 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
mainwithexpected 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:#237804Because 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_projlooked 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:#237804The dense
mixer.up_projalready carried:nosrcfor exactly this reason(
relu(x)^2fold 2.2e-2,docs/awq-scaling-groups.md); the expert MLPs are thesame network and now say so too.
3. Failure and ambiguity contract
Linear/Convabsent from the treetest_nemotron_omni_real_decoder_leaves_are_declaredfailsrelu2expert producer offered as a fold source:nosrc, group dropped, plain quantizationn_routed_expertsmissing/non-scalar4. Change inventory
gptqmodel/models/definitions/nemotron_h.pyNEMOTRON_H_LAYER_MODULES,:nosrcon routed/shared expertup_projgptqmodel/models/definitions/nemotron_omni.pylanguage_model.backbonetests/module_tree/fixtures/registered_module_plans.jsontests/module_tree/test_nemotron_h_model_tree.pytests/test_awq_scaling_groups.pyup_projadded to the declared non-source listdocs/model-tree-resolution.mddocs/awq-scaling-groups.mdREADME.md5. Tests / guarantees
test_nemotron_h_model_tree.py::test_nemotron_omni_reuses_the_nemotron_h_layer_declaration...::test_nemotron_omni_plan_covers_moe_router_conv_and_experts:!,up_projis:nosrc...::test_nemotron_omni_real_decoder_leaves_are_declaredNemotronHForCausalLM, mounts it atlanguage_model.backbone, and walksstate_dict()owners...::test_nemotron_omni_simple_layer_modules_expand_the_routed_experts#expands toexperts.0..N; router/conv excluded...::test_nemotron_omni_awq_groups_preserve_the_real_decoder_layer_output1e-5relativetest_awq_scaling_groups.py::test_declared_non_sources_never_become_prev_ops[nemotron_h]up_projnever becomesprev_optest_moe_tags.py::...marks_dynamic_expert_root[NemotronOmniQModel-...]test_registered_module_plans.py::...matches_quantization_consumers[nemotronh_nano_omni_reasoning_v3]Remote-code layout tests skip with a precise reason when the checkpoint's
modeling_nemotron_h.pyis unavailable; the registry contract and thedeclaration-identity test always run.
6. Validation
Run with the repository's CUDA and ROCm environments against local checkout of
this branch.
The 7 module_tree failures are pre-existing on unmodified
main; verified byrunning the same nodes in a clean
origin/mainworktree:maintest_awq_relationships.py::...[falcon-ssm-width-collision]test_fusion_kernel_backends.py::...[*-cuda-AwqGEMMTritonLinear-float16]x3test_moe_expert_coverage.py::...[bailing_hybrid]test_registry_leaf_coverage.py::...[glm4v]test_shared_input_cpu_forward.py::...[jamba]test_awq_scaling_groups.py::...[falcon_h1],[falcon_mamba],[nemotron_h]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 aBaseQuantLinearsubclass, router and
conv1duntouched, checkpoint state containsqweight/qzeros/scales/g_idxforexperts.0..7. The same run completed onCUDA and ROCm.
The real checkpoint reports
n_routed_experts=128atllm_config.n_routed_experts, resolved through_expert_count_config→text_config; the plan now expands all 128.7. Reviewer notes
between sibling definitions; sharing the object is cheaper and cannot drift.
NemotronHPuzzleQModelkeeps its own tree on purpose: Puzzle layers areheterogeneous (Mamba / attention / MoE with optional latent projections) and
its
mixer.experts/shared_expertswere already declared. It therefore doesnot need
mixer.gate/mixer.conv1dat the layer root.nosrcchange is a behaviour change for plainnemotron_htoo: theprevious tree only marked the dense
up_proj. Expert folds were silentlywrong before; now those two groups fall back to plain quantization. The block
input norm still folds routed + shared experts together.
docs/model-tree-resolution.mdgained a section titled for the mechanism("Shared decoder declarations across variants"), not for this PR.
8. CI status notes
ruff-checkcurrently fails onmainas well, with the identical 13 findings(12
I001import-sort, 1F821inparoquant_triton.py). They come from recentmaincommits and touch none of the files in this PR;ruff checkon the fourchanged Python files is clean:
AWQ CPU (unit)fails 4 nodes intests/test_awq_weight_mean.pywithunexpected keyword argument 'sym'/'syms'. Those come from the AWQ processorsignature, not this change: a clean
origin/mainworktree fails the same 9nodes in that file (
9 failed, 79 passed), and this branch fails the identical9 (
9 failed, 79 passed). Nothing in the changed paths is involved.