Repository navigation
test(awq): cover fold-graph config features and fix Gemma KV/MoE folds - #6329
Conversation
Rebased audit/awq-neutrality onto origin/main abde192. gemma3n.py and gemma4_unified.py conflicted with main's newer _kv_shared_replay helpers. Kept main's awq_module_replay_inputs/retarget behavior and applied this PR's _retarget_attention_output_folds on top, so KV-shared consumers (main) and attention_k_eq_v layers (this PR) both keep o_proj out of the norm-fed fold. Dropped the PR's duplicate awq_get_modules_for_scaling definitions in gemma4.py in favour of one method per class; kept the PR's _gemma4_decoder_block refactor and tree fixes (postnorm, pre_feedforward_layernorm_2, router noconsumer). Tests: new test_awq_scaling_group_features.py 79 passed; base test_awq_scaling_groups.py 172 passed, 2 skipped on both main and the rebase. ruff clean.
fcb5338 to
68ad780
Compare
|
Rebased onto |
fb73a14 to
68ad780
Compare
- test_checkpoint_method_compatibility: the fake BaseQModel.quantize() receiver now needs `quantized` (#6347 reads it before checkpoint validation). - test_qwen2_family_compat: clear the explicit HF_CONVERSION_MAP_REVERSED (#6360) so the test still covers the transformers fallback path. - registered_module_plans.json: re-record the Gemma4/Gemma4Text plan after #6329 moved pre_feedforward_layernorm_2 ahead of the router block. Co-authored-by: agent <agent@local>
Summary
The per-family AWQ output-preservation invariant in
tests/test_awq_scaling_groups.pyonly built default configs. A fold can be non-neutral only when a config feature
changes the fold graph (which modules a layer owns, which tensor a consumer reads, or
which producer a fold source has). This adds
tests/test_awq_scaling_group_features.py: 70 feature-enabled tiny-fixture cases(79 tests total) that run the same fold-neutrality check with those features enabled,
and adds
gemma3n/gemma3n_text, which were absent from the invariant.The existing parametrizations and tolerances in
tests/test_awq_scaling_groups.pyareunchanged.
Failures found (pre-fix, CPU, tiny fixtures)
gemma4_textnum_kv_shared_layers=2)input_layernorm -> [self_attn.q_proj, self_attn.o_proj](layers 2/3)gemma4(composite)gemma4_unifiedgemma4_unified_textgemma4_textattention_k_eq_v=Trueinput_layernorm -> [self_attn.q_proj, self_attn.k_proj, self_attn.o_proj]gemma4_textenable_moe_block=Truepre_feedforward_layernorm -> [mlp.gate_proj, mlp.up_proj, experts.0..3.gate_proj, experts.0..3.up_proj]gemma4(composite)enable_moe_block=TrueThe KV-sharing failure is the one reported from PR #6317 (
1.839e-01on its fixture).gemma4_text+ KV sharing + MoE reproduced both defects together (1.363e-01 on theattention fold and 1.074e-01 on the expert fold).
During the MoE diagnosis, moving
pre_feedforward_layernorm_2before the expert blockalone reduced the error to 3.533e-02: the remaining error was the MoE router being
treated as a scale consumer of that norm. The router reads the pre-norm residual, not the
norm's output.
Fixes
v_proj(gptqmodel/models/definitions/gemma4.py,wired into
gemma4,gemma4_text,gemma4_unified,gemma4_unified_text,gemma3n,gemma3n_text):_retarget_attention_output_foldsremoveso_projfrom a norm-fedgroup when its attention parent owns no
v_proj(KV-shared consumer orattention_k_eq_v). It keepsq_proj(plusk_projwhen the layer owns one), andscores a single surviving projection on itself (Hymba [BUG] #5019 (fix of #4891) incomplete: Hymba AWQ still always crashes on the real checkpoint at layer 2 - HymbaBlock replay lacks kv_last_layer for KV-reuse layers (AssertionError, no fallback) #5098 precedent).
o_projstayson plain quantization because it has no foldable source of its own.
gemma4.py,base.py):pre_feedforward_layernorm_2is declared beforerouter/experts, so the routedgate/up group anchors on the norm that actually feeds it.
:noconsumer+awq_no_scale_consumer_modules()excludesrouter.projfrom_norm_scale_consumers; it reads the pre-norm residual._gemma4_decoder_block()sothe two definitions cannot drift.
Feature/coverage table (families in the base invariant +
gemma3n)layer_typesnum_dense_layersnum_expertsnum_shared_expertsuse_qk_normlayer_typeslayer_typesmlp_layer_typesnum_expertsnum_shared_expertsfirst_k_dense_replacen_routed_expertsn_shared_expertslayer_typesnew_decoder_architecturenum_ln_in_parallel_attnparallel_attnmamba_norm_before_gatedecoder_sparse_steplayer_typesmlp_only_layersnum_expertsshared_expert_intermediate_sizetext_config.layer_typestext_config.num_kv_shared_layerstext_config.attention_k_eq_vtext_config.enable_moe_blocktext_config.layer_typestext_config.num_expertstext_config.num_kv_shared_layerstext_config.use_double_wide_mlpattention_k_eq_venable_moe_blocklayer_typesnum_expertsnum_kv_shared_layersuse_double_wide_mlptext_config.attention_k_eq_vtext_config.layer_typestext_config.num_kv_shared_layerstext_config.use_double_wide_mlpadd_cross_attentionadd_cross_attentionattention_typesuse_parallel_residuallayer_typesnum_local_expertsdecoder_sparse_stepmlp_only_layersnum_expertsnum_shared_expertslayer_typesmlp_layer_typesnum_expertsshared_expert_intermediate_sizelayer_typesnum_dense_layersnum_expertslayer_typesuse_sandwich_normlayer_typesnum_local_expertsnum_local_expertsnum_local_expertslayers_block_typen_routed_expertsn_shared_expertslayer_typeslayer_typesnum_expertsdo_layer_norm_beforeqk_layernormdecoder_sparse_steplayer_typesmlp_only_layersnum_expertsshared_expert_intermediate_sizedecoder_sparse_stepmlp_only_layersnum_expertslayer_typesn_routed_expertsn_shared_expertsqk_layernormuse_parallel_residualThe enumeration script also inspected every other
MODEL_MAPdefinition: 110 modeltypes declare at least one curated graph-changing field. 74 of those are outside the
base invariant's 60-family buildable set (mostly VL/audio wrappers and ports without a
tiny
AutoModelForCausalLMfixture); the full machine table marks themno/unknownrather than silently omitting them.
Unbuildable feature variants (recorded, not dropped)
smollm3layer_types=[sliding, full]ValueError: missing per-layer head_dim(heterogeneous per-layer config rejects a global head_dim)nemotron_hhybrid_override_patternAttributeError: property 'hybrid_override_pattern' has no setter; the defaultME*-fixture already covers linear-attention, MoE, full-attention and dense-MLP blocksinternvl_chatlayer_types=[sliding, full]TypeError: 'NoneType' object cannot be interpreted as an integerin the vision-wrapper forwardgpt_bigcodeadd_cross_attention=TrueNotImplementedError: Cross-attention not implemented for MQAminimax_m2/gpt_ossnum_local_experts=1RuntimeError: selected index k out of range(top_k=2with one expert)falconnum_ln_in_parallel_attn=2AttributeError: 'FalconDecoderLayer' object has no attribute 'input_layernorm'; the definition tree declares the single-norm parallel layout.num_ln_in_parallel_attn=0is covered and neutral.gemma3n's default composite fixture is ~976M parameters (300M MobileNet vision tower);the test shrinks the text stack, vision tower (
mobilenetv3_small_100) and audio towerto ~1.6M parameters. It skips if
timmis unavailable.Verification (CPU only)
A full
tests/test_awq_*.pysweep was also attempted: 328 tests reported PASSED with noFAILED before the run was stopped at the slow CPU end-to-end quantization test
test_awq_gemv.py::test_awq_gemv_quantized_model_loads_and_generates(runtime, not afailure).
Follow-ups
None requiring a redesign. The unbuildable variants above are fixture/definition-layout
limitations, not observed non-neutral folds.
falcon's 2-norm parallel layout is notdeclared by the definition tree, so the invariant cannot exercise it; its 0-norm and
1-norm layouts are covered.