Skip to content

[BUG] Calibration input normalisation gaps: [B,T,T] masks collapse to one token; min-length checks only row 0 and counts padding; validation gaps #4194

Closed

Description

@Qubitium

Severity: low
Version: 7.11.0 @ 9dad249

1. A [B, T, T] causal attention_mask keeps only token 0

  • _pack_ids (utils/calibration.py:246-268) routes masks through _normalize_attention_mask and then normalize_seq_mask.
  • In utils/attn_mask.py:53-56, the fallback reshape(B, -1)[..., :seq_len] takes the first row of the T×T matrix.
  • The rank>2 handler meant for this case (calibration.py:233-239, "Some tokenizers emit causal masks shaped like [B, 1, T, T] or [B, T, T]") is dead code: _to_2d_long_tensor is never called with name="attention_mask".
import types, torch
from gptqmodel.utils.calibration import prepare_calibration_dataset
class Tok: pad_token_id = 0; padding_side = "right"; truncation_side = "right"
qm = types.SimpleNamespace(tokenizer=Tok(), model=types.SimpleNamespace(config=types.SimpleNamespace(max_position_embeddings=4096)), support_batch_quantize=True)
ids = torch.arange(1, 17).unsqueeze(0); m3 = torch.tril(torch.ones(1, 16, 16, dtype=torch.long))
for m in (m3, m3.unsqueeze(1)):
    print(int(prepare_calibration_dataset(qm, [{"input_ids": ids, "attention_mask": m}], calibration_data_min_length=0)[0]["attention_mask"].sum()))
# [B,T,T] -> 1 (expected 16);  [B,1,T,T] -> 16

Possibly related (likely, not reproduced on a stock model): normalize_seq_mask(torch.zeros(1,1,5,5)) returns all-False, the same additive-mask flaw as #4187. That helper also builds the GPTQ Hessian keep-mask (forward_executor.py:~372, looper_helpers.py:~710).

2. calibration_data_min_length checks only row 0, by padded width

  • utils/calibration.py:498: if len(input_ids[0]) <= calibration_data_min_length.
  • Multi-row items, e.g. tokenizer(texts, padding=True) rows, are judged by the padded width of the first row. Rows with 3 real tokens, or fully padded rows, pass the filter.
out = prepare_calibration_dataset(qm, [{"input_ids": torch.tensor([[7,7,7]+[0]*30]), "attention_mask": torch.tensor([[1,1,1]+[0]*30])}], calibration_data_min_length=10)
print(len(out), int(out[0]["attention_mask"].sum()))   # 1 3  -> kept with 3 real tokens

Expected: filter per row on attention_mask.sum().

3. Validation gaps

  • An unknown calibration_sort (e.g. "descending") silently falls back to native order (:619-638). Valid values are asc, desc and shuffle.
  • These raise "must contain only integers" (:384-390), while the equivalent numpy array or tensor is accepted:
    • a list of np.int64 (list(np_array));
    • a list of torch scalars;
    • a nested [[ids]] sample.
  • A torch.empty(0, N) sample raises a bare IndexError: list index out of range (:498).
  • calibration_sort="shuffle" uses the unseeded global random.shuffle (:635) and there is no seed argument.

Found during an AI-assisted review (Claude Code) of 9dad249; repros were run 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