Skip to content

fix(calibration): interpolate the item index in the unsupported-sequence error - #3017

Open
Anai-Guo wants to merge 1 commit into
ModelCloud:mainfrom
Anai-Guo:fix-calibration-fstring-idx
Open

fix(calibration): interpolate the item index in the unsupported-sequence error#3017
Anai-Guo wants to merge 1 commit into
ModelCloud:mainfrom
Anai-Guo:fix-calibration-fstring-idx

Conversation

@Anai-Guo

Copy link
Copy Markdown
Contributor

Problem

In prepare_calibration_dataset, the helper _tokenize_messages_value raises three
ValueErrors that all report which calibration item failed. Two of them are f-strings;
the middle one is a plain string literal, so its {idx} is emitted verbatim:

gptqmodel/utils/calibration.py

if templated is None:
    raise ValueError(f"tokenizer.apply_template returned None for calibration item {idx}.")   # L244  f-string
...
if isinstance(templated, (list, tuple)):
    if len(templated) > 0 and isinstance(templated[0], int):
        return _pack_ids(list(templated), None, idx)
    raise ValueError(
        "tokenizer.apply_template returned an unsupported sequence type for calibration item {idx}."  # L262  no f
    )
...
raise ValueError(
    f"tokenizer.apply_template returned unsupported type {type(templated)} for calibration item {idx}."  # L272  f-string
)

Rendering the two literals with idx = 3:

L244 (sibling) -> tokenizer.apply_template returned None for calibration item 3.
L262 (this fix) -> tokenizer.apply_template returned an unsupported sequence type for calibration item {idx}.

The index is the only actionable part of the message — it is what tells the user which
row of their calibration dataset to look at. This branch fires when a custom
apply_template returns a non-empty sequence whose first element is not an int
(e.g. a list of token strings), and the user is left without the item number.

Neither ruff nor flake8 flags this: F541 covers f-strings with no placeholders, not
the reverse.

Fix

Add the missing f prefix. One character, no behaviour change beyond the message text.

Note on AGENTS.md

AGENTS.md routes tokenizer/chat-template behaviour changes to Tokenicer. This patch
changes no tokenization, prompt rendering, or normalization logic — it only makes an
existing diagnostic interpolate the value it already names — so it stays in
GPT-QModel.

🤖 Generated with Claude Code

…nce error

The sibling raises in _tokenize_messages_value are f-strings; this one is not,
so it reports a literal {idx} instead of the calibration item number.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant