Repository navigation
Description
Follow-up review of the merged PRs #4031, #4032, #4033, #4034, #4035 and #4043. I compared each one against its parent commit (extracted with git archive) on an RTX 4090, quantizing tiny Llama / Qwen3-MoE / Qwen2-MoE / DeepSeek-V2-MLA / ERNIE-4.5-MoE models plus a 6-layer h2048 Llama, with GPTQ and AWQ at bs=1 and bs=4 padded. Every saved tensor was compared by SHA-256. The items below were found at e6b19c5 and re-checked on main @ 39cd57a.
Complete: #4031 (AWQ dequant layouts; all GEMM/GEMV/GEMV_FAST/dynamic cases within 3.5e-4) and #4034 (legacy gptaq booleans, untied lm_head).
#4043 has no numeric regression. Packed outputs are bitwise identical to its parent in all 24 pairs. Peak memory, parent → PR:
| run | peak (MB) |
|---|---|
| GPTQ bs=4 | 886 → 700 |
| AWQ bs=4 | 1134 → 855 |
The p2p leak is fixed (8/8 tensors alive before, 0/8 after).
1. #4035 regression: an MoE expert that receives only padding rows gets its whole weight zeroed at batch_size > 1 (high, silent)
looper/gptq_processor.py register_moe_root_capture_hook zeroes the padded rows of the MoE input, but those rows are still routed and still counted in nsamples:
- All-zero rows give all-zero router logits. The tie goes to experts 0/1 on CUDA, or for DeepSeek-style routers with
e_score_correction_bias, to the highest-bias experts (usually the under-used ones). - An expert with no real tokens therefore clears the 0.5% fallback threshold on padding alone.
- It then runs GPTQ on an all-zero Hessian, and
_neutralize_dead_columnszeroes every weight column.
Repro: Qwen3-MoE, 6 experts, router rows constructed so experts 0/1 never win a real token, batch_size=4:
parent 85f18c0 : WARN mlp.experts.1.gate_proj -> Using `rtn` fallback quantization (observed 0 samples ...) |Wq| = 2.58
main (39cd57a): model.layers.0.mlp.experts.1.gate_proj |Wq| = 0.000 zero_frac = 1.000 (also down_proj)
bs=1 : RTN fallback, as before
Fix: count only kept rows toward nsamples and the fallback threshold, e.g. skip all-zero rows in the expert hooks or pass the row mask through. Alternatively, drop the padded rows instead of zeroing them so they never reach the router. test_moe_batch_equivalence misses this because its 2-sample fixture never leaves an expert without real tokens.
A related, plausible case: an expert with a few real tokens (below the threshold) plus padding now runs GPTQ on those few tokens at bs>1, but gets RTN at bs=1.
2. #4043 incomplete: the AWQ sibling-capture dedup never fires (dead code), and apply_scale has a latent bug that would surface once it does
looper/awq_processor.py:658 _capture_share_key does int(feature._version). Calibration runs under inference_mode, so every captured feature is an inference tensor, _version raises, and the key is always None.
- Instrumented counts: Llama AWQ bs=1 rejected 336/336 captures as
noversion(inference=True), with 0 cache hits. - Every
apply_scalecall had 0 shared features across llama / qwen3moe / qwen2moe, with native, bypass and"all"routing. - So the cat cache and the divide-once logic never run either. The PR's AWQ memory win comes from items 1–2 of [PERF] Quantization pipeline: GPU memory leak (p2p_move_nested closure cycle pins every layer's replay outputs, ~1 GiB/layer at 70B), AWQ host round-trip and duplicate sibling captures, missing :in= Hessian dedup tags #4020, not from this one. Its unit test builds normal tensors, which is why it passes.
Fix: key on data_ptr(), shape, stride and dtype within a batch (inference tensors can't be modified in place outside inference mode), or capture outside inference_mode.
Latent bug, reachable once the dedup works: in quantization/awq/quantize/scale.py apply_scale, if one shared feature tensor belongs to two scale groups, both groups read x / s_last. Before the PR, each group read its own x / s:
feature for a: x/4.0 (own-copy semantics: x/2.0)
3. #4032: TorchFused GPTQ (CPU/XPU) with fp16 activations and a bias is now 7–17× slower; TorchAten fp16+bias and BnB INT8 bf16 are still on the slow paths
- TorchFused:
nn_modules/qlinear/torch_fused.py~335-352:fused_bias_safeis False for fp16 with a bias, solinear_modeis permanentlyTRAINand every forward dequantizes the full weight. K=N=4096, M=1, 4 threads: 928d8dd 12.5 / 25.3 / 32.4 ms → 4f7fab7 217 / 310 / 211 ms. This is the same slow-path pattern [BUG] Follow-up on #3999/#4001: stale uniform-group flag after load_state_dict (M=2..64 wrong), TorchFused GPTQ still overflows, bias forces 7x (ExLlamaV2) and 2.6-21x (CPU) slower paths, AwqExLlamaV2+LoRA returns fp32 #4028 item 3 reported for the other CPU kernels. - Still incomplete from [BUG] Follow-up on #3999/#4001: stale uniform-group flag after load_state_dict (M=2..64 wrong), TorchFused GPTQ still overflows, bias forces 7x (ExLlamaV2) and 2.6-21x (CPU) slower paths, AwqExLlamaV2+LoRA returns fp32 #4028:
- TorchAten fp16+bias is still dense (190–220 ms).
- BitsAndBytes INT8 bf16 still uses the Python fp32 path ([BUG] Follow-up on #3999/#4001: stale uniform-group flag after load_state_dict (M=2..64 wrong), TorchFused GPTQ still overflows, bias forces 7x (ExLlamaV2) and 2.6-21x (CPU) slower paths, AwqExLlamaV2+LoRA returns fp32 #4028 item 6); only fp16 without a bias went back to native.
- Minor: ExLlamaV2 bf16 with a bias now writes a bf16 output and then adds the bias, rounding twice (relative error 1.67e-3 → 1.95e-3).
- Verified fixed:
- ExLlamaV2 / AwqExLlamaV2 fp16+bias: 160–185 µs → 30–60 µs at M=1/16, accuracy unchanged.
- TorchAten bf16+bias: 68.6 → 24.4 ms.
- Stale uniform-group flag and LoRA dtype: fixed.
Fix: use an fp32-output fused op and add the bias before a single cast, or fall back to dense only when the output can actually overflow.
4. #4033 incomplete: the OpenAI server restores the RNG state outside the generation lock (low-medium)
utils/openai_server.py ~470-490: _restore_rng_state(rng_state) runs in a finally after the with self._generation_lock: block exits, while the comment says the restore happens while the lock is held. After request A releases the lock, request B can seed and start generating, and then A's restore overwrites B's RNG state. With a 0.1 s delay injected inside the restore (standing in for preemption), a seed=22 request drew 0.7025 instead of the expected 0.3659. Without the delay it reproduced 0/5 times; the GIL keeps the window narrow. Fix: move the restore inside with self._generation_lock. Note that the PR's concurrency test can't run in an environment without httpx / fastapi.
🤖 Generated with Claude Code
Activity
fix(moe,awq,kernels,server): keep padding out of expert Hessians and …