Repository navigation
Description
Found on main @ 4f287eb, Radeon AI PRO R9700 (ROCm, gfx1201) and CPU.
What is wrong
With GPTAQ (and FOEM with alpha > 0), the run plan has two calibrated processors: NativeProcessor followed by GPTQProcessor (gptqmodel/models/quantization_run_plan.py:159-163). Each one prepares its own copy of the calibration data in LoopProcessor.__init__ (gptqmodel/looper/loop_processor.py:564). ModuleLooper then runs a separate input capture for each processor from that processor's own calibration_dataset (gptqmodel/looper/module_looper.py:2209-2229).
With CalibrationConfig(sort="shuffle"), each preparation calls the global random.shuffle (gptqmodel/utils/calibration.py:1066-1069) separately, so the two processors get different batch orders. GPTAQ pairs the native input with the quantized input by batch index: NativeProcessor tags its entries (batch_index, x) (native_processor.py:257) and GPTAQ._take_native_input(batch_index) (quantization/gptaq.py:76) picks the entry with the same index. Batch i of the native pass and batch i of the quantized pass are now different samples, so dXXT = (X_native - X_q) X_q^T mixes unrelated sequences.
- Rows of different lengths (the normal case): the run crashes inside the first layer with an unhelpful message:
RuntimeError: The size of tensor a (367) must match the size of tensor b (528) at non-singleton dimension 1. The same happens withconcat_size, because the padded tail window has fewer real tokens. - Rows of equal length (pre-tokenized
max_lengthrows, or concatenated windows that fill exactly): the run completes silently with a garbagedXXT. At layer 0 the native and quantized inputs are identical, so the correctdXXTis exactly 0, but the shuffled run gets a non-zero one. Deeper modules'dXXTis 14-70x the norm of the correct one.
Measured (Qwen2.5-0.5B-Instruct, fp16, 128 C4 rows pre-tokenized to exactly 256 tokens, quantize -> save -> reload -> wikitext-2 PPL, 80x512; base 18.55)
| method | sort=None |
sort="shuffle" |
|---|---|---|
| GPTQ 4-bit g128 (control) | 21.21 | 21.12 |
| GPTAQ 4-bit g128 | 20.52 | 42.91 |
| GPTAQ, same 128 C4 docs as text (variable length) | - | RuntimeError: The size of tensor a (367) must match the size of tensor b (528) |
CPU, 2-layer Qwen2.5 trunc, 13 rows x 128 tokens: the order of the first token of each batch as prepared by each processor:
call 0 (NativeProcessor): [63590, 2183, 11135, 140386, 32792, 785, 38214, 1, 1861, 33, 71021, 11526, 4340]
call 1 (GPTQProcessor) : [11526, 785, 33, 63590, 71021, 32792, 4340, 2183, 140386, 1861, 38214, 11135, 1]
layer0 q_proj: H rel diff vs sort=None 1.3e-07, dXXT rel diff inf (correct dXXT is 0)
layer0 o_proj: dXXT rel 15.5; gate/up: 70.5; down: 14.4
Repro
import random
from gptqmodel import GPTQModel, CalibrationConfig
from gptqmodel.quantization.config import GPTQConfig, GPTAQConfig
m = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", GPTQConfig(bits=4, group_size=128, gptaq=GPTAQConfig()))
rows = [{"input_ids": ids[:256]} for ids in (m.tokenizer(t)["input_ids"] for t in c4_texts) if len(ids) >= 256]
random.seed(1)
m.quantize(CalibrationConfig(dataset=rows, sort="shuffle")) # completes; PPL 42.9 vs 20.5 with sort=None
m2 = GPTQModel.load(..., GPTQConfig(bits=4, group_size=128, gptaq=GPTAQConfig()))
m2.quantize(CalibrationConfig(dataset=c4_texts, sort="shuffle")) # RuntimeError: size of tensor a (367) must match ... (528)Suggested fix
Prepare the calibration data once per run and hand the same prepared list to every processor in the chain (or shuffle with one random.Random(seed) drawn once per run and reused by every preparation). Pairing by batch index is only valid if all processors see the same batch order. _quantize_with_calibration already materializes the dataset once for this reason (#4307); the prepared batches need the same treatment. EoRA has no pairing, but it also prepares independently and would benefit from the same single preparation.
Test that should have caught it
GPTAQ/FOEM tests run only with the default sort="desc", which is deterministic. A test that runs GPTAQ with sort="shuffle" on a tiny model (variable-length rows -> must not crash; equal-length rows -> layer-0 dXXT must be 0) would catch both symptoms.
Severity
High for GPTAQ/FOEM users who shuffle: either an unexplained crash or a silently 2x-worse checkpoint (PPL 20.5 -> 42.9). sort="shuffle" is a documented CalibrationConfig option.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-root-4869fixed this in #4985 (squash-merged as 7f0ca1f).fix(gptaq): prepare calibration batches once per run (ModelCloud#4985)
Port every supported model onto the Transformers 5.23 ABI; never patc…