Repository navigation
fix(awq): fold dots3_note input_layernorm into every projection that reads it - #6453
Merged
Merged
Conversation
…reads it Dots 3 Note attention reads the input_layernorm output in q_a_proj, kv_a_proj_with_mqa, the per-head sigmoid gate g_proj and, on indexed_attention layers, the DSA indexer's wk and weights_proj. The definition declared only q_proj/q_a_proj/kv_a_proj_with_mqa in stage 0 and put g_proj, indexer.wk and indexer.weights_proj in stage 1, so the generic AWQ planner built the input_layernorm group from stage 0 alone: the norm weight was divided by the scale but g_proj/wk/weights_proj were never multiplied by it. Fold-only (identity quantization) logits on a tiny random model from the vendored config changed by 6.9e-2 on the indexed layer and 1.7e-3 on the sliding layer. Declare those three readers in stage 0, as deepseek_v32 already does for its indexer, so they join the input_layernorm group. Fold-only change drops to 1.8e-7 / 1.5e-7. GPTQ inputs are unchanged (all three read the attention input), and tiny dots3_note GPTQ quantizes (dense and MoE) are bit-identical to main. Refresh the registered module plan and the dots3_note entry of the AWQ fold-plan inventory (regenerated with --types dots3_note); the effective plan still matches canonical_awq_folds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
13 of 23 tasks
Qubitium
marked this pull request as ready for review
November 30, 2026 00:19
This was referenced Nov 30, 2026
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
In dots3_note's AWQ
input_layernormfold, some modules that read the normed hidden states never got the scale applied to their input columns.Dots 3 Note attention (
gptqmodel/models/ports/native/dots3_note/modeling_dots3_note.py) reads theinput_layernormoutput in these modules:self_attn.q_a_projandself_attn.kv_a_proj_with_mqa(Dots3NoteTextAttention.forward, l.538 / l.544)self_attn.g_proj, the per-head sigmoid gate (l.604), on every layerself_attn.indexer.wk(l.253) andself_attn.indexer.weights_proj(l.268), onindexed_attentionlayers only.Dots3NoteTextIndexer.forwardgets the samehidden_states.The definition put only
q_proj/q_a_proj/kv_a_proj_with_mqain stage 0.g_proj,indexer.wkandindexer.weights_projwere in stage 1. The generic planner builds theinput_layernormgroup from stage 0 only. So AWQ divided the norm weight by the scale but never multiplied the three stage-1 readers by it.Fold-only result (identity quantization, real
AWQProcessor._quantize_layer) on a tiny random model built from the vendoredtests/fixtures/ports/native_parity/dots3_note.json: the logits change by 6.9e-2 on the indexed layer and 1.7e-3 on the sliding layer.What Changed
gptqmodel/models/definitions/dots3_note.py:g_proj,indexer.wkandindexer.weights_projmove from stage 1 to stage 0.deepseek_v32already declares its indexer this way.indexer.wq_bstays in stage 1 because it readsq_resid, likeq_b_proj. Quantization flags are unchanged: all three modules are still quantized.tests/module_tree/test_dots3_note_awq_relationships.py(new): for the indexed layer and the sliding layer of a real tiny model:input_layernormoutput, usingtorch.equal;input_layernormgroup (targets + consumers);assert_awq_folds_neutral.tests/module_tree/fixtures/registered_module_plans.json: the dots3_note block split is updated.tests/module_tree/fixtures/awq_fold_plans.json: only the dots3_note entry is regenerated, withpython -P tests/module_tree/awq_fold_inventory.py --write --types dots3_note, on top of test(awq): refresh the fold inventory after the mimo_v2/diffusion_gemma/dots3_note/glm5_next fixes #6452.test_canonical_folds_match_inventory[dots3_note/default]still passes: the fixed plan matchescanonical_awq_folds.deepseek_v4, listed in Notes.Tests
Environment: CPU only,
/root/venv/bin/python(Python 3.14, torch 2.15.0, transformers 5.23.0),python -P,PYTHONPATH=<tree>,HF_HUB_OFFLINE=1.Measured Impact
Fold-only (identity quantization, no clip) relative change of the full-model logits. Same tiny random model and inputs on both revisions. Per layer, with the model restored between layers:
indexed_attentionsliding_attentionNative-reader check (nonuniform
linspace(0.55, 1.45)scale applied withapply_scale, fixture config including its sparse MLP layer):g_proj,indexer.wk,indexer.weights_projg_projFold-plan diff across every
MODEL_MAPdefinition: I generatedawq_fold_inventory.generatefresh on origin/main 8e8864d and on the branch for all 210 types. #6452 changed only the fixture, not the planner. Onlydots3_notediffers.input_layernormgroup gainsself_attn.g_proj, plusself_attn.indexer.wkandself_attn.indexer.weights_projon indexed layers. Status isokon every layer.drop:width, so nothing is folded through them:weights_proj -> [q_b_proj, wq_b]andwq_b -> o_proj;kv_a_proj_with_mqa -> [q_b_proj, kv_b_proj]group is no longer emitted.wq_boutput is 64128 = 8192 ando_projinput is 128128 = 16384, so the width drop applies.GPTQ calibration ordering: the three modules read the attention input
hidden_states, which does not depend on any stage-0 weight. Moving them to stage 0 does not change their captured inputs. A tiny dots3_noteGPTQConfig(bits=4, group_size=16)CPU quantize + save is bit-identical to origin/main:AWQ end-to-end CPU quantize + save succeeds on both revisions for both tiny models. Tensors differ as expected:
input_layernorm,q_a_proj,kv_a_proj_with_mqa,g_proj,indexer.wk/weights_proj, and everything downstream that is calibrated on those outputs.Model Support / Module Plan
MODEL_MAPentry has an explicit registry plan case. (not applicable: no new entry)test_dots3_note_awq_relationships.pybuilds the realDots3NoteForCausalLMand checks the norm consumers on both attention layouts. The registered plan case is updated.)fusable_models.json... (not applicable: unchanged, dots3_note stays unqualified)model.module_plan()... (not applicable)Model test node IDs and results:
tests/module_tree/test_dots3_note_awq_relationships.py::test_awq_input_layernorm_fold_covers_every_native_reader[indexed_attention]: passedtests/module_tree/test_dots3_note_awq_relationships.py::test_awq_input_layernorm_fold_covers_every_native_reader[sliding_attention]: passedtests/module_tree/test_registered_module_plans.py: passedtests/module_tree/test_awq_fold_inventory.py::test_current_planner_matches_inventory[dots3_note/default]and::test_canonical_folds_match_inventory[dots3_note/default]: passedAWQ onboarding safety
self_attn, which runs g_proj and the indexer.)_quantize_layerwith identity quantization.)indexed_attention: the input_layernorm fold is qualified (all 5 readers).sliding_attention: the input_layernorm fold is qualified (3 readers).q_b_proj/kv_b_proj/wq_b) ando_proj: no fold source, so plain quantization, as on main.Logic Flow Documentation
Diagram summary: not applicable. This is a definition declaration change; the planner and processor flow are unchanged.
Review Requirements
I or an AI agent (such as Codex or Claude) have:
Kernel Accuracy Requirements
Notes
deepseek_v32: correct; fold-only 3.0e-7 / 1.9e-7,indexer.weights_projis a compensated consumer.minimax_m3_vl: correct, including theminimax_m3_sparseindexer layer; 2.7e-7 / 1.8e-7.glm_moe_dsaandaxk2: no input-norm fold (nosrc).glm5_next(DSA attention layers) andqwen4_exp: no input-norm fold on the indexer layers.deepseek_v4: the generic planner's width-matched:!sibling heuristic addsself_attn.o_a_projas aninput_layernormscale consumer.o_a_projis the grouped output projection: it reads the attention output, not the normed input. It is selected because its per-group input widthnum_heads*head_dim/o_groupsequalshidden_size. That holds on the default V4-Flash config (64*512/8 = 4096) and on the tiny fixture. Fold-only logits change on the fixture is 1.5e-1 / 1.1e-1, and 2.8e-7 / 2.0e-7 wheno_a_projis left out.🤖 Generated with Claude Code