Skip to content

fix(awq): preserve output for gated/lerped scale folds (#4175) - #4249

Merged
Qubitium merged 2 commits into
mainfrom
fix/issue-4175-awq-tags
Nov 16, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/issue-4175-awq-tags

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #4175

Root cause

AWQProcessor._validate_scale_group checks widths, live bindings, replay
containment and execution, but it cannot see whether the selected producer's
output is the tensor a consumer actually reads. Each definition below emitted a
group that passed validation and changed the full-precision layer output when
the fold was applied without quantization.

Model file:line Incorrect relationship Neutral-fold diff before
Intern-S2-Preview gptqmodel/models/definitions/intern_s2_preview.py:65-66 DeltaNet in_proj_qkv/in_proj_z read the same input norm, but the copied tree dropped :in=x; only in_proj_qkv folded and in_proj_z then folded into in_proj_qkv. 5.168e-04 (issue: 9.7e-3)
MiniCPM-V-4.6 gptqmodel/models/definitions/minicpmv_4_6.py:50-51 Same dropped :in=x tags on the Qwen3.5 linear-attention tree. 2.073e-02
MiniCPM-V gptqmodel/models/definitions/minicpmv.py:44-54 Sequential q:0,k:1,v:2,o:3 folded the norm into q, then q into k; the ungrouped MLP put down_proj in the gate/up subset. 1.720e-01
MiniCPM-o gptqmodel/models/definitions/minicpm_o.py:221-230 Same sequential attention/MLP stages. 1.720e-01
DiffusionGemma gptqmodel/models/definitions/diffusion_gemma.py:206,223 v_proj's scale-free v_norm hides it from o_proj; router.proj was compensated as a consumer of pre_feedforward_layernorm_2 although it reads the raw residual through its own scale-free norm, flipping selected experts. 2.285e-01
Ricursive (Ripple) gptqmodel/models/definitions/ricursive.py:44,61-62 g_proj is a sigmoid gate on the attention output but was o_proj's fold source; v_proj reads lerp(value_residual, normed) but was folded with the input norm. 7.611e-03
Qwen4-Exp (qwen4_exp, qwen4_exp_text) gptqmodel/models/definitions/qwen4_exp.py:57,66,71 No norms declared, so attention o_proj/linear_attn.out_proj became the MLP input source across the gated hyper-connection mix; routed experts sharing that input were uncompensated. 8.367e-04

Fix

All repairs use the existing tree tags (no new DSL, no environment switches):

  • Intern-S2-Preview / MiniCPM-V-4.6: restore Qwen3.5's :in=x tags on
    Q/K/V and in_proj_qkv/in_proj_z (plus gate/up on Intern-S2's MoE). One
    group per input norm; in_proj_b/in_proj_a are compensated consumers.
  • MiniCPM-V / MiniCPM-o: Q/K/V share stage 0 with :in=x, o_proj:1;
    gate/up share :in=x, down_proj:1.
  • DiffusionGemma: v_proj:0:in=x:nosrc; the router is declared after the
    expert block so it is not collected into pre_feedforward_layernorm_2's
    _scale_consumers (it never receives that scale).
  • Ricursive: g_proj:0:in=x:nosrc, v_proj in its own stage, and
    input_layernorm:!:norm:nosrc because a fold through the value-residual
    lerp cannot be undone by any single v_proj scale. Attention falls back to
    plain quantization; the MLP folds stay.
  • Qwen4-Exp: o_proj, in_proj_a and out_proj are :nosrc; the
    shared/routed experts fall back to plain quantization together.

docs/awq-scaling-groups.md gains an "Issue #4175" relationship table.

Regression test (the durable deliverable)

tests/module_tree/test_awq_fold_safety_4175.py builds a real tiny CPU layer
per definition (native Qwen3.5/Qwen3/Qwen4/DiffusionGemma classes, the pinned
Ripple custom code, and the pinned Intern-S2 reference code), asks the
definition for its groups, applies one non-unit non-uniform fold with no
quantization
, and asserts the full layer output is unchanged (<1e-5).

Measured max relative change after the fix: 2.7e-07 across all cases.

Fail before / pass after

Parent of this branch (60b420d58), test file copied in:

pytest -q tests/module_tree/test_awq_fold_safety_4175.py
7 failed in 4.75s
  input_layernorm -> ['linear_attn.in_proj_qkv'] 2.073e-02
  input_layernorm -> ['linear_attn.in_proj_qkv'] 5.168e-04
  input_layernorm -> ['self_attn.q_proj', 'k_proj', 'v_proj', 'g_proj'] 7.611e-03
  input_layernorm -> ['self_attn.q_proj'] 1.720e-01
  linear_attn.out_proj -> shared_expert.gate/up 8.367e-04
  self_attn.v_proj -> ['self_attn.o_proj'] 2.285e-01

Branch (merged with origin/main @ 60b420d58):

pytest -q tests/module_tree/test_awq_fold_safety_4175.py
7 passed

Related definitions + pinned plan inventory:

pytest -q tests/module_tree/test_awq_fold_safety_4175.py \
  tests/module_tree/test_registered_module_plans.py \
  tests/test_ricursive_support.py tests/test_qwen4_exp_support.py \
  tests/module_tree/test_awq_relationships.py
553 passed, 3 failed

The 3 failures are pre-existing granitemoe_swa failures
(block_sparse_moe.experts.gate_up_proj weight-owner resolution) that fail
identically on 60b420d58 without this branch.

Skill CPU baseline (all listed files) + the new test:

pytest -q 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 \
  tests/module_tree/test_awq_fold_safety_4175.py
569 passed, 3 failed   # same pre-existing granite failures

tests/test_diffusion_gemma_support.py passes except
test_diffusion_gemma_post_quantize_syncs_encoder_layer, which fails
identically on 60b420d58 (AttributeError: ... has no attribute 'quantize_config', an incomplete test wrapper unrelated to this change).

Lint:

ruff check gptqmodel docs/eora tests setup.py
All checks passed!

Hardware: CPU only (tiny real CPU layers). No GPU was used.

Deferred (not silently dropped)

  • gptqmodel/models/definitions/bailing_moe.py:47 — shared experts have no
    group ids, so down_proj is calibrated in the gate/up subset on unquantized
    activations. This file is owned by the [BUG][model] Several model definitions silently leave layers unquantized against transformers 5.22 #4174 worker this round and was
    not edited here. It remains deferred to that change.
  • Quality loss, no corruption: Qwen3.5 dense and Olmo-Hybrid
    linear-attention layers still get no input-norm scaling. The empty
    self_attn subset clears the pending norm and the linear_attn container
    becomes the (non-foldable) source. The owning definition files
    (qwen3_5*.py, olmo_hybrid.py) are outside this task's file ownership, so
    this was not changed; it needs a base-builder or definition-owner change.
  • Latent: Laguna/Spark2.5 g_proj would become o_proj's source in a
    full-gating config; shipped configs reject it today. Out of scope.

CI

ruff-check passes on the PR head. The new test is wired into the AWQ CPU
unit suite in .github/workflows/awq_cpu.yml; because pull_request runs use
the base branch's workflow definition, that line takes effect after merge
(pre-merge, the run below still executes the old command list).

Latest AWQ CPU run on the PR head: AWQ CPU (unit) 808 passed, 68 skipped,
1 failed, and AWQ CPU (moe) passed. The single unit failure is
tests/test_awq_scaling_groups.py::test_scaling_groups_preserve_decoder_layer_output[nemotron_h]
(2.822e-1) and AWQ CPU (dense) fails
tests/test_awq_hf_cpu.py::test_real_checkpoint_awq_cpu_roundtrip[dense]
(relative RMSE 0.234 > 0.2). Both reproduce identically on the merge base
60b420d58 in a clean worktree without this branch; nemotron_h.py is owned by
the #4174 worker.

Residual risk

  • Ricursive and Qwen4-Exp deliberately lose AWQ scaling on the affected
    branches (plain quantization) to stay output-preserving; this trades some
    quantization quality for correctness.
  • The Intern-S2 test downloads pinned reference code; it skips with a precise
    reason when that code is unavailable, so that variant is unverified in an
    offline CI run.
  • The DiffusionGemma router is declared after the expert block. That is a
    data-flow declaration (the router is a parallel residual consumer), not
    literal execution order; the subset ordering tests still pass.

Restore the Qwen3.5 :in=x tags on the Intern-S2-Preview and
MiniCPM-V-4.6 linear-attention trees, regroup MiniCPM-V/o attention
and MLP stages, mark DiffusionGemma v_proj as nosrc and keep its
router out of the pre-feedforward norm consumers, mark Ricursive's
gated/lerped projections and input norm as non-sources, and mark the
Qwen4-Exp attention outputs as non-sources across the hyper-connection
mix. Each case passed _validate_scale_group but changed the
full-precision layer output.

Add tests/module_tree/test_awq_fold_safety_4175.py, which applies the
emitted fold with no quantization to real tiny CPU layers and asserts
the full output is unchanged.
@Qubitium
Qubitium merged commit 5c39759 into main Nov 16, 2026
7 of 9 checks passed
@Qubitium
Qubitium deleted the fix/issue-4175-awq-tags branch November 16, 2026 06:04
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.

[BUG][model][AWQ] Unsafe AWQ scale folds in several definitions change the full-precision output

1 participant