Skip to content

[BUG] concat_size packing runs after the per-row min_length filter and position-budget trim: short documents dropped (397/400 rows), long documents truncated before windowing #4892

Closed

Description

@Qubitium

Found on main @ 4f287eb, CPU (x86_64).

What is wrong

prepare_calibration_dataset applies two per-row policies before concat_size packing (gptqmodel/utils/calibration.py:796-898, then packing at :949-1051). Both are meant to protect unpacked rows, and both throw away data that packing would have used:

  1. min_length drops short documents before they are packed (:859-862). Packing exists to combine short samples into full windows, but every document of <= min_length (default 10) tokens is discarded first. On a dataset of short utterances, almost the whole corpus disappears. The warning blames the rows (Use CalibrationConfig(min_length=...)), not the combination with concat_size.
  2. The position-budget trim cuts a long document before it is split into windows (:827-846). A document longer than max_position_embeddings is truncated to that length, then packed into concat_size windows, which are all far below the budget. Everything past max_position_embeddings is lost with only an INFO line (trimmed 1 calibration rows above max_position_embeddings). A window can never exceed the budget as long as concat_size <= max_position_embeddings, so the trim is unnecessary on this path.

Meanwhile the packed windows themselves are never checked: the padded tail window is kept even with only a few real tokens, and concat_size > max_position_embeddings is not validated.

Repro (Qwen2.5-0.5B-Instruct tokenizer, max_position_embeddings=32768)

from gptqmodel.utils.calibration import prepare_calibration_dataset
short = [<400 random 3-9 word sentences>]            # 2807 tokens, max row 11 tokens
prepare_calibration_dataset(q, short, calibration_dataset_concat_size=256)                               # default min_length=10
prepare_calibration_dataset(q, short, calibration_dataset_concat_size=256, calibration_data_min_length=0)
prepare_calibration_dataset(q, [one_40000_token_doc], calibration_dataset_concat_size=2048)
rows 400 tokens 2807 max row 11
WARN  Quantize: 397 calibration rows with <= 10 non-padding tokens were removed. Use CalibrationConfig(min_length=...) ...
concat_size=256 min_length=10: windows=1 real tokens=33          <- 99% of the corpus dropped
concat_size=256 min_length=0:  windows=11 real tokens=2807
INFO  Quantize: trimmed 1 calibration rows above max_position_embeddings=32768 (longest original length=40000, truncation_side=right)
one 40000-token doc, concat_size=2048: windows=16 real tokens=32768 lost=7232

Suggested fix

When concat_size is set, skip the per-row min_length filter and the position-budget trim. Pack every real token first, then apply min_length to the packed windows (it then drops only a near-empty tail window). Validate concat_size <= max_position_embeddings up front instead. The non-concat path keeps its current per-row behaviour.

Test that should have caught it

tests/test_prepare_dataset.py concat cases use documents longer than min_length. Add a case with many sub-min_length documents and concat_size, asserting that every token is packed, and one with a document longer than max_position_embeddings.

Severity

Low-medium. Silent (or misattributed) loss of calibration data with concat_size. Short-utterance corpora are hit hardest (99% dropped in the repro); long-document corpora lose every token past max_position_embeddings.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-11788dff99fd finished this issue.

    Pull request: #4916

    concat_size: pack every real token before the per-row min_length/position-budget policies, apply min_length to the packed windows, validate concat_size <= max_position_embeddings up front

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions