Skip to content

fix(awq): fold dots3_note input_layernorm into every projection that reads it - #6453

Merged
Qubitium merged 1 commit into
mainfrom
fix/dots3-note-awq-norm-consumers
Nov 30, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/dots3-note-awq-norm-consumers

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

In dots3_note's AWQ input_layernorm fold, 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 the input_layernorm output in these modules:

  • self_attn.q_a_proj and self_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 layer
  • self_attn.indexer.wk (l.253) and self_attn.indexer.weights_proj (l.268), on indexed_attention layers only. Dots3NoteTextIndexer.forward gets the same hidden_states.

The definition put only q_proj/q_a_proj/kv_a_proj_with_mqa in stage 0. g_proj, indexer.wk and indexer.weights_proj were in stage 1. The generic planner builds the input_layernorm group 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 vendored tests/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.wk and indexer.weights_proj move from stage 1 to stage 0. deepseek_v32 already declares its indexer this way. indexer.wq_b stays in stage 1 because it reads q_resid, like q_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:
    • hooks the native forward and finds every linear whose input equals the input_layernorm output, using torch.equal;
    • asserts that set equals the planner's input_layernorm group (targets + consumers);
    • runs 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, with python -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 matches canonical_awq_folds.
  • Out of scope: a separate bug in deepseek_v4, listed in Notes.

Tests

  • Unit tests have been executed and passed, or the reason they are not applicable is documented.
  • I added a new simple/fast unit test for this change, or documented why that is not applicable.

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.

# New regression test, origin/main 8e8864da8 (test file copied in): FAILS for the intended reason
python -P -m pytest -q tests/module_tree/test_dots3_note_awq_relationships.py
# E AssertionError: ...: input_layernorm -> ['self_attn.q_a_proj', 'self_attn.kv_a_proj_with_mqa'] changed the layer output by 6.602e-02
# E AssertionError: ...: input_layernorm -> ['self_attn.q_a_proj', 'self_attn.kv_a_proj_with_mqa'] changed the layer output by 4.014e-03
# 2 failed

# Branch
python -P -m pytest -q tests/module_tree/test_dots3_note_awq_relationships.py
# test_awq_input_layernorm_fold_covers_every_native_reader[indexed_attention] PASSED
# test_awq_input_layernorm_fold_covers_every_native_reader[sliding_attention] PASSED

# Fold inventory + registered plans (+ new test), on origin/main 452550d29 (after #6452)
python -P -m pytest -q -n 16 tests/module_tree/test_dots3_note_awq_relationships.py \
  tests/module_tree/test_awq_fold_inventory.py tests/module_tree/test_registered_module_plans.py
# origin/main (new test copied in): 2 failed (the new test), 928 passed
# branch:                           930 passed

# AWQ onboarding baseline + module_tree + port/registry tests
python -P -m pytest -q -n 32 tests/module_tree 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/test_native_definition_loading_0.py \
  tests/test_native_auto_registry.py tests/test_model_port_policy.py -rfs
# origin/main 452550d29: 4333 passed, 813 skipped, 2 xfailed
# branch:                4335 passed, 813 skipped, 2 xfailed  (+2 new tests)
# The 813 skips are the same on both revisions: CUDA/ROCm hardware (Marlin/fusion/Q4NX), the opt-in meta_coverage marker,
# offline-unconstructible registry leaf configs, one network-only release asset, and the minicpm-o extra.

bash format/check.sh   # ruff 0.14.2: All checks passed!

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:

Layer origin/main branch
0 indexed_attention 6.865e-02 1.848e-07
1 sliding_attention 1.729e-03 1.452e-07

Native-reader check (nonuniform linspace(0.55, 1.45) scale applied with apply_scale, fixture config including its sparse MLP layer):

Layer main: readers not folded main rel branch rel
0 indexed g_proj, indexer.wk, indexer.weights_proj 1.07e-01 1.91e-07
1 sliding g_proj 4.33e-03 1.47e-07

Fold-plan diff across every MODEL_MAP definition: I generated awq_fold_inventory.generate fresh on origin/main 8e8864d and on the branch for all 210 types. #6452 changed only the fixture, not the planner. Only dots3_note differs.

  • Each layer's input_layernorm group gains self_attn.g_proj, plus self_attn.indexer.wk and self_attn.indexer.weights_proj on indexed layers. Status is ok on every layer.
  • The planner also emits Linear->Linear chain groups between stages. These keep status drop:width, so nothing is folded through them:
    • indexed layers: weights_proj -> [q_b_proj, wq_b] and wq_b -> o_proj;
    • sliding layers: the kv_a_proj_with_mqa -> [q_b_proj, kv_b_proj] group is no longer emitted.
  • On the default (real) config, wq_b output is 64128 = 8192 and o_proj input 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_note GPTQConfig(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

  • Every new MODEL_MAP entry has an explicit registry plan case. (not applicable: no new entry)
  • A new model-specific module-plan unit test builds the real model class and verifies declared paths, checkpoint weight ownership/tags, roles, and applicable consumers, including layout variants and method overrides. (test_dots3_note_awq_relationships.py builds the real Dots3NoteForCausalLM and checks the norm consumers on both attention layouts. The registered plan case is updated.)
  • Runtime-created tensors are distinguished from checkpoint-owned weights. (not applicable: no ownership change)
  • Fusion eligibility is recorded in fusable_models.json... (not applicable: unchanged, dots3_note stays unqualified)
  • Fusion modules/parents resolve through model.module_plan()... (not applicable)
  • Composed fusion configs... (not applicable)
  • New fusion qualifications... (not applicable)
  • Registry and model-specific tests passed; any dependency skips and their precise coverage limits are listed below.

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]: passed
  • tests/module_tree/test_dots3_note_awq_relationships.py::test_awq_input_layernorm_fold_covers_every_native_reader[sliding_attention]: passed
  • tests/module_tree/test_registered_module_plans.py: passed
  • tests/module_tree/test_awq_fold_inventory.py::test_current_planner_matches_inventory[dots3_note/default] and ::test_canonical_folds_match_inventory[dots3_note/default]: passed

AWQ onboarding safety

  • Native forward evidence identifies each source, all quantized and non-quantized consumers, intervening operations, and complete replay scope. (See the reader list in Summary. The test derives readers from a hooked native forward, not from the tree. The replay boundary for the group is self_attn, which runs g_proj and the indexer.)
  • Real-model neutral-fold and candidate-search tests cover applicable layouts/configs, shared branches/routers, and nontrivial scales. (Both attention layouts, nonuniform scales, full-model logits. Fold-only through the real _quantize_layer with identity quantization.)
  • Native context/chunk parity, failure rollback, and configured fallback/error behavior are tested where applicable. (not applicable: no replay/search/fallback code changed)
  • Each variant is AWQ-scaling qualified, tested plain-quantization-only, or explicitly unsupported/unverified. Status of each variant:
    • indexed_attention: the input_layernorm fold is qualified (all 5 readers).
    • sliding_attention: the input_layernorm fold is qualified (3 readers).
    • MLA stage-1 (q_b_proj/kv_b_proj/wq_b) and o_proj: no fold source, so plain quantization, as on main.
    • MLP/MoE: unchanged.

Logic Flow Documentation

  • This change does not alter a major logic flow, or the required diagrams and docs page are included below.

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:

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching and used the project's normal extension points where possible.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions.

Kernel Accuracy Requirements

  • Kernel accuracy vs Torch oracle. (not applicable: no kernel change)
  • Fusion support changes... (not applicable)
  • Kernel inventory/device report... (not applicable)

Notes

  • I checked the other indexer definitions for the same omission with a hooked native forward on their tiny fixtures:
    • deepseek_v32: correct; fold-only 3.0e-7 / 1.9e-7, indexer.weights_proj is a compensated consumer.
    • minimax_m3_vl: correct, including the minimax_m3_sparse indexer layer; 2.7e-7 / 1.8e-7.
    • glm_moe_dsa and axk2: no input-norm fold (nosrc).
    • glm5_next (DSA attention layers) and qwen4_exp: no input-norm fold on the indexer layers.
    • None of them needs this fix.
  • Separate bug found (not fixed here), deepseek_v4: the generic planner's width-matched :! sibling heuristic adds self_attn.o_a_proj as an input_layernorm scale consumer. o_a_proj is the grouped output projection: it reads the attention output, not the normed input. It is selected because its per-group input width num_heads*head_dim/o_groups equals hidden_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 when o_a_proj is left out.
  • The tiny AWQ e2e did not reload the quantized checkpoint. Reloading a saved dots3_note checkpoint hits a separate tokenizer-config issue, already tracked from fix(models): split dots3_note routed experts through the loader's Defuser pass #6448.

🤖 Generated with Claude Code

…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]>
@Qubitium
Qubitium marked this pull request as ready for review November 30, 2026 00:19
@Qubitium
Qubitium merged commit 1c51b32 into main Nov 30, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/dots3-note-awq-norm-consumers branch November 30, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant