Skip to content

[BUG] Follow-up on #4035/#4043/#4032/#4033: pad-only MoE expert zeroed at bs>1 (regression), AWQ capture dedup never fires, TorchFused fp16+bias 7-17x slower, RNG restore outside lock #4051

Closed

Description

@Qubitium

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_columns zeroes 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.

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions