Repository navigation
Description
Found on main @ b225a43, RTX 4090 (sm_89, CUDA 13.2, torch 2.15, transformers 5.22.1). A/B against 12c1273c2 (before #4703) on the same card.
What is wrong
#4703 (fix for #4679) replaced the declared-last forward_hook_last with _mark_subset_member (gptqmodel/looper/stage_subset.py:1728-1743, set up at :1069-1072). There are two problems:
pending_members = set(subset_names)is built once per subset pass. It is shared by every calibration batch and is never refilled.- The member whose hook empties the set gets
module.forward_hook_last = True. The flag stays set for the rest of the pass and is only cleared in the cleanup at:1165.
From the next batch onward, the forward therefore raises StopForward as soon as that one member fires. That is correct only if the member is also the last one to fire in every later batch. In a MoE subset it is not:
- routing differs per batch;
- the expert loop runs experts in index order;
- the member that happened to complete the set (on OLMoE it ends up being
experts.0.gate_proj) fires first in later batches, so every other expert projection is cut off.
Every processor with subset_early_stop=True / replay_after_process=True is affected: GPTQ, AWQ, EXL3, ParoQuant and MACaQ.
Result: each routed expert (except the one that holds the flag) receives calibration from only one batch per layer. The tokens are silently dropped. GPTQ builds expert Hessians from about 1/N of the data. AWQ sees most experts as "starved" and sends them to the RTN fallback.
Evidence
OLMoE-1B-7B-0924 truncated to 4 layers, 16 C4 rows (t[:2500]), batch_size=1.
GPTQ: GPTQ.add_batch calls per expert module, summed over the 4 layers (names are layer-relative):
main @ b225a4383 12c1273c2 (before #4703)
experts.0.gate_proj 64 calls / 3359 tok 64 / 3442
experts.0.up_proj 4 calls / 137 tok 64 / 3442
experts.1.gate_proj 4 calls / 163 tok 64 / 4055
experts.10.gate_proj 4 calls / 444 tok 60 / 2506
median over all experts 4 calls (1 per layer) 64 calls (16 per layer)
AWQ: captured feature stats for layer 0 (_feature_stats at _should_fallback_group):
main: ('mlp.experts.0.gate_proj', 'token_rows', raw_tokens=826, batches=16)
('mlp.experts.0.up_proj', 'token_rows', raw_tokens=26, batches=1)
('mlp.experts.1.gate_proj', 'token_rows', raw_tokens=47, batches=1)
('mlp.experts.21.gate_proj','token_rows', raw_tokens=1, batches=1)
12c1273c2: ('mlp.experts.0.up_proj', 'token_rows', raw_tokens=826, batches=16)
('mlp.experts.1.gate_proj', 'token_rows', raw_tokens=753, batches=16)
On main, the default AWQConfig(bits=4, group_size=128) now logs the following for layers 0-3. At 12c1273c2, the same run has no fallback at all:
AWQProcessor: layer 3 keeps AWQ for 88 of 128 members of a scaling group; 40 starved member(s) are scale-folded then plain-quantized
AWQProcessor: layer 3 fallback quant 60 modules
(L0/L1/L2: 7 / 19 / 25 modules fall back.) Even experts.0.gate_proj and experts.0.up_proj disagree (826 vs 26 tokens) although they read the same input.
Quality (quantize, save, reload; mean token KL vs bf16 on 16x256 wikitext-2 tokens):
| main | 12c1273 | |
|---|---|---|
| AWQ, OLMoE-L4, n=16 | 0.07233 | 0.06972 |
| GPTQ, OLMoE-L4, n=16 | 0.0690 | 0.0709 |
On this 4-layer probe, the quality effect is small: AWQ is 3.7% worse, and GPTQ is within run-to-run noise. The mechanism is still a silent drop of about 15/16 of each expert's calibration data, together with spurious AWQ RTN fallback. The effect should grow with the expert count (Qwen3-MoE: 128 experts) and with skewed routing.
Dense subsets (q/k/v, gate/up) are not affected, because the member that completes the set in batch 0 is also the last to fire in later batches.
Minimal repro
import collections, torch
from gptqmodel import GPTQModel
from gptqmodel.quantization.config import GPTQConfig, CalibrationConfig
from gptqmodel.quantization import gptq as G
calls = collections.Counter()
orig = G.GPTQ.add_batch
def add_batch(self, inp, out, *a, **k):
calls[self.name] += 1
return orig(self, inp, out, *a, **k)
G.GPTQ.add_batch = add_batch
m = GPTQModel.load("OLMoE-1B-7B-0924 (num_hidden_layers=4)", GPTQConfig(bits=4, group_size=128), dtype=torch.bfloat16)
m.quantize(CalibrationConfig(dataset=c4_rows[:16], batch_size=1))
print({k: calls[k] for k in ["mlp.experts.0.gate_proj", "mlp.experts.0.up_proj", "mlp.experts.1.gate_proj"]})
# main: {'mlp.experts.0.gate_proj': 64, 'mlp.experts.0.up_proj': 4, 'mlp.experts.1.gate_proj': 4}
# 12c1273c2: {'mlp.experts.0.gate_proj': 64, 'mlp.experts.0.up_proj': 64, 'mlp.experts.1.gate_proj': 64}Suggested fix
Make the completion state per batch. At the start of each calibration batch's forward:
- refill
pending_members; - clear
forward_hook_laston every member.
Only then let the member that completes the set for this batch raise StopForward. Alternatively, keep the declared-order stop for dense subsets and never early-stop a subset with conditionally-executed members (MoE experts), as before #4703. Note that a MoE batch in which some expert is not routed never completes the set, so it runs to completion. That is correct and costs only the rest of the layer forward.
Test that should have caught it
tests/test_subset_declared_order_4679.py runs the out-of-order MLP with one batch only. Add a case with two or more batches where the member that completes the set in batch 0 fires first in batch 1, for example a toy MoE whose routing flips between batches. Assert that every member's hook (and GPTQ.add_batch) fires in every batch that routes to it. An end-to-end check on a tiny Qwen3-MoE with batch_size=1 and 8 rows that asserts per-expert nsamples would also catch it.
Severity
High (silent calibration-data loss, regression). Every MoE model quantized with GPTQ/AWQ/EXL3/ParoQuant on main calibrates its routed experts on about one batch per layer instead of the full dataset. AWQ additionally sends many experts to RTN. Nothing errors.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-53ba17eb4d83finished this issue.Pull request: #4752
Resetting the subset early-stop flag between batches so routed MoE experts keep all calibration
Qubitium commentedon Nov 17, 2026
Dense models are affected as well, and badly. The statement "Dense subsets (q/k/v, gate/up) are not affected" does not hold. In batch 1 and every later batch,
pendingis already empty, somarked()setsforward_hook_last = Trueon whichever member fires first, andStopForwardis raised right after it. In a q/k/v subset that member isq_proj; in gate/up it isgate_proj. The other members are cut off. As a result,k_proj,v_projandup_projsee only batch 0 of the calibration set on every dense Llama/Qwen model.Measured on
main@ b225a43, with12c1273c2as the A/B base. Hook calls per layer-0 module are counted by wrappingpre_process_fwd_hook. The model is Qwen2.5-0.5B-Instruct truncated to 3 layers, with 8 C4 rows atbatch_size=1. Numbers are summed over the 3 layers:For AWQ this changes the checkpoint through the clip search.
v_projandup_projare clipped from one sample (q/kare excluded from clipping). In the diff of the 3-layer checkpoint, onlyv_projandup_projqweight/scales differ, already in layer 0. MACaQ is hit the same way. GPTQ, GPTAQ, FOEM, QQQ, EXL3 and ParoQuant checkpoints remain byte-identical here, because the siblings share the leader's Hessian/capture.git bisect runon the 3-layer AWQ checkpoint hash lands on 219a528 (#4703). For MACaQ, the hash at219a52803~1equals12c1273c2, and the hash at219a52803equalsmain.Full-model quantize, save and reload. Wikitext-2 PPL, 80x512 windows, 128 C4 rows, default configs, fp16:
Every one of these was byte-identical between rounds before #4703. So on
main, the default AWQ and MACaQ path silently loses quality on every dense model, not only MoE. The alternative fix in the issue ("keep the declared-order stop for dense subsets, never early-stop MoE subsets") would therefore not be enough by itself. The per-batch reset is required: refillpendingand clearforward_hook_laston every member before each batch's forward.Test addition: also assert the per-module hook count for a dense q/k/v + gate/up layer with 2+ batches. For example, on a tiny Llama with
batch_size=1and 4 rows, every member's hook should fire 4 times per layer. Todayk_proj/v_proj/up_projfire once.🤖 Generated with Claude Code
Qubitium commentedon Nov 17, 2026
Additional data: gpt-oss-20b-BF16 truncated to 2 layers (real weights), default
AWQConfig(bits=4, group_size=128), 32 C4 rows,batch_size=1, RTX 4090,main@ b225a43. #4723 restores thepost_attention_layernorm -> 64 expert gate/upgroup here. Because of this bug, most of that group's members then fall back:So on gpt-oss, 70-77% of the routed-expert gate/up projections become RTN only because their calibration rows are cut off after the first batch.
🤖 Generated with Claude Code
Qubitium commentedon Nov 17, 2026
One extra data point. An existing repo test already catches this, and it has been red on
mainsince #4703:tests/test_moe_batch_equivalence.py::test_moe_expert_weights_match_across_calibration_batch_sizes(CPU, tiny Qwen3-MoE, 2 calibration rows, comparesbatch_size=1vsbatch_size=2dequantized expert weights):Bisect (CPU, this test file at each commit): passes at
04be2e62band at12c1273c2; first failing commit is219a52803(#4703). CountingGPTQ.add_batchrows per expert in that fixture:At a larger scale, on OLMoE-1B-7B truncated to 1 layer with 32 C4 rows (
t[:800]),batch_size=1, GPTQ, the sum ofadd_batchrows over all 64experts.*.gate_projis:main: 2,962 (min 5, median 30 per expert);219a52803^: 44,768 (min 331, median 644).q_projgets 5,596 rows in both runs. So with the defaultbatch_size=1, experts receive about 6.6% of their calibration tokens.The suite had a red test for this regression, but it was not run before #4703 merged.
🤖 Generated with Claude Code
Qubitium commentedon Nov 17, 2026
Follow-up: dense GPTQ is affected too once the shared-input Hessian dedup is off. With the default
HessianConfig(dedup_shared_inputs=True),k_proj/v_proj/up_projreuse the leader's (q_proj/gate_proj) Hessian, and that masks the bug. WithGPTQConfig(bits=4, group_size=128, hessian=HessianConfig(dedup_shared_inputs=False)), each sibling builds its own Hessian. Those Hessians now come from batch 0 only.Llama-3.2-1B-Instruct, fp16, 128 C4 rows,
batch_size=1, quantize, save and reload. Wikitext-2 PPL over 80x512 windows, RTX 4090:12c1273c2(pre-#4703)main@ b225a43In the 3-layer Qwen2.5-0.5B checkpoint, the hash changes exactly at 219a528:
219a52803~1gives 8306848e and219a52803gives 11058ba7.🤖 Generated with Claude Code
fix(looper): rebuild the subset early-stop state every calibration ba…
Qubitium commentedon Nov 17, 2026
A correction to "Dense subsets (q/k/v, gate/up) are not affected". That holds only while
HessianConfig(dedup_shared_inputs=True)(the default) collapses q/k/v and gate/up onto one hooked leader. Withdedup_shared_inputs=False, the dense followers are starved the same way.Repro:
tests/test_shared_input_hessian_dedup_e2e.py::test_tiny_llama_dedup_matches_independent_hessians. It is a CPU test: tiny Llama, 2 layers, 3 calibration rows of 15/12/9 tokens,batch_size=1.219a52803^and fails from219a52803(fix(looper): stop a subset only after every member captured (#4679) #4703) on:AssertionError: model.layers.0.self_attn.v_proj(dedup-on and dedup-off weights differ).GPTQ.add_batchrows per module withdedup_shared_inputs=False:(Both layers show the same counts.) On main, k/v/up see only the first batch, which is the 15-token row. So with dedup off, every dense shared-input follower is calibrated on one batch. The fix should cover both cases: re-arm
pending_membersand clearforward_hook_lastper batch.🤖 Generated with Claude Code
Qubitium commentedon Nov 17, 2026
Full-model data point for checking #4752. Qwen1.5-MoE-A2.7B (full, 24 layers x 60 experts, top-4), default
GPTQConfig(bits=4, group_size=128), 128 C4 docs, bf16, RTX 4090. Quantize, save, reload (Marlin), then wikitext-2 40x512:main@ b225a43 (before #4752)12c1273c2(before #4703)Using rtn fallback quantizationOn the full model, almost every routed expert projection silently became RTN. The fix should bring
mainback to about 8.66 with 0 expert fallbacks; a quick check is to grep the quantize log forrtnfallback on any MoE model.🤖 Generated with Claude Code