Skip to content

fix(calibration): accept an HF Dataset whatever display format it carries (#4882) - #4902

Merged
Qubitium merged 1 commit into
mainfrom
fix/calibration-hf-dataset-format
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/calibration-hf-dataset-format

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4882 (#4652 was incomplete).

What was wrong

prepare_calibration_dataset iterated an HF Dataset exactly as handed in
(list(calibration_dataset)), and the VLM split_calibration_dataset did the
same. What iteration yields is decided by the format the caller last set on
the dataset, so a dataset that is otherwise identical was accepted or rejected
depending only on that format:

input iteration yields before
with_format("pandas") one-row pandas.DataFrame rejected
with_format("arrow") one-row pyarrow.Table rejected
with_format("arrow")[:] one pyarrow.Table, whose iteration yields ChunkedArray columns rejected

None/torch/numpy/python and their [:] slices worked. pandas[:] also
worked because it is a top-level DataFrame, which _frame_columns already
handled — which is why the existing test_dataset_formats_unpack_into_token_rows
passed while the iterated shape was broken.

Fix

  1. _hf_dataset_rows(dataset) — new helper in utils/calibration.py. When
    the input is an HF Dataset/IterableDataset, iterate
    dataset.with_format(None) so the rows are the documented python mappings
    regardless of the caller's display format. Returns None for non-HF input,
    so the existing handling is unchanged.
  2. _frame_columns() — accepts a pyarrow.Table through to_pydict().
    Such a table has columns but no to_dict, so it previously fell through
    to the iterable path where iteration yields ChunkedArray columns.
  3. Both helpers are now used by prepare_calibration_dataset and by the VLM
    split_calibration_dataset (models/definitions/_vlm_calibration.py), which
    had the same gap for the same reason.

No row content, ordering or tokenization changes: the format is cleared, the
rows are the ones the caller already passed.

Red / green

Red, origin/main @ d8758c4, library unchanged:

$ python repro_4882c.py            # 24 format x shape combinations
FAIL text/pandas/iterated: ValueError: Quantize: unsupported calibration example type <class 'pandas.DataFrame'> at index 0.
FAIL text/arrow/iterated:  ValueError: Quantize: unsupported calibration example type <class 'pyarrow.lib.Table'> at index 0.
FAIL text/arrow/sliced:    ValueError: Quantize: unsupported calibration example type <class 'pyarrow.lib.ChunkedArray'> at index 0.
FAIL ids/pandas/iterated:  ...
FAIL ids/arrow/iterated:   ...
FAIL ids/arrow/sliced:     ...
FAILS: 6

$ pytest test_calibration_mapping_input.py test_vlm_mapping_calibration_4308.py -q
9 failed, 103 passed

Green, same host, with the fix:

$ python repro_4882c.py
24/24 OK, FAILS: 0     # every combination token-identical to with_format(None)

$ pytest test_calibration_mapping_input.py test_vlm_mapping_calibration_4308.py -q
112 passed

The 6 repro failures are exactly the rows the issue lists. The oracle is the
with_format(None) row set: the repro asserts the token ids and attention
masks are identical across all 24 combinations, not merely that they parse.

Tests

  • test_calibration_mapping_input.py::test_dataset_formats_unpack_into_token_rows
    now parametrizes ["numpy", "pandas", "torch", "arrow", "python", None] ×
    {iterated, [:]} instead of only the [:] shape. This is the test that
    should have caught it.
  • test_calibration_mapping_input.py::test_dataset_text_column_format_is_tokenized_per_row
    covers a plain text column in pandas/arrow, both shapes.
  • test_vlm_mapping_calibration_4308.py::test_split_calibration_dataset_ignores_the_dataset_display_format
    covers the VLM splitter directly, both shapes.

Regression run

$ pytest <18 calibration + VLM test modules> -q
388 passed, 1 warning in 67.74s

Files: test_calibration_{mapping_input,input_gaps_4311,normalisation,windows,padding_mask,text_and_ids_precedence_4635,messages_ids_precedence_4670,truncation,attention_sinks,config,special_tokens_4191,empty_text_4306}.py,
test_vlm_{mapping_calibration_4308,calibration_metadata_columns_4455,pretokenized_calibration,multimodal_calibration_4371}.py,
test_multimodal_{calibration_replay,modality_calibration}.py.

ruff check passes on all four changed files.

Claim: agent-11788dff99fd, workload 311d4f31ceb6.

…ries (#4882)

prepare_calibration_dataset and the VLM splitter iterated an HF Dataset as
handed in. Iteration yields whatever format the caller last set, so a dataset
left in with_format("pandas") produced one-row DataFrames, one left in
with_format("arrow") produced one-row Tables, and a plain HF Dataset was
rejected purely because of that format (#4652 fixed only the numpy and
top-level-DataFrame shapes).

- _hf_dataset_rows() clears the display format before iterating, so the rows
  are the same python mappings the caller documented.
- _frame_columns() now reads a pyarrow Table through to_pydict(). The arrow
  slice was doubly broken: the Table has columns but no to_dict, so it fell
  through to iteration, which yields one ChunkedArray per column.
- Both are used by prepare_calibration_dataset and by the VLM
  split_calibration_dataset, which had the same gap.

Tests: every datasets format (None/torch/numpy/python/pandas/arrow) in both
shapes (iterated and [:]) must reach the same token rows, and the same matrix
for split_calibration_dataset. 9 of the new cases fail before this change and
all 112 pass after it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant