Repository navigation
fix(awq): preserve output for gated/lerped scale folds (#4175) - #4249
Merged
Merged
Conversation
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.
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.
Fixes #4175
Root cause
AWQProcessor._validate_scale_groupchecks widths, live bindings, replaycontainment 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.
file:linegptqmodel/models/definitions/intern_s2_preview.py:65-66in_proj_qkv/in_proj_zread the same input norm, but the copied tree dropped:in=x; onlyin_proj_qkvfolded andin_proj_zthen folded intoin_proj_qkv.gptqmodel/models/definitions/minicpmv_4_6.py:50-51:in=xtags on the Qwen3.5 linear-attention tree.gptqmodel/models/definitions/minicpmv.py:44-54q:0,k:1,v:2,o:3folded the norm into q, then q into k; the ungrouped MLP putdown_projin the gate/up subset.gptqmodel/models/definitions/minicpm_o.py:221-230gptqmodel/models/definitions/diffusion_gemma.py:206,223v_proj's scale-freev_normhides it fromo_proj;router.projwas compensated as a consumer ofpre_feedforward_layernorm_2although it reads the raw residual through its own scale-free norm, flipping selected experts.gptqmodel/models/definitions/ricursive.py:44,61-62g_projis a sigmoid gate on the attention output but waso_proj's fold source;v_projreadslerp(value_residual, normed)but was folded with the input norm.qwen4_exp,qwen4_exp_text)gptqmodel/models/definitions/qwen4_exp.py:57,66,71o_proj/linear_attn.out_projbecame the MLP input source across the gated hyper-connection mix; routed experts sharing that input were uncompensated.Fix
All repairs use the existing tree tags (no new DSL, no environment switches):
:in=xtags onQ/K/V and
in_proj_qkv/in_proj_z(plus gate/up on Intern-S2's MoE). Onegroup per input norm;
in_proj_b/in_proj_aare compensated consumers.:in=x,o_proj:1;gate/up share
:in=x,down_proj:1.v_proj:0:in=x:nosrc; the router is declared after theexpert block so it is not collected into
pre_feedforward_layernorm_2's_scale_consumers(it never receives that scale).g_proj:0:in=x:nosrc,v_projin its own stage, andinput_layernorm:!:norm:nosrcbecause a fold through the value-residuallerp cannot be undone by any single
v_projscale. Attention falls back toplain quantization; the MLP folds stay.
o_proj,in_proj_aandout_projare:nosrc; theshared/routed experts fall back to plain quantization together.
docs/awq-scaling-groups.mdgains an "Issue #4175" relationship table.Regression test (the durable deliverable)
tests/module_tree/test_awq_fold_safety_4175.pybuilds a real tiny CPU layerper 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:Branch (merged with
origin/main@60b420d58):Related definitions + pinned plan inventory:
The 3 failures are pre-existing
granitemoe_swafailures(
block_sparse_moe.experts.gate_up_projweight-owner resolution) that failidentically on
60b420d58without this branch.Skill CPU baseline (all listed files) + the new test:
tests/test_diffusion_gemma_support.pypasses excepttest_diffusion_gemma_post_quantize_syncs_encoder_layer, which failsidentically on
60b420d58(AttributeError: ... has no attribute 'quantize_config', an incomplete test wrapper unrelated to this change).Lint:
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 nogroup ids, so
down_projis calibrated in the gate/up subset on unquantizedactivations. 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.
linear-attention layers still get no input-norm scaling. The empty
self_attnsubset clears the pending norm and thelinear_attncontainerbecomes the (non-foldable) source. The owning definition files
(
qwen3_5*.py,olmo_hybrid.py) are outside this task's file ownership, sothis was not changed; it needs a base-builder or definition-owner change.
g_projwould becomeo_proj's source in afull-gating config; shipped configs reject it today. Out of scope.
CI
ruff-checkpasses on the PR head. The new test is wired into the AWQ CPUunitsuite in.github/workflows/awq_cpu.yml; becausepull_requestruns usethe 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 istests/test_awq_scaling_groups.py::test_scaling_groups_preserve_decoder_layer_output[nemotron_h](2.822e-1) and
AWQ CPU (dense)failstests/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
60b420d58in a clean worktree without this branch;nemotron_h.pyis owned bythe #4174 worker.
Residual risk
branches (plain quantization) to stay output-preserving; this trades some
quantization quality for correctness.
reason when that code is unavailable, so that variant is unverified in an
offline CI run.
data-flow declaration (the router is a parallel residual consumer), not
literal execution order; the subset ordering tests still pass.