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] Regression from #5175 (fix of #5137), worse after #5212: AWQ routed-expert reservoir copies the whole kept buffer under the processor lock on every capture - OLMoE-2L AWQ quantize 43-54 s -> 164-217 s (main) / 217-312 s (63da42c0e), capture time 8.6 s -> 73-123 s #5233
Found on main @ 396b5f0 and on 63da42c (with #5212), RTX 4090, torch 2.15, transformers 5.22.
What is wrong
#5175 (fix of #5137) bounds AWQ token-row capture at capture time. Routed MoE experts do not match the per-batch plan, so every capture goes through the "dynamic / streaming reservoir" branch of AWQProcessor._record_input_feature (gptqmodel/looper/awq_processor.py:1302-1353). Each call does all of the following while holding the processor-wide self.lock:
torch.cat of the whole kept buffer (up to budget_cap = 906 rows x hidden) plus the new rows;
an index_select copy of the result;
a rebuild of the Python provenance list of (source_idx, row) tuples (current_prov + candidate_prov, then a list comprehension).
#5212 (fix of #5204) made the same branch heavier. It now concatenates the kept rows, the priorities and the provenance on every capture, even below the budget. It also sorts the survivors with a Python key (keep.sort(key=lambda index: provenance[index])).
That is O(budget x hidden) copying plus O(budget) Python work per expert, per module, per batch, serialized on one lock. Capture used to be a cheap append. It now dominates AWQ quantize time on MoE models. Scale search time is unchanged, so this is not extra search work from the larger retained sample.
Measurements
OLMoE-1B-7B-0924 truncated to 2 layers (config copy), AWQConfig(bits=4, group_size=128), bf16, 128 C4 docs (2500 chars), single RTX 4090. Old and new runs were interleaved, and quantize() wall time was measured by the harness:
The per-function totals come from wrapping the methods with a thread-safe timer, summed across capture threads. In cProfile of the 63da42c run (258 s): torch.cat 196,828 calls / 35.3 s, {method 'acquire' of '_thread.lock'} 38.4 s (capture threads waiting on self.lock), list.sort 8.8 s with 40.3M calls of the provenance[index] key lambda, and _record_input_feature cumulative 101 s.
Dense models are not affected: Qwen2.5-0.5B awq4 takes 147/72 s old vs 65/65 s on main, and the checkpoint is bit-identical. Dense modules use the precomputed plan.
The cost is about 1.5-2.4 ms per routed-expert capture. On a real MoE (for example 48 layers x 128 experts at 128 docs) that is tens of thousands of captures per layer, so roughly minutes per layer and hours per model of pure bookkeeping under one lock.
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 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^: ~43-54 s main 396b5f0e1: ~164-217 s 63da42c0e: ~217-312 s
Suggested fix
Make the routed-expert reservoir O(rows of the new batch) per capture, not O(budget):
Keep a preallocated [budget_cap, hidden] buffer plus a [budget_cap] priority tensor (and integer provenance tensors) per module.
For a new batch, draw its priorities, select the survivors among the at most budget_cap + L priorities with one topk, and write only the replaced rows into the buffer (index_copy_/scatter). Do not concatenate or reorder the whole buffer.
Store provenance as two int tensors (source_idx, row), and order the buffer once in _layer_input_features with argsort(source_idx * max_len + row), not a Python key sort on every capture.
Do the tensor work outside the processor-wide self.lock (use a per-module lock, as the plan path does), so the experts' capture threads do not serialize.
Test that should have caught it
The #5137 tests check retained row counts and RSS but not time. An OLMoE-2L (or tiny random MoE) AWQ quantize timing check against a capture-time budget, or a unit test asserting that _record_input_feature does not copy the kept buffer when the batch is fully rejected, would have caught it.
Severity
Medium [PERF]: AWQ quantization of MoE models is 3-6x slower end to end on the measured model (capture bookkeeping 8.6 s -> 73-123 s), and the cost grows with experts x layers x batches.
Activity
Qubitium commentedon Nov 18, 2026
Agent claim released:
agent-fb5145b84190finished this issue.Pull request: #5236
Profiling the routed-expert reservoir capture path on CPU and reworking it to incremental merge
Port every supported model onto the Transformers 5.23 ABI; never patc…