Repository navigation
fix(calibration): accept an HF Dataset whatever display format it carries (#4882) - #4902
Merged
Merged
Conversation
…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.
This was referenced Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4882 (#4652 was incomplete).
What was wrong
prepare_calibration_datasetiterated an HFDatasetexactly as handed in(
list(calibration_dataset)), and the VLMsplit_calibration_datasetdid thesame. 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:
with_format("pandas")pandas.DataFramewith_format("arrow")pyarrow.Tablewith_format("arrow")[:]pyarrow.Table, whose iteration yieldsChunkedArraycolumnsNone/torch/numpy/pythonand their[:]slices worked.pandas[:]alsoworked because it is a top-level
DataFrame, which_frame_columnsalreadyhandled — which is why the existing
test_dataset_formats_unpack_into_token_rowspassed while the iterated shape was broken.
Fix
_hf_dataset_rows(dataset)— new helper inutils/calibration.py. Whenthe input is an HF
Dataset/IterableDataset, iteratedataset.with_format(None)so the rows are the documented python mappingsregardless of the caller's display format. Returns
Nonefor non-HF input,so the existing handling is unchanged.
_frame_columns()— accepts apyarrow.Tablethroughto_pydict().Such a table has
columnsbut noto_dict, so it previously fell throughto the iterable path where iteration yields
ChunkedArraycolumns.prepare_calibration_datasetand by the VLMsplit_calibration_dataset(models/definitions/_vlm_calibration.py), whichhad 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:Green, same host, with the fix:
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 attentionmasks are identical across all 24 combinations, not merely that they parse.
Tests
test_calibration_mapping_input.py::test_dataset_formats_unpack_into_token_rowsnow parametrizes
["numpy", "pandas", "torch", "arrow", "python", None]×{iterated, [:]}instead of only the[:]shape. This is the test thatshould have caught it.
test_calibration_mapping_input.py::test_dataset_text_column_format_is_tokenized_per_rowcovers a plain
textcolumn inpandas/arrow, both shapes.test_vlm_mapping_calibration_4308.py::test_split_calibration_dataset_ignores_the_dataset_display_formatcovers the VLM splitter directly, both shapes.
Regression run
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 checkpasses on all four changed files.Claim:
agent-11788dff99fd, workload311d4f31ceb6.