Bug: unpair IterableDatasetDict preference datasets
Reproduction
from datasets import Dataset, IterableDatasetDict
from trl import unpair_preference_dataset
dataset = IterableDatasetDict(
{
"train": Dataset.from_dict(
{
"prompt": ["p1", "p2"],
"chosen": ["c1", "c2"],
"rejected": ["r1", "r2"],
}
).to_iterable_dataset()
}
)
list(unpair_preference_dataset(dataset)["train"])
On current main at 6d484baed4db18c2799b9d5b32c2520cba6b4df2, the call raises:
ValueError: Column lengths mismatch: columns ['chosen', 'rejected'] have length [2, 2] while completion has length 4.
unpair_preference_dataset advertises IterableDatasetDict support, but only unwraps the column names for DatasetDict. For an IterableDatasetDict, column_names is a split-to-columns mapping, so the underlying iterable map does not remove the original chosen and rejected columns before _unpair_row doubles the batch size.
Expected behavior
Each split of an IterableDatasetDict should unpair successfully, returning the doubled prompt, completion, and label rows (and duplicated extra columns) just like DatasetDict and IterableDataset inputs.
System Info
- Platform: macOS-26.5.2-arm64-arm-64bit
- Python version: 3.11.15
- TRL revision: current
mainat6d484baed4db18c2799b9d5b32c2520cba6b4df2 - PyTorch version: 2.13.0
- accelerator(s): cpu
- Transformers version: 5.15.1
- Datasets version: 5.0.1
Checklist
- [x] I have checked that my issue isn't already filed (see open issues)
- [x] I have included my system information
- [x] Any code provided is minimal, complete, and reproducible (more on MREs)
- [x] Any code provided is properly formatted in code blocks, (no screenshot, more on code blocks)
- [x] Any traceback provided is complete
@YZJF @DaoyuanLi2816 Is this issue open to contribute? If Yes I would like to go through the PRs and work on it?
Closing, same as #6970: this is a code path that can be reached, not a problem someone hit. No trainer passes an IterableDatasetDict here (KTO unpairs each split on its own), it fails loudly, and unpairing the split works: unpair_preference_dataset(dataset["train"]).