Skip to content

[BUG] AWQ crashes on GPT-Neo with batch_size>1: packed token-row replay exceeds max_position_embeddings and GPTNeoSelfAttention's fixed causal bias buffer cannot be sliced (RuntimeError, no fallback) #5085

Closed

Description

@Qubitium

Found on main @ e75181d, CPU (tiny model). The round-16 base 4f287eb fails the same way, so this is not a recent regression.

What is wrong

AWQ scale search packs the captured rows of several calibration documents into one [1, retained_tokens, hidden] replay sequence (AWQProcessor._pack_token_rows, gptqmodel/looper/awq_processor.py:1357). The budget comes from _token_row_budget (:1327): max(largest batch's kept tokens, number of batches). So with batch_size > 1 the packed sequence is about batch_size x seq_len tokens long. A block-diagonal mask and the original position_ids keep that semantically correct for rotary/mask-driven attention.

GPTNeoSelfAttention does not take its causal mask from the attention_mask argument. It slices a fixed self.bias buffer of [max_position_embeddings, max_position_embeddings]:

causal_mask = self.bias[:, :, key_length - query_length : key_length, :key_length]
attn_weights = torch.where(causal_mask, attn_weights, mask_value)

When the packed replay is longer than max_position_embeddings (2048 for every EleutherAI GPT-Neo checkpoint), the slice is clipped and torch.where raises. This is a plain RuntimeError, not _AWQScaleGroupError, so the configured fallback never runs and quantize() aborts in layer 0. GPTQ on the same model and data succeeds, and so does AWQ with batch_size=1.

Repro

GPT-Neo with the real gpt-neo-125m position geometry (max_position_embeddings=2048, window_size=256, global/local layers), narrowed to 2 layers × 128 hidden. Calibration is 4 wikitext rows of 1100 tokens, each well under the 2048 limit.

cfg = GPTNeoConfig(vocab_size=50257, hidden_size=128, num_layers=2, num_heads=4, max_position_embeddings=2048,
                   window_size=256, attention_types=[[["global", "local"], 1]], intermediate_size=512)
GPTNeoForCausalLM(cfg).save_pretrained(D); AutoTokenizer.from_pretrained("gpt2").save_pretrained(D)
rows = [{"input_ids": ids[i*1100:(i+1)*1100], "attention_mask": [1]*1100} for i in range(4)]
q = GPTQModel.load(D, AWQConfig(bits=4, group_size=32), dtype=torch.bfloat16)
q.quantize(CalibrationConfig(dataset=rows, batch_size=bs))
awq bs 1 OK
awq bs 2 FAILED: RuntimeError The size of tensor a (2048) must match the size of tensor b (2200) at non-singleton dimension 3
gptq bs 2 OK

The replay that fails is GPTNeoAttention(x=[1, 2200, 128], attention_mask=[1, 1, 2200, 2200], position_ids=[1, 2200]), the ln_1 -> q/k/v group.

Suggested fix

Cap the token-row replay length at the model's position limit, for example min(budget, config.max_position_embeddings) (or a per-definition awq_input_feature_aggregation(...)["max_tokens"] for GPTNeoQModel). Alternatively, replay the packed rows per document when the packed length would exceed max_position_embeddings. Either way, a replay failure in the scale search should become an _AWQScaleGroupError so the configured fallback applies instead of aborting the run.

Test that should have caught it

No AWQ test runs GPT-Neo with batch_size > 1. A tiny gpt_neo quantize with batch_size=2 and rows longer than max_position_embeddings / 2 would catch it.

Severity

AWQ crashes on every GPT-Neo checkpoint whenever batch_size > 1 and one batch's non-pad tokens exceed 2048. The same happens if the calibration set has more than 2048 batches. There is no workaround short of batch_size=1.

🤖 Generated with Claude Code

Activity

  1. ZX-ModelCloud commented on Nov 18, 2026

    @ZX-ModelCloud
    Collaborator

    Claimed. I'm working on this issue and will submit a fix PR. Please avoid duplicate work in the meantime.

  2. ZX-ModelCloud commented on Nov 18, 2026

    @ZX-ModelCloud
    Collaborator

    Agent claim released: agent-aeb7dd7a0ca2 finished this issue.

    Pull request: #5120

    User-directed fix of AWQ GPT-Neo batch_size>1 replay crash: reproduce on latest main, then correct scale-search replay budget and fallback

  3. ZX-ModelCloud commented on Nov 18, 2026

    @ZX-ModelCloud
    Collaborator

    Confirmed on current main (e75181df5), and fixed in #5120.

    I reproduced the reported failure exactly with the real gpt-neo-125m
    position geometry (max_position_embeddings=2048, window_size=256,
    global/local layers, 2 layers x 128 hidden) and four 1100-token rows:

    Run Result
    AWQ, batch_size=1 OK
    AWQ, batch_size=2 RuntimeError: The size of tensor a (2048) must match the size of tensor b (2200) at non-singleton dimension 3
    GPTQ, batch_size=2 OK

    The replay that fails is the ln_1 -> q/k/v group, as described. Two notes
    that broadened the fix:

    • The same fixed causal buffer exists on OpenAI GPT
      (self.bias[:, :, :w.size(-2), :w.size(-1)]), where the slice is clipped
      without raising. Those rows would have been scored against a silently
      truncated causal mask rather than aborting, so the bound is worth having for
      correctness even where nothing crashes.
    • The second half of the suggested fix is needed too. Capping the budget covers
      the default policy, but a definition-declared max_tokens, or a module that
      bounds its context below the config value, can still produce an over-long
      replay. Such a replay now becomes an _AWQScaleGroupError so the configured
      plain-quantization fallback applies; fallback=None still propagates it.
      Memory, kernel and numerical RuntimeErrors keep propagating unchanged.

    The applied fix is the resolve_position_limit(...) cap on the token-row
    budget and on a definition-declared max_tokens, using the same config keys
    calibration truncation already reads, plus the geometry-error conversion around
    the reference replay. Fixes #5085 in #5120.

  4. added a commit that references this issue on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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