Skip to content

[BUG] GPTAQ / FOEM crash on Qwen2-MoE (Qwen1.5-MoE) at batch_size > 1: shared expert gets one native entry per batch but one quantized entry per sample #4457

Closed

Description

@Qubitium

Severity: medium-high. GPTAQ, and FOEM with alpha ≠ 0, cannot run on qwen2_moe at any batch_size > 1, padded or not.

Kind: new bug. It reproduces identically at def6e61. It is a gap in the per-sample native split from #4237/#4067 that 9626f50 kept when it rewrote _split_batch_samples.

Confirmed at 489aed6 on an RTX 4090.

m = GPTQModel.load("Qwen/Qwen1.5-MoE-A2.7B",
                   quantize_config=QuantizeConfig(bits=4, group_size=128, gptaq={}), dtype=torch.float16)
m.quantize(calib_rows_of_varying_length, batch_size=4)

(Run on a 2-layer truncation.)

  • batch_size=4: RuntimeError: The size of tensor a (1024) must match the size of tensor b (256) at non-singleton dimension 1 in gptaq._accumulate_device_batch (dxxT.add_((scale*native_inp - scaled_inp)...)), during layer 0.
  • batch_size=2 with 2 rows: (334) vs (167).
  • FOEM alpha=0.25: the same error at foem.py:315.
  • batch_size=1: completes (374 modules).

Cause

  • gptqmodel/looper/native_processor.py:136-144: _split_batch_samples only splits 3-D [B,S,H] inputs. When inp.dim() < 3 it returns a single entry holding the whole flattened batch.
  • looper/gptq_processor.py:630-672: the quantized-pass hook has a 2-D "flattened [B*S,H]" branch for HF qwen2_moe's shared_expert, which is called on hidden_states.view(-1, H). That branch calls add_batch once per sample, with pad rows masked out.
  • quantization/gptaq.py:241 (and foem.py:315) then pair one native entry of B*S rows with an S-row quantized entry. Even when the shapes happen to match, the native side still includes pad rows, so the dXXT term is wrong.
  • Routed experts are not affected (is_routed_expert disables the native delta). Only the shared expert, or any other module fed flattened rows, is hit.

Expected

batch_size > 1 completes. _split_batch_samples should mirror the hook's 2-D branch (inp.shape[0] == keep_mask.numel()) and produce one masked entry per sample, inp[s*S:(s+1)*S][keep[s]]. tests/test_moe_gptaq_foem.py only uses batch_size=1; a batch_size > 1 variable-length case would catch this.


Found during an AI-assisted review (Claude Code, round 13) of 489aed6; repros were run at that commit (A/B against def6e61 where noted) on RTX 4090/5090 (CUDA 13) and/or Radeon AI PRO R9700 (ROCm) unless marked static/suspected.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions