Repository navigation
fix(awq): score Hymba's mixer input instead of replaying the KV-reuse block (#5098) - #5172
Merged
Merged
Conversation
… block (#5098) A Hymba reuse_kv layer projects no K/V of its own: HymbaBlock reads the producing layer's kv_last_layer, which ForwardExecutor threads between layers and the per-linear activation capture never records. The input_layernorm -> mamba.in_proj group replayed the whole HymbaBlock, so every real checkpoint aborted at the first KV-reuse consumer with a bare AssertionError, which the configured fallback could not catch. Anchor that group's module2inspect on the mamba.in_proj Linear: it is the single member of the group and its reconstruction error is the objective. Keep the fold itself unchanged. Also convert an AssertionError raised by a replayed module into _AWQScaleGroupError so an unscorable replay takes the configured plain quantization fallback instead of aborting quantize(). Processor-side assertions and other exceptions still propagate.
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.
Summary
Fixes #5098.
#4891/#5019made Hymba's AWQ replay receive the captured kwargs, but it wasonly verified on a synthetic fixture and on a slice with no KV reuse. On a real
nvidia/Hymba-1.5B-Basecheckpoint, AWQ still aborts at layer 2 — the firstKV-reuse consumer — with
AssertionError: assert kv_last_layer is not None.Root cause. Every Hymba checkpoint shares K/V across layers
(
kv_reuse_group; 15 consumer layers of 32). A consumer'sHymbaBlockprojectsno K/V of its own: it reads the producing layer's
kv_last_layer, whichForwardExecutorinjects for the real layer forward(
looper/forward_executor.py, enabled byHymbaQModel.write_shared_kv_cache).That value is token-aligned (
[b, heads, seq, d]) and is never part of theper-linear activation capture, so it cannot be reconstructed from the retained
token rows. The
input_layernorm -> mamba.in_projgroup declaredmambaas itsinspection module, so the scale search replayed
HymbaBlock(x, **captured_kwargs)without it.
The failure was a bare
AssertionErrorraised inside the replayed module, whichthe existing geometry-error path (
_is_replay_geometry_error,RuntimeErroronly) does not convert, so
AWQConfig.fallbacknever ran andquantize()died.Confirmation the bug is real and still on
main: reproduced on the realcheckpoint at the current base
8a2fbeb2e, with the issue's exact traceback(
modeling_hymba.py,cuda_kernels_forward:assert kv_last_layer is not None)at layer 2, after
layer 2 sanitized 3 scaling groups.git log origin/maincontains nothing that touches this path, so
maindoes not fix it.What Changed
gptqmodel/models/definitions/hymba.py:HymbaQModel.awq_get_modules_for_scalingre-anchors the
input_layernorm -> mamba.in_projgroup'smodule2inspectonto the
mamba.in_projnn.Linear. That group has exactly one member andin_projis the norm's only consumer, so the projection's own reconstructionerror is precisely the group objective; the mixer's cross-layer K/V and packed
causal mask are not needed to rank the scale. The fold is unchanged: the norm
is still divided and
in_proj's input rows still receive the scale. There-anchor is skipped when the group has multiple members, the norm has
declared
_scale_consumers(the fold would leave the boundary), or the memberis not an
nn.Linear; those cases keep the mixed replay so the existingvalidation decides.
gptqmodel/looper/awq_processor.py: newAWQProcessor._invoke_replay_module,used by both the unchunked and chunked replay branches of
_iter_prepared_forward_outputs. It converts anAssertionErrorraised by thereplayed module into
_AWQScaleGroupError, so an unscorable replay takes theconfigured plain-quantization fallback (or raises when
fallback=None).Scope is deliberately narrow: the processor's own assertions and every
non-
AssertionErrorexception still propagate; there is no catch-all.docs/awq-scaling-groups.md: new "Module replay failures and the scale-groupfallback" and "
hymba: KV-reuse layers" mechanism sections with the diagramsand the before/after table below.
tests/test_hymba_awq_4891.py: KV-reuse fixture (producer/consumer/reuselayers, a mixer that asserts on
kv_last_layer, and aHymbaModelforwardthat threads it) plus 3 regressions.
No public API, config, CLI or checkpoint-format change. No behaviour switch.
Tests
Red evidence (broken implementation)
tests/test_hymba_awq_4891.pycopied onto the pre-fix tree (04e745269), so itfails for the intended reason and not on import or collection:
Green
python -m pytest tests/test_hymba_awq_4891.py -q -rs # 10 passedFull AWQ CPU regression baseline from the AWQ skill, on this branch:
python -m pytest -q -rs \ tests/test_awq_scale_search_safety.py \ tests/test_awq_moe_router_scaling.py \ tests/test_awq_empty_groups.py \ tests/test_awq_position_kwargs.py \ tests/test_awq_scale_search_memory.py \ tests/test_bloom_awq_replay.py \ tests/module_tree/test_awq_relationships.py \ tests/module_tree/test_bloom_awq_relationships.py \ tests/module_tree/test_registered_module_plans.py \ tests/module_tree/test_definition_subset_ordering.py # 581 passedAdditional affected AWQ suites:
python -m pytest -q -rs \ tests/test_awq_mpt_replay_4872.py \ tests/test_awq_moe_bypass_4223.py \ tests/test_awq_rotary_device.py \ tests/test_awq_scaling_groups.py \ tests/test_awq_deepseek_v4_hash_moe_4880.py \ tests/test_awq_weight_mean.py # 262 passed, 5 skippedSkips (not counted as validation): 3×
mamba_ssmCUDA-only CPU fold cases; 2×model families whose
CausalLMis not constructible from the registry fixture(
opt350,muse_glimmer).Real checkpoint,
nvidia/Hymba-1.5B-Base(32 layers, BF16,sdpa)AssertionErrorat layer 2QUANTIZE OKsave()Verified out of scope, not claimed by this PR: generation on that checkpoint path
currently fails in the remote
HybridMambaAttentionDynamicCache.__init__(
KeyError: '0'onconfig.conv_dim). It reproduces identically on anon-quantized model loaded through GPTQModel, so it is unrelated to #5098 and is
tracked separately.
Lint
ruff check gptqmodel tests setup.py docs # All checks passedModel Support / Module Plan
Not a new model or alias.
HymbaQModel.module_treeis unchanged; the fix onlyre-points an existing group's inspection module, so declared paths, ownership,
tags and roles are untouched. Module-plan tests above still pass.
Model test node IDs and results:
tests/module_tree/test_registered_module_plans.pyand
tests/module_tree/test_awq_relationships.py— passed (within the 581).AWQ onboarding safety
input_layernorm→mamba.in_proj(single Linear member), and the mixeralso reads
kv_last_layerfrom the producing layer, which the capturenever records.
test_hymba_awq_fold_is_output_preservingstill pins that folding thesegroups reproduces the logits;
test_hymba_kv_reuse_group_search_completes_without_cross_layer_kvdrives the real
_search_best_scaleand asserts a finite per-channel scaleis produced for the projection.
test_hymba_mixer_replay_without_cross_layer_kv_uses_the_configured_fallbackre-introduces the broken boundary, asserts the group is quantized plainly,
that the layer is marked quantized, and that the fallback is logged; a
non-assertion failure or
fallback=Nonestill raises.projection boundary (verified on the real 32-layer checkpoint); multi-member
groups, norms with declared extra consumers and non-Linear members keep
the pre-existing block replay and validation.
AWQ evidence:
tests/test_hymba_awq_4891.py(10 nodes) plus the 581/262 suitesabove. Limits: generation, GPU kernels and non-Hymba KV-reuse families were not
qualified by this change.
Logic Flow Documentation
included here and in
docs/awq-scaling-groups.md(already linked fromREADME.md).awq_get_modules_for_scaling,_invoke_replay_module,_iter_prepared_forward_outputs,_AWQScaleGroupError,AWQConfig.fallback).file:line-level pointers below.Removed / replaced mechanism
awq_get_modules_for_scalingemittedinput_layernorm -> [mamba.in_proj]withmodule2inspect = HymbaBlock;_search_best_scale(gptqmodel/looper/awq_processor.py:3479ate75181df5) replayed the mixer through_iter_prepared_forward_outputs(:4816)module2inspect = mamba.in_proj; the search replays the Linear onlyAssertionErrorpropagated through_build_chunked_reference_outputs(:4039) and abortedquantize()_invoke_replay_moduleconverts it to_AWQScaleGroupError;_quantize_layer(:3045-3051) applies the configured fallback or raisesRuntimeErrorgeometry failures were convertible (_is_replay_geometry_error,:99)AssertionErrorfrom the module is convertible too; processor assertions and other exception types are notflowchart LR subgraph OLD["before: boundary is the mixer"] N1["input_layernorm"] --> M1["HymbaBlock.forward"] M1 --> R1["needs kv_last_layer<br/>and packed causal mask"] R1 --> X1["AssertionError<br/>aborts quantize()"] end subgraph NEW["after: boundary is the projection"] N2["input_layernorm"] --> P2["mamba.in_proj Linear"] P2 --> S2["score scale on the projection"] S2 --> F2["fold the norm; consumer stays quantized"] end style X1 fill:#f8d7da,stroke:#842029,stroke-width:2px style F2 fill:#d1e7dd,stroke:#0f5132,stroke-width:2pxNew flow
flowchart TD A["HymbaQModel.awq_get_modules_for_scaling"] --> B["super(): input_layernorm -> mamba.in_proj<br/>module2inspect = HymbaBlock"] B --> C{"single Linear member,<br/>inspect is mamba,<br/>no _scale_consumers?"} C -- "no" --> D["keep the mixed block replay<br/>existing validation decides"] C -- "yes" --> E["module2inspect = mamba.in_proj"] E --> F["AWQProcessor._search_best_scale"] D --> F F --> G["_iter_prepared_forward_outputs"] G --> H["_invoke_replay_module"] H --> I{"module forward raised?"} I -- "no" --> J["score candidates and fold"] I -- "AssertionError" --> K["_AWQScaleGroupError"] K --> L{"AWQConfig.fallback set?"} L -- "yes" --> M["plain quantization for the group<br/>layer stays quantized"] L -- "no" --> N["raise; no unsafe fold"] I -- "other exception" --> O["propagate; abort quantize()"] style N fill:#f8d7da,stroke:#842029,stroke-width:2px style O fill:#f8d7da,stroke:#842029,stroke-width:2px style M fill:#fff3cd,stroke:#997404,stroke-width:2px style J fill:#d1e7dd,stroke:#0f5132,stroke-width:2pxReview Requirements
the documented
awq_get_modules_for_scalinghook; the replay conversionsits beside the existing geometry-error conversion.
existing replay call sites, docs and tests.
Kernel Accuracy Requirements
Not applicable: no kernel, dispatch, fusion or packed-storage change. The AWQ
math and folding path is unchanged.
Notes
AssertionErrorconversion is generic (any replayed module can assert onmissing cross-block context) but deliberately not a catch-all: only
AssertionErrorfrom the module call itself becomes a scale-group error, andit still raises when
fallback=None.hymbaonly, so otherarchitectures keep their declared inspection boundaries.