Skip to content

[BUG] AWQ scale-search replay ignores seq dim (7-8B OOM with fixed-length calibration); dict fallback= doubles threshold 0.5% -> 1.0% #4087

Closed

Description

@Qubitium

Audit of main @ ad0525c (both lines are unchanged in 701e58b). Tested on an RTX 5090 (32 GB) with Llama-3.1-8B-Instruct, Mistral-7B-Instruct-v0.3, DeepSeek-V2-Lite and Qwen3-30B-A3B: 128 × 2048 C4 calibration windows, wikitext-2 PPL at ctx 2048.

1. AWQ scale-search replay sizing ignores the sequence dimension, so every 7-8B model OOMs with fixed-length calibration (high)

_scale_search_replay_batch_size (looper/awq_processor.py:2893-2915; :3010 on 701e58b) treats x.shape[0] as rows but sizes each row as hidden elements only:

bytes_per_row = max(1, hidden) * element_size * 3

Equal-length captures are concatenated by _can_concat_batch_tensors to [128, 2048, H]. The seq dim is missing from the estimate, so the function returns 0 ("one forward over everything") and the MLP scale search runs a single forward over 262k tokens.

This hits anyone using fixed-length windows or calibration_concat_size, i.e. the standard recipe. Variable-length text takes the latest_batch path (#4063) instead, which hid this bug.

x=(128, 2048, 4096):  replay_batch_size=0 -> one forward covers 262144 tokens, input chunk 2.00 GiB (budget 1 GiB)
x=(128, 2048, 14336): replay_batch_size=0 -> 7.00 GiB
x=(262144, 4096):     replay_batch_size=43690 -> 0.33 GiB   (2-D input is sized correctly)

Llama-3.1-8B / Mistral-7B, AWQ 4-bit g128, 128x2048, 32 GB card:
  OutOfMemoryError: Tried to allocate 7.00 GiB  (=128*2048*14336*2 B)
  at awq_processor.py _iter_prepared_forward_outputs -> modeling_llama.py LlamaMLP

With the per-row bytes fixed to x.numel() // rows * element_size * 3, both models quantize (peak 12.8 GB):

model fp RTN GPTQ AWQ (fixed)
Llama-3.1-8B 6.778 7.478 7.124 7.215
Mistral-7B-v0.3 6.136 6.305 6.357 6.284

Fix: bytes_per_row = (x.numel() // rows) * element_size * 3. tests/test_awq_scale_search_memory.py only covers 2-D inputs; add a 3-D [N, seq, H] case.

2. fallback= given as a dict silently doubles the fallback threshold from 0.5% to 1.0% (low-medium, silent)

_normalize_fallback (quantization/config.py:3506) defaults to fallback.get("threshold", "1.0%"). The Fallback dataclass default (:1449) and docs/quantization_protocol.md both say 0.5%.

GPTQConfig(bits=4, group_size=128).fallback.threshold                               # '0.5%'
GPTQConfig(bits=4, group_size=128, fallback={"strategy": "rtn"}).fallback.threshold # '1.0%'

A dict that only sets smooth gets the doubled threshold too. On Qwen3-30B-A3B (128×2048 = 262,144 tokens), the per-expert token counts from a real run give:

  • 0.5%: 1458 experts (23.7%) fall back to RTN.
  • 1.0%: 1886 experts (30.7%) fall back to RTN.

So 428 more experts silently move from GPTQ to RTN.

Fix: default the dict path to Fallback().threshold, i.e. fallback.get("threshold", Fallback.threshold).

Checked, no defect found

  • Sliding window: a tiny Mistral (window 32) and Mistral-7B-v0.1 (window 4096, 6144-token calibration): every self_attn replay call sees the exact sliding mask.
  • Replay vs HF hidden states: layer 0 is exact; later layers are within ≤2.5% relative error, with no growth over position. Llama-3.1's rope_type=llama3 is handled correctly.
  • Calibration length: going from 2048 to 4096 tokens scales time and peak memory linearly, with no OOM. Trimming is limited only by max_position_embeddings.
  • MoE GPTQ: DeepSeek-V2-Lite +3.5% PPL and Qwen3-30B-A3B +2.1%. All experts are quantized, and save/reload works.

🤖 Generated with Claude Code

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