Skip to content

MoE quantization: 5 unresolved edge-case bugs in QuantTensor indexing / regex safety checks #2598

Description

@titaiwangms

Summary

microsoft/Olive#2584 (extending RTN quantization to MoE experts via QuantTensor) went through 3 rounds of adversarial review. Round 3 found 5 new Major-severity bugs, all independently reproduced, but not fixed in that PR — tracked here as a separate follow-up so #2584 can merge without blocking on them.

Why these are follow-ups, not blockers for #2584

All 5 are edge cases in QuantTensor's live in-memory dispatch (tensor.py) or the skip-pattern regex safety check (patterns.py) — neither is exercised by the currently-supported RTN quantization pipeline, which is @torch.no_grad() round-to-nearest and never runs a live forward pass through QuantTensor. They matter for: (a) future passes that do run forward calibration through quantized MoE weights (e.g. GPTQ, see microsoft/Olive#<gptq-issue>), and (b) any direct PyTorch-side use of QuantTensor outside the quantize-then-save flow.

The 5 issues

  1. tensor.py — uint8-dtype tensor indices misclassified as safe integer indices. Same bug class as a round-2 fix for boolean-mask indexing, different dtype variant not covered by that fix.
  2. tensor.pycopy_() does not propagate/clear is_placeholder. Copying real data into a placeholder QuantTensor can still get silently no-op'd by a later init-style op (zero_, normal_, ...).
  3. state_dict.pyrefresh_quant_tensor_refs clears is_placeholder unconditionally, not gated on an actual data load having completed.
  4. tensor.py — arbitrary-rank integer indexing (added to support top-k MoE routing) can produce a QuantTensor that can't be dequantized or re-indexed afterward.
  5. patterns.py — a third ReDoS bypass via (?#...) inline-comment regex syntax, confusing the char-class scanner used by the skip-pattern safety check (previous two bypasses: (a{1,2})+$, ((a|aa))+$).

Structural observation

This is the third consecutive round where a whitelist/blacklist-enumeration defense (index-dtype whitelist in tensor.py, regex-construct blacklist in patterns.py) gets bypassed by a new variant not covered by the previous fix. This is a signal the enumeration approach may be the wrong shape of fix for both checks, not that a 4th patch will finish the job. A more robust alternative — post-hoc shape/data assertion (verify the actual resulting shape/rank against what was claimed, after the op runs, rather than enumerating safe forms upfront) — was proposed but not implemented; there's a partial existing precedent for this pattern at olive/passes/onnx/compose.py:173.

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions