Repository navigation
fix(granitemoehybrid): declare every checkpoint-owned decoder owner - #4674
Merged
Merged
Conversation
The module tree declared only mamba.in_proj/out_proj, so mamba.conv1d and the gated mamba.norm failed ModulePlan.find(), and dt_bias/A_log/D resolved through the untagged mamba container with no quantize/exclude policy. The MoE router had no plan entry at all. Declare the container, conv1d and norm as explicit dense owners and the router under the :moe root. The new real-model plan test walks state_dict() owners on a tiny GraniteMoeHybridForCausalLM and removes the registry xfail for this family. The declaration also records two AWQ repairs measured on the tiny model: folding in_proj into out_proj crosses the convolution and SSM scan (1.6e-1 relative logit drift), and folding the post-attention norm for the routed experts omits the shared_mlp consumer outside the MoE replay boundary (1.5e-2). Both sources are marked nosrc so the projections quantize plainly; out_proj folds the gated norm, which is output-neutral (1.6e-7).
This was referenced Nov 17, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 17, 2026
…4891) (#5019) * fix(awq): replay a `**kwargs` block against the norm the layer owns (#4891) Two defects in Hymba's AWQ path; the first hid the second. Replay: `AWQProcessor._sanitize_kwargs` kept only the keys that appear by name in `inspect.signature(module.forward)`. `HymbaBlock.forward` is `(hidden_states, past_key_value=None, **kwargs)` and reads `attention_mask`, `position_ids`, `kv_last_layer` and `use_swa` out of the catch-all, so the filter handed it an empty dict and the scale search aborted in layer 0 with `KeyError: 'attention_mask'`. A `VAR_KEYWORD` parameter now means the module accepts the captured kwargs, minus the processor's own private bookkeeping (`_awq_feature_kwargs`); `_prepare_module_forward` also treats `position_ids` as accepted so a 2-D activation is promoted to `[1, seq, hidden]` the way the block's `pack(...)` requires. Scaling groups: the tree declared `post_attention_layernorm`, which `HymbaDecoderLayer` does not own -- the norm in front of the MoE is `pre_moe_layernorm`. With no producer of its own, the routed-expert gate/up block was merged into the preceding norm run and folded into `input_layernorm`: input_layernorm -> [mamba.in_proj, moe.experts.0.gate_proj, moe.experts.0.up_proj] The experts read `pre_moe_layernorm(residual + mamba_out)`, so that fold is not output-preserving: 3.3e-2 (layer 0) and 2.5e-2 (layer 1) relative logit change on the synthetic fixture. The tree now declares `pre_moe_layernorm`, marks `mamba.in_proj` `:nosrc` (the conv/SSM path between `in_proj` and `out_proj` is not homogeneous, the same guard as Falcon-H1's mixer in #4674) and declares the mixer's dense leaves `conv1d`, `x_proj.0` and `dt_proj.0` `:!`. Groups become input_layernorm -> [mamba.in_proj] pre_moe_layernorm -> [moe.experts.0.gate_proj, moe.experts.0.up_proj] (+ moe.gate as a scale consumer) moe.experts.0.up_proj -> [moe.experts.0.down_proj] and every fold measures < 1e-7. `tests/test_hymba_awq_4891.py` synthesises the layer from the exact module names the tree declares (a `**kwargs` block, `input_layernorm` -> `mamba` -> `pre_moe_layernorm` -> `moe`) and asserts the sanitisation, the promotion, the declared tree, the group set and the fold invariant. Seven nodes: 7 failed on unmodified `origin/main`, 7 pass here. Real `nvidia/Hymba-1.5B-Base` weights are not available on this host (no checkpoint, no remote code, no `mamba_ssm`/`causal_conv1d`), so the fixture is the verification boundary for this commit. * ci(awq): run the Hymba AWQ regression in the unit suite The new file is the only coverage for #4891 on a CPU host. The workflow lists its files explicitly, so the path filter alone would start the job without ever executing it. * test(hymba): bind the required replay kwargs instead of bare reads (#4891) Two bare `kwargs[...]` expressions in the fake block's forward were statements with no effect. Bind them explicitly; a missing key still raises KeyError, which is the behaviour the test pins. * test(module_tree): pin Hymba's corrected plan in the registered inventory `tests/module_tree/test_registered_module_plans.py` compares every definition's compiled blocks against `fixtures/registered_module_plans.json`, so the Hymba case has to follow the tree fix: `post_attention_layernorm` becomes `pre_moe_layernorm`, and the mixer's dense leaves (`conv1d`, `x_proj.0`, `dt_proj.0`) now appear in the `mamba.in_proj` block instead of being undeclared. The `AWQ CPU (unit)` job caught this; the pinned case is the only place the declared block order is written down outside the definition itself. * test(hymba): validate the required replay kwargs explicitly The stub block read `kv_last_layer`/`position_ids` into underscore locals to assert the `**kwargs` replay forwards them; both bindings were unused, so the code-quality review flagged them. Check the whole required set up front and raise `KeyError` with the missing key, which is the behaviour the test pins.
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.
TL;DR
GraniteMoeHybridQModel.module_treedeclared onlymamba.in_proj/mamba.out_proj.Every other checkpoint-owned tensor of the Mamba branch either had no plan entry
(
mamba.conv1d,mamba.norm) or resolved through an untagged container(
mambaowningdt_bias/A_log/D), and the MoE router had no entry at all.This PR declares those owners explicitly, adds a real-model plan/ownership test,
and removes the registry
KNOWN_UNDECLAREDexemption that hid the gap.Two AWQ defects surfaced while validating the newly declared owners and are
fixed in the same declaration: a fold across the state-space path and a fold
whose replay boundary misses
shared_mlp.1. The problem
ModulePlanis the oracle for checkpoint-owned weights, but the registry sweepin
tests/module_tree/test_registry_leaf_coverage.pyscanned supportedquantizable modules + expert parameters, not every
state_dict()owner. It alsocarried an explicit exemption:
A tiny real
GraniteMoeHybridForCausalLMbuilt onmetaand converted through_convert_model_with_defuserresolved owners as follows:state_dict()itemmamba.conv1d.weight,mamba.conv1d.biasmamba.conv1dplan.find()→Nonemamba.norm.weightmamba.normplan.find()→Nonemamba.dt_bias,mamba.A_log,mamba.Dmambaflags == ()andquantize is Trueblock_sparse_moe.router.weightblock_sparse_moe.routerplan.find()→Nonemamba.in_proj.weight,mamba.out_proj.weightOld flow (
gptqmodel/models/definitions/granitemoehybrid.py:29-42on42c5bca11):flowchart TD A["granitemoehybrid module_tree"] --> B["mamba: in_proj, out_proj"] A --> C["post_attention_layernorm:!"] A --> D["block_sparse_moe:? → experts"] E["mamba.conv1d / mamba.norm modules"] --> F{"plan.find()"} G["mamba.dt_bias / A_log / D"] --> F H["block_sparse_moe.router.weight"] --> F F -- "no entry" --> X["undeclared owner<br/>no policy recorded"] F -- "container entry, flags ()" --> Y["reported as quantizable<br/>though it is a parameter owner"] style X fill:#f8d7da,stroke:#842029 style Y fill:#fff3cd,stroke:#997404Mechanisms replaced, with old locations:
granitemoehybrid.py:29conv1d/norm/container parameters never reached the planmambacontainergranitemoehybrid.py:29dt_bias/A_log/Dresolved with empty flagsgranitemoehybrid.py:32-38test_registry_leaf_coverage.py:1662. The new flow
flowchart TD T["module_tree"] --> M["mamba:!<br/>in_proj:0:nosrc, out_proj:1,<br/>conv1d:!, norm:!"] T --> N["post_attention_layernorm:!:nosrc"] T --> R["block_sparse_moe:moe:?<br/>router:!"] L["layer.state_dict()"] --> O["deepest owner"] O --> P["ModulePlan.find(owner)"] P --> Q{"policy flag?"} Q -- "quantize and in simple_layer_modules" --> OK["quantized projection"] Q -- "! or ?" --> DENSE["explicit dense owner"] Q -- "missing or no flag" --> FAIL["test fails with path + layers"] M --> P N --> P R --> P style FAIL fill:#f8d7da,stroke:#842029 style DENSE fill:#d1e7dd,stroke:#0f5132New declarations:
granitemoehybrid.py:34-45—"mamba:!"container,in_proj:0:nosrc,out_proj:1,conv1d:!,norm:!.granitemoehybrid.py:54—post_attention_layernorm:!:nosrc.granitemoehybrid.py:59—"router:!": ()under the:moeroot.test_registry_leaf_coverage.py:166— exemption removed.3. AWQ repairs found while validating the new owners
GraniteMoeHybridDecoderLayer.forwardruns the Mamba mixer, then hands thepost-attention norm to
block_sparse_moeandshared_mlp. The mixer splitsin_projinto gate / conv input /dt; the convolution and the SSM scanconsume those channels before the gated
normproducesout_proj's input.Measured with non-unit scales and no quantization, comparing full-model logits
against a fresh native baseline (tiny 2-layer model, FP32, eager Torch Mamba-2):
input_layernorm → mamba.in_projmamba.in_proj → mamba.out_projin_proj:nosrc)mamba.norm → mamba.out_projnormundeclared)post_attention_layernorm → expertsshared_mlpoutside the MoE replay boundarypost_attention_layernorm:nosrc)experts.N.up_proj → experts.N.down_proj,shared_mlp.input_linear → output_linearThe router already received the folded post-attention scale as a
_scale_consumersentry, so declaring it did not change that compensation. Withthe source now
nosrc, the routed/shared projections and the router arequantized plainly.
docs/awq-scaling-groups.mdrecords the same table and the flow diagram;docs/module-tree-leaf-coverage.mdrecords the removed exemption.4. Failure and ambiguity contract
conv1d/ gatednormmoduleplan.find()→Noneconv1d:!/norm:!dt_bias/A_log/Don the containermamba:!router:!under the:moerootin_proj:nosrc; no group emittedshared_mlpnosrc; projections quantize plainlymamba.foo)plan.find()5. Tests
tests/module_tree/test_granitemoehybrid_model_tree.pybuilds the installedGraniteMoeHybridForCausalLMfrom a tiny config onmeta, runs the same_convert_model_with_defuseras the loader, and asserts:test_every_checkpoint_tensor_owner_is_declaredstate_dict()owner resolves, and dense owners carry:!/:?test_mamba_branch_owners_are_explicit_and_densemamba/conv1d/normdense, projections quantized, container parameters are realnn.Parameterstest_moe_router_is_checkpoint_owned_and_unquantized:moeroottest_mamba_projections_keep_their_declared_blockssimple_layer_modulesstill yields the two Mamba projection blockstest_awq_does_not_fold_across_the_state_space_pathtest_awq_post_attention_norm_is_not_a_scale_sourcetest_awq_folds_preserve_the_full_model_outputThe full-model fold test pins transformers' eager Torch Mamba-2 reference
(
__wrapped__) because the optional fused kernels are CUDA-only; it does notclaim those kernels were exercised.
Also updated:
tests/module_tree/fixtures/registered_module_plans.json,tests/module_tree/test_moe_tags.py(router is now a declared child of the:moeroot), and.github/workflows/awq_cpu.yml(new test added to the AWQ CPUsuite).
6. Validation
Red evidence (only the definition reverted to
42c5bca11, new test kept):Green:
The three failures (
test_definition_subset_ordering.py::test_issue_4372_tiny_model_data_flow[nemotron_h],test_fusion_kernel_backends.py::test_every_registered_gptq_awq_kernel_has_an_explicit_fusion_contract,test_shared_input_cpu_forward.py::test_plan_matches_real_forward_inputs[jamba]) reproduce onunmodified
42c5bca11on the same host (CUDA-onlymamba_ssm/Triton fallbackand an unregistered AWQ kernel), so they are not caused by this change.
AWQ baseline from the onboarding checklist: 577 passed.
Merged AWQ/fold/plan family run: 818 passed, 19 skipped, 3 xfailed.
A tiny end-to-end GPTQ quantize → save → reload run reproduced the defect
(
mamba.conv1dstayed an unquantizedConv1dbefore the change) and, after thechange, keeps
mamba.conv1d,mamba.normandblock_sparse_moe.routerdensewhile every declared projection is quantized.
7. Scope and limits
fixture plus the declared checkpoint conversion mappings
(
get_checkpoint_conversion_mapping("granitemoehybrid")), not against realcheckpoint keys; runtime-only tensors are not treated as obligations.
layer_typesmix or a checkpoint with a differentmamba_*layout isunverified.
fused
mamba_ssm/causal_conv1dkernels are not qualified by this PR.