Align ORPO with DPO: support iterable and dict eval datasets
ORPOTrainer prepares its datasets in __init__ with .map(..., num_proc=...), which fails on two inputs that DPOTrainer already accepts:
1. IterableDataset (streaming). IterableDataset.map() does not accept num_proc, so training on a streaming dataset fails immediately:
TypeError: IterableDataset.map() got an unexpected keyword argument 'num_proc'
2. dict eval_dataset. Passing multiple eval datasets as a dict calls .map() on the dict itself:
AttributeError: 'dict' object has no attribute 'map'
Dataset preparation is factored into a _prepare_dataset helper (mirroring DPOTrainer): num_proc is only passed for map-style Datasets, and a dict eval_dataset is prepared per key. For iterable datasets the raw (string) columns are dropped during tokenization, because streaming batches are passed through accelerate's find_batch_size, which only handles tensors. Regular datasets keep those columns since generate_during_eval relies on them (and that path — which needs select / len — isn't available for iterable datasets anyway).
Verification
- Added
test_train_with_iterable_dataset(streaming=True) andtest_train_with_multiple_eval_dataset(dicteval_dataset). Both fail onmainwith the errors above and pass with this change. - Full
tests/experimental/test_orpo_trainer.pypasses locally (RTX 4080);ruff check/ruff format --checkclean.
[!NOTE] Low Risk Changes are confined to dataset preparation and Accelerate config defaults in ORPOTrainer, with regression tests; core ORPO loss/training logic is unchanged.
Overview ORPOTrainer dataset setup is refactored to match DPOTrainer: preparation lives in
_prepare_dataset, which only passesnum_procfor map-styleDatasets so streamingIterableDatasettraining no longer breaks on.map(..., num_proc=...).For iterable training,
dispatch_batchesis forced toFalse(with a warning if it wasTrue), and tokenization drops raw string columns so Accelerate’s batch handling only sees tensors. Eval now accepts adictof datasets; each entry is prepared separately instead of calling.mapon the dict.Tests cover streaming train and multi-key eval (
eval_data1_loss/eval_data2_lossin logs).Reviewed by Cursor Bugbot for commit 13bdeafbb2fdd3cea122e0f2360e014e0895166d. Bugbot is set up for automated code reviews on this repo. Configure here.