Repository navigation
Description
Found on main @ 597b39b, RTX 4090 host (CPU-only repro, real tokenizers).
What is wrong
prepare_calibration_dataset (gptqmodel/utils/calibration.py) mishandles two common tabular containers that hold exactly the columns it accepts.
-
A column-major mapping with NumPy object columns crashes.
Dataset.with_format("numpy")[:](and{"input_ids": np.array(list_of_ragged_arrays, dtype=object)}) stores each column as a 1-Dndarrayofdtype=object._is_batched_column(:140-161) checksndimfirst and returnsndim >= 2, so the 1-D object array is classed as one token row._to_2d_long_tensorthen fails:
ValueError: Quantize: failed to convert input_ids to tensor for calibration item 0(cause:can't convert np.ndarray of type numpy.object_).
The same data works aswith_format("torch")[:], aswith_format(None)[:], astok(texts, return_tensors="np", padding=True), and as a list of 1-D arrays. Only the object-dtype column fails, and the message points at the data instead of the container. -
A
pandas.DataFramecalibrates on its column names. A DataFrame is not aMapping, so it reachesraw_examples = list(calibration_dataset)(:391). Iterating a DataFrame yields its column labels, so every label becomes one raw text row:- With the default
calibration_data_min_length=10, the 1-3-token label rows are dropped and the run fails with the misleading "every input_ids was shorter than calibration_data_min_length" error. - With a small
calibration_data_min_length, it silently quantizes on the literal text"text"(or"input_ids","attention_mask").Dataset.with_format("pandas")[:]andds.to_pandas()return such a DataFrame.
- With the default
Repro
import types, numpy as np, pandas as pd
from transformers import AutoTokenizer, AutoConfig
from datasets import Dataset
from gptqmodel.utils.calibration import prepare_calibration_dataset
P = "Qwen/Qwen2.5-0.5B-Instruct"
tok = AutoTokenizer.from_pretrained(P)
q = types.SimpleNamespace(tokenizer=tok, model=types.SimpleNamespace(config=AutoConfig.from_pretrained(P)),
support_batch_quantize=True)
texts = ["The quick brown fox jumps over the lazy dog. " * 3,
"Hello world, this is a calibration sample with some words in it."]
ds = Dataset.from_dict({"text": texts}).map(lambda x: tok(x["text"]), remove_columns=["text"])
for fmt in ("torch", "numpy"):
try:
print(fmt, [int(b["attention_mask"].sum()) for b in prepare_calibration_dataset(q, ds.with_format(fmt)[:])])
except Exception as e:
print(fmt, type(e).__name__, e, "|", repr(e.__cause__)[:80])
b = prepare_calibration_dataset(q, pd.DataFrame({"text": texts * 3}), calibration_data_min_length=0)
print(len(b), [tok.decode(x["input_ids"][0]) for x in b])Output:
torch [31, 14]
numpy ValueError Quantize: failed to convert `input_ids` to tensor for calibration item 0. | TypeError("can't convert np.ndarray of type numpy.object_ ...
1 ['text'] # 6 documents -> one 1-token row, the column label (Llama tokenizer: '<|begin_of_text|>text')
Suggested fix
_is_batched_column: treat a 1-Dnp.ndarraywithdtype=object(andpandas.Series) as a column of rows, then convert each element on its own. In_columnar_mapping_examples, index such columns element-wise.- Treat a
pandas.DataFrame(any object with.to_dict("list")/.columns) as a columnar mapping. Alternatively reject it with a clear error, instead of iterating it as an iterable of strings.
Test that should have caught it
tests/test_calibration_mapping_input.py covers lists and tensors only. Add ds.with_format("numpy")[:] and a DataFrame case.
Severity
Low. Item 1 is a crash with a misleading message. Item 2 is silent only with a lowered calibration_data_min_length; under defaults it is a misleading error.
🤖 Generated with Claude Code
Activity
ZX-ModelCloud commentedon Nov 17, 2026
Claimed. I'm working on this issue and will submit a fix PR. Please avoid duplicate work in the meantime.
fix(calibration): unpack DataFrame and NumPy object columns into rows (…
fix(calibration): accept an HF Dataset whatever display format it car…