Skip to content

[BUG][calibration] Over-long left-padded rows keep their padding and drop real tokens; a heavily padded row becomes all padding (regression of #4008) #4238

Closed

Description

@Qubitium

Severity: medium
Version: 7.11.0 @ 9dad249. The repo test tests/test_prepare_dataset.py::test_prepare_dataset_trims_left_padded_rows_from_the_left_edge fails at HEAD.

Summary

utils/calibration.py:472-490 cuts rows longer than max_position_embeddings purely by truncation_side (default right), as row_ids[:max_positions], ignoring the attention mask.

Reproduce

import types, torch
from gptqmodel.utils.calibration import prepare_calibration_dataset
class Tok: pad_token_id = 0; padding_side = "left"; truncation_side = "right"
qm = types.SimpleNamespace(tokenizer=Tok(), model=types.SimpleNamespace(config=types.SimpleNamespace(max_position_embeddings=4)), support_batch_quantize=True)
for ids, m in [([[0,0,11,12,13,14]], [[0,0,1,1,1,1]]), ([[0,0,0,0,0,0,11,12]], [[0,0,0,0,0,0,1,1]])]:
    out = prepare_calibration_dataset(qm, [{"input_ids": torch.tensor(ids), "attention_mask": torch.tensor(m)}], calibration_data_min_length=0)
    print(out[0]["input_ids"].tolist(), out[0]["attention_mask"].tolist())
# [[0, 0, 11, 12]] [[0, 0, 1, 1]]     expected [[11, 12, 13, 14]]
# [[0, 0, 0, 0]]   [[0, 0, 0, 0]]     expected [[11, 12]]

Expected

Strip padding (by mask) before applying the position budget, then truncate the real tokens by truncation_side. Never emit an all-pad row.

Related: #4008 (closed; introduced the truncation_side logic), #4194.


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.

Activity

  1. added
    bug
    on Nov 16, 2026
  2. added a commit that references this issue on Nov 16, 2026
    1104081
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