Repository navigation
Conversation
… real MoE norm (#4891) Two defects, the first hiding the second. 1. `AWQProcessor._sanitize_kwargs` kept only the keys that appear by name in `inspect.signature(module.forward).parameters`. `HymbaBlock.forward(self, hidden_states, past_key_value=None, **kwargs)` indexes `kwargs["attention_mask"]`, `kwargs["kv_last_layer"]`, `kwargs["position_ids"]`, `kwargs["use_cache"]` and `kwargs["use_swa"]`, so it received an empty dict and the replay raised `KeyError: 'attention_mask'` -- not an `_AWQScaleGroupError`, so `quantize()` aborted in layer 0. A `VAR_KEYWORD` parameter now passes the captured kwargs through unchanged; an explicit signature still filters. 2. `gptqmodel/models/definitions/hymba.py` declared `post_attention_layernorm`, which `HymbaDecoderLayer` does not have: the norm in front of the MoE is `pre_moe_layernorm`, applied to `residual + mamba_out`. With no producer of its own, the experts block was merged into the preceding norm run, so AWQ built `input_layernorm -> [mamba.in_proj, moe.experts.0.gate_proj, moe.experts.0.up_proj]`. The experts read `pre_moe_layernorm`'s output, so that fold was not output-preserving (measured 5.8e-2 / 8.2e-2 relative logit change in the report). The tree now declares `pre_moe_layernorm` and marks `mamba.in_proj` `:nosrc`, because `in_proj` feeds a conv/SSM/attention path that is not positively homogeneous; the previous tree only avoided that fold through a width mismatch. Fixes #4891
Collaborator
Author
|
Closing as a duplicate of #5019, which is the maintainer's version of the same two fixes (created 22:27, before this one) and already builds on #5021. Same root causes and same corrected groups ( |
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 #4891
Two defects in Hymba AWQ; the first hid the second.
1.
_sanitize_kwargsdropped every kwarg of a**kwargs-only forwardAWQProcessor._sanitize_kwargskept only keys that appear by name ininspect.signature(module.forward).parameters.HymbaBlock.forward(self, hidden_states, past_key_value=None, **kwargs)readskwargs["attention_mask"],kwargs["kv_last_layer"],kwargs["position_ids"],kwargs["use_cache"]andkwargs["use_swa"], so it got an empty dict:That is not an
_AWQScaleGroupError, soquantize()aborted in layer 0. AVAR_KEYWORDparameter now passes the captured kwargs through unchanged; a forward with an explicit signature still filters (both pinned by tests).2. The tree named a norm the decoder layer does not have
gptqmodel/models/definitions/hymba.pydeclared"post_attention_layernorm": ("post_attention_layernorm:!",)beforemoe:moe.HymbaDecoderLayerhas no such module — the norm in front of the MoE ispre_moe_layernorm, applied toresidual + mamba_out(verified againstnvidia/Hymba-1.5B-Base'smodeling_hymba.py:self.pre_moe_layernorm = HymbaRMSNorm(...)andhidden_states = self.pre_moe_layernorm(hidden_states)right beforeself.moe(...)).With no producer of its own, the experts block was merged into the preceding norm run:
The experts read
pre_moe_layernorm's output, so the old fold was not output-preserving (the report measured 5.8e-2 / 8.2e-2 relative logit change).mamba.in_projis now marked:nosrctoo, because it feeds a conv/SSM/attention path that is not positively homogeneous — the old tree only avoided that fold through a width mismatch, which is not a guarantee.Verification
New
tests/test_hymba_awq_groups_4891.py(8 tests), using a syntheticHymbaDecoderLayer-shaped module because the real model needs remote code withmamba_ssm/causal_conv1d/flash_attn:pre_moe_layernormand nopost_attention_layernorm;in_proj:0:nosrcpresent;input_layernorm → expertsorin_proj → out_projfold;< 1e-5;_sanitize_kwargspasses everything to a**kwargsforward and still filters an explicit signature.Red on parent (
git checkout origin/main -- gptqmodel/models/definitions/hymba.py gptqmodel/looper/awq_processor.py, then restored): 5 failed, 3 passed — includingtest_folding_a_scale_is_output_preserving[0], i.e. the oldinput_layernorm → [in_proj, gate, up]fold does not preserve the layer output.Green after merging current
main: 8 passed. Neighbouring suites —tests/test_awq_scale_folding.py tests/test_awq_scale_search_safety.py tests/module_tree/test_awq_relationships.py tests/test_hymba_awq_groups_4891.py→ 114 passed;tests/test_awq_conv1d_gpt2_4887.pyandtests/test_awq_scale_search_memory.py/test_awq_deepseek_v4_rotary_4695.pypass too.ruff check gptqmodel testsclean.One note:
tests/test_awq_weight_mean.py::test_awq_weight_mean_matches_legacy_impl_2_cpu_gs128asserts a wall-clock ratio and failed once under a parallel suite run (59.2 ms vs 25.7 ms); it passes in isolation and does not touch this change.Residual risk
in_proj → relu → out_proj. The claim being tested is the fold topology (which module reads which norm, and homogeneity), which the realforwardshares. A real-model AWQ run onnvidia/Hymba-1.5B-Basewas not possible here (nomamba_ssm/flash_attn)._sanitize_kwargsnow forwards unknown keys to any**kwargsforward. That is what**kwargsmeans, but a remote-code forward that re-dispatches**kwargsto a stricter child would now see the extra keys; the previous behaviour silently broke such a forward instead.intermediate_size == 0) have neitherpre_moe_layernormnormoe; the tree tolerates absent entries exactly as it did for the previously declared (also absent) norm.