You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[PERF] #5236 (fix of #5233) incomplete: MoE AWQ quantize still 2.1-3.4x slower than pre-#5175 (OLMoE-2L 119-129 s vs 38-56 s) - per-capture ModulePlan policy rebuild (51k calls), ~160 us tensor merge per capture, and every routed expert now keeps the 906-row cap (5x clip-search rows) #5284
Found on main @ c1807f8, RTX 4090 (shared GPU; old and new runs interleaved), torch 2.15, transformers 5.22.
What is wrong
#5236 (fix of #5233) removed the copy of the whole kept buffer under the processor lock. That part works: the r21 base 396b5f0 spent 90.7 s in capture, main spends 22-35 s. But AWQ quantize of a MoE model is still 2.1-3.4x slower than before #5175, which is the level #5233 asked to restore. Three costs remain, all on the routed-expert path. They were measured with method wrappers (time.perf_counter, summed) on the same OLMoE run.
Per-capture policy lookup._record_input_feature calls _feature_aggregation_policy(module_name) (gptqmodel/looper/awq_processor.py:1200) on every capture. That calls BaseQModel.awq_input_feature_aggregation (gptqmodel/models/base.py:6062), which rebuilds ModulePlan.from_tree(...) and walks the whole module tree each time. One call costs about 36 us. Main makes 51,470 calls (3.4-3.5 s); pre-fix(awq): bound token-row activation capture to sampling budget (#5137) #5175 made 1,308 (0.1 s). The result is a pure function of the class and the module name.
Per-capture tensor merge._merge_reservoir_rows costs 7.2-8.6 s over 48,882 calls, about 160 us each. Every capture runs torch.cat of the priorities, topk, a bool mask, nonzero and two torch.arange, even when no new row survives.
Clip search on about 5x more rows. Every routed expert now keeps the layer-wide cap: 906 rows for every expert projection (384 of 384). Before fix(awq): bound token-row activation capture to sampling budget (#5137) #5175, each expert's budget came from its own captures (max(largest capture, contributing batches)): mean 185 rows (min 128, max 548). _search_best_clip time rose accordingly: 10.0 s -> 22 s (cProfile run) and 12.9 s -> 68.5 s (a heavily contended run).
Measurements
OLMoE-1B-7B-0924 truncated to 2 layers (config copy), AWQConfig(bits=4, group_size=128), bf16, 128 C4 documents (2500 chars), one capture thread (single GPU, run_single). Each row is one quantize():
The pairs were interleaved (main, pre, main, pre). In every pair main took 2.1-3.4x as long. _search_best_scale is unchanged (1.5-3 s).
Repro
importtime, gzip, json, torchfromgptqmodelimportGPTQModelfromgptqmodel.quantizationimportconfigasCcal= [t[:2500] fortin (json.loads(l)["text"] forlingzip.open("c4-train.00000-of-01024.json.gz", "rt")) iflen(t) >=1500][:128]
m=GPTQModel.load("<OLMoE-1B-7B-0924 config copy with num_hidden_layers=2>", C.AWQConfig(bits=4, group_size=128), dtype=torch.bfloat16)
t=time.time(); m.quantize(C.CalibrationConfig(dataset=cal)); print(time.time() -t)
# 0b1aea0f5^: 38-56 s main c1807f889: 119-129 s
Policy cost alone: OlmoeQModel.awq_input_feature_aggregation("mlp.experts.3.gate_proj") takes 36.5 us per call (2,000 calls, CPU).
Suggested fix
Cache the aggregation policy per (cls, module_name), or resolve it once per module per layer. It does not change between captures.
In _merge_reservoir_rows, once the buffer is full, compare priorities.min() with the current maximum kept priority (keep that maximum as a scalar). Skip the merge when no new row can survive; with a full 906-row buffer, most captures of a routed expert add nothing. Do small merges with a single topk on the new rows only.
Decide whether every routed expert should keep the dense layer's 906-row cap. Before fix(awq): bound token-row activation capture to sampling budget (#5137) #5175, an expert kept a budget sized from its own captures (about 185 rows here). If the larger sample is intended for accuracy, document the roughly 5x clip-search cost. Otherwise size the reservoir from the expert's own capture budget.
Test that should have caught it
The #5233 tests check buffer reuse and provenance but not time. A capture micro-benchmark asserting a per-capture cost bound, or a check that _feature_aggregation_policy is not called on every capture, would catch items 1 and 2.
Severity
Medium [PERF]: AWQ quantization of MoE models is still 2-3x slower end to end than before #5175, with no accuracy evidence offered for the larger per-expert sample. The cost grows with experts x layers x batches.
Cache the AWQ feature-aggregation policy per (class, module name) and skip the reservoir merge when no new row can survive; measure both on CPU and add regression tests.
Agent claim:agent-4e3a0639ecaf is working on this issue now.
Started 2026-11-18T23:50:03Z. The claim expires 4.0h after this comment is last edited (heartbeat). Other agents: do not start this issue while the claim is live.
Scope: recover the remaining MoE AWQ quantize gap vs pre-#5175: cache the per-capture ModulePlan policy lookup, make the reservoir merge cheap when no row survives, and restore a per-expert row budget so the clip search is not run on 5x the rows; verify with OLMoE-2L wall time and unchanged checkpoint quality
Accuracy data for item 3 (the routed-expert cap), which #5295 left open as "an accuracy decision". Measured on main @ c03416c (includes #5295), RTX 4090, full 16-layer OLMoE-1B-7B-0924.
Setup: AWQConfig(bits=4, group_size=128), bf16, 128 C4 documents (2500 chars, batch_size=1). Quantize, save, reload with AwqMarlin, then wikitext-2 PPL over 40 x 512 windows. The bf16 base is 10.6925. Runs were back to back on the same GPU.
The 3.6x larger expert sample gives no measurable accuracy gain on the full model: PPL 11.2870 vs 11.2814. It costs about 15 s per MoE layer, roughly 1.4x end-to-end quantize(). The layer-wide cap is the dominant remaining gap to pre-#5175 speed. The last row's quantize time was not recorded because it was a quant-only run; its per-layer times are directly comparable.
Per-expert budget used above. Monkeypatch only. Before _materialize_reservoir_provenance, keep the k = _cap_token_rows(min(sum(counts), max(max(counts), len(counts)))) lowest-priority rows of the reservoir, where counts are the expert's non-empty batch_row_counts. This is the pre-#5175_token_row_budget formula applied to the expert's own captures. The lowest-k priorities of a uniform priority reservoir are themselves a uniform sample, so #5212's uniformity is kept. Memory stays O(906), and the kept set stays deterministic.
Second model. Qwen3-30B-A3B truncated to 12 layers (128 experts, top-8), same settings. KL is measured against the bf16 logits of the same truncated model. Truncation makes PPL meaningless here.
expert budget
rows kept per expert projection
s / layer
quantize()
KL vs bf16 (reloaded)
starved-fallback records
layer-wide cap (current)
906, or all raw rows when fewer
49-64
698 s
0.1010
1860
per-expert budget
mean 195
27-38
489 s
0.1013
1854
Here too the larger sample is accuracy-neutral (+0.3% KL, within run-to-run noise) and costs about 1.4x quantize time.
Checks I ran on the 906-cap main runs:
0 fallbacks, and every expert's raw rows sum to 8.000 x tokens in every layer.
gate/up/down provenance is identical for every expert (1024/1024).
Agent claim released:agent-4e3a0639ecaf opened follow-up PR #5327.
#5295 landed the policy memoization and the no-op merge. This PR carries the two remaining items from the accuracy data above: the per-expert reservoir budget (max(largest capture, capture count), mean 254 on the full model) and an incremental merge that writes only the surviving captured rows. A growing budget now carries the rows it holds instead of re-seeding from inputs (which silently dropped them).
2-layer OLMoE, 128 C4 docs, batch_size=1, RTX 4090, alternating runs: 165.4 s -> 65.5 s (2.5x).
Activity
Qubitium commentedon Nov 18, 2026
Agent claim released:
agent-fb5145b84190finished this issue.Pull request: #5295
Cache the AWQ feature-aggregation policy per (class, module name) and skip the reservoir merge when no new row can survive; measure both on CPU and add regression tests.
Qubitium commentedon Nov 18, 2026
Agent claim:
agent-4e3a0639ecafis working on this issue now.Started 2026-11-18T23:50:03Z. The claim expires 4.0h after this comment is last edited (heartbeat). Other agents: do not start this issue while the claim is live.
Scope: recover the remaining MoE AWQ quantize gap vs pre-#5175: cache the per-capture ModulePlan policy lookup, make the reservoir merge cheap when no row survives, and restore a per-expert row budget so the clip search is not run on 5x the rows; verify with OLMoE-2L wall time and unchanged checkpoint quality
perf(awq): memoize the capture policy and skip losing reservoir merges (
Qubitium commentedon Nov 19, 2026
Accuracy data for item 3 (the routed-expert cap), which #5295 left open as "an accuracy decision". Measured on
main@ c03416c (includes #5295), RTX 4090, full 16-layer OLMoE-1B-7B-0924.Setup:
AWQConfig(bits=4, group_size=128), bf16, 128 C4 documents (2500 chars,batch_size=1). Quantize, save, reload with AwqMarlin, then wikitext-2 PPL over 40 x 512 windows. The bf16 base is 10.6925. Runs were back to back on the same GPU.quantize()main, layer-wide cap (current)main+ per-expert budget (see below)7b8f12785(pre-#5175, round-20 base)The 3.6x larger expert sample gives no measurable accuracy gain on the full model: PPL 11.2870 vs 11.2814. It costs about 15 s per MoE layer, roughly 1.4x end-to-end
quantize(). The layer-wide cap is the dominant remaining gap to pre-#5175 speed. The last row's quantize time was not recorded because it was a quant-only run; its per-layer times are directly comparable.Per-expert budget used above. Monkeypatch only. Before
_materialize_reservoir_provenance, keep thek = _cap_token_rows(min(sum(counts), max(max(counts), len(counts))))lowest-priority rows of the reservoir, wherecountsare the expert's non-emptybatch_row_counts. This is the pre-#5175_token_row_budgetformula applied to the expert's own captures. The lowest-kpriorities of a uniform priority reservoir are themselves a uniform sample, so #5212's uniformity is kept. Memory stays O(906), and the kept set stays deterministic.Second model. Qwen3-30B-A3B truncated to 12 layers (128 experts, top-8), same settings. KL is measured against the bf16 logits of the same truncated model. Truncation makes PPL meaningless here.
quantize()Here too the larger sample is accuracy-neutral (+0.3% KL, within run-to-run noise) and costs about 1.4x quantize time.
Checks I ran on the 906-cap
mainruns:🤖 Generated with Claude Code
Qubitium commentedon Nov 19, 2026
Agent claim released:
agent-4e3a0639ecafopened follow-up PR #5327.#5295 landed the policy memoization and the no-op merge. This PR carries the two remaining items from the accuracy data above: the per-expert reservoir budget (
max(largest capture, capture count), mean 254 on the full model) and an incremental merge that writes only the surviving captured rows. A growing budget now carries the rows it holds instead of re-seeding frominputs(which silently dropped them).2-layer OLMoE, 128 C4 docs,
batch_size=1, RTX 4090, alternating runs: 165.4 s -> 65.5 s (2.5x).perf(awq): size routed-expert reservoirs from their own captures (#5284…
Port every supported model onto the Transformers 5.23 ABI; never patc…