You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] #4902 (fix of #4882) incomplete: a messages column from with_format("numpy")[:] / ("pandas")[:] collapses every conversation into one 21-token system-prompt-only row #4936
Found on main @ 3867c82, CPU (tokenizer-only path).
What is wrong
#4902 (fix of #4882) makes text and input_ids columns reach the same token rows in every HF datasets format, both iterated and sliced. A messages column sliced from a numpy- or pandas-formatted dataset (ds.with_format("numpy")[:], ds.with_format("pandas")[:]) is still mis-read. All conversations silently collapse into one row that renders only the template's default system prompt.
The cause is in _is_columnar_mapping (gptqmodel/utils/calibration.py:405-409):
In the numpy format, a messages column is a 2-D ndarray(dtype=object) of dicts when all conversations have the same number of turns, otherwise a 1-D object array of arrays. pandas gives a Series of ndarrays. In both cases entries[0] is an ndarray, not a list/tuple, so the mapping is classified as a single row. The whole column then goes to apply_chat_template as one "conversation", which renders as just the default system turn. The run logs no warning.
Repro (Qwen2.5-0.5B-Instruct tokenizer)
texts= [f"This is calibration sentence number {i} with enough words to pass the filter."foriinrange(6)]
msgs= [[{"role":"user","content":t},{"role":"assistant","content":"ok fine sure"}] + ([{"role":"user","content":"more"}] ifi%2else []) fori, tinenumerate(texts)]
ds=Dataset.from_dict({"messages": msgs})
prepare_calibration_dataset(q, [{"messages": m} forminmsgs], batch_size=1) # referenceprepare_calibration_dataset(q, ds.with_format("numpy")[:], batch_size=1)
prepare_calibration_dataset(q, ds.with_format("pandas")[:], batch_size=1)
(rows, real tokens)
reference list (6, 312)
numpy [:] (1, 21) decoded: '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n'
pandas [:] (1, 21)
The same happens with equal-length conversations (2-D object array): 294 expected, 21 calibrated. Every other format and shape gives 294 (None/torch/numpy/python/pandas/arrow, iterated, and [:] for None/torch/python/arrow). This is pre-existing at c41fa937c^ too, but #4902's stated contract ("every datasets format in both shapes must reach the same token rows") does not hold for messages.
Suggested fix
In _is_columnar_mapping and _columnar_mapping_examples, treat an ndarray/Series entry as a conversation: test getattr(entries[0], "ndim", 0) >= 1 or isinstance(entries[0], Sequence | np.ndarray). Convert each row's messages to a list of dicts (.tolist()) before apply_chat_template. A cheaper alternative: when the mapping has a messages column, raise if the "single row" conversation is not a list of mappings with role, instead of rendering an empty prompt.
Test that should have caught it
tests/test_calibration_mapping_input.py runs the format x shape matrix only for text/input_ids rows. Add a messages dataset to the same matrix.
Severity: medium. The calibration data is silently replaced by one system-prompt-only row (95-99% of the tokens are lost), and quantize then proceeds on it.
Finish #4902: a messages column read through with_format('numpy')[:] or ('pandas')[:] collapses every conversation (structured fields lost); normalize the container back to the row dicts the template expects and add tests for both formats.
Activity
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-53ba17eb4d83finished this issue.Pull request: #4991
Finish #4902: a messages column read through with_format('numpy')[:] or ('pandas')[:] collapses every conversation (structured fields lost); normalize the container back to the row dicts the template expects and add tests for both formats.
fix(calibration): keep `messages` conversations from numpy/pandas sli…
fix(calibration): drop Arrow's injected nulls from `messages` (#5082) (…