Support DatasetDict and IterableDatasetDict as eval_dataset in trainers#6322
Merged
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
This was referenced Jul 8, 2026
qgallouedec
approved these changes
Jul 8, 2026
Comment on lines
+486
to
+489
| per_device_train_batch_size=3, # reduce the batch size to reduce memory usage | ||
| per_device_eval_batch_size=3, # reduce the batch size to reduce memory usage | ||
| num_generations=3, # reduce the number of generations to reduce memory usage | ||
| max_completion_length=8, # reduce the completion length to reduce memory usage |
Member
There was a problem hiding this comment.
nit: we're just initializing here, so these memory reduction trick could be removed
bfead47 to
7d827df
Compare
1 task
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.
This PR adds explicit support for passing a
DatasetDictorIterableDatasetDictaseval_datasetwhen initializing the stable trainers (SFT, DPO, KTO, Reward, GRPO, RLOO).This PR adds and tests support for passing
DatasetDictandIterableDatasetDictobjects as evaluation datasets (eval_dataset) to all TRL trainers, not just plain dictionaries or datasets. This makes it easier to use the raw output ofload_datasetfor evaluation, including both map-style and streaming datasets where supported. The tests are updated to cover these cases, and the trainer docstrings and type annotations are updated accordingly. For trainers that do not support streaming (IterableDatasetDict), explicit error handling is added.Motivation
load_datasetreturns aDatasetDict(or anIterableDatasetDictwhen streaming) whenever no split is specified, so users commonly hold these types. They already flowed through at runtime because both subclass dict, but the trainers neither declared nor documented them, so the support was implicit and untested.Solution
The
eval_datasetparameter of each stable trainer's__init__now acceptsDatasetDictandIterableDatasetDictexplicitly, in its type annotation and docstring. Each split keeps being prepared independently at initialization. GRPO and RLOO still do not support streaming datasets, so anIterableDatasetDictraises the existing informative error.Changes
DatasetDictand anIterableDatasetDicteval dataset are accepted and prepared per splitIterableDatasetDicteval dataset with a clear errorDetailed changes
Trainer support for
DatasetDictandIterableDatasetDictas eval datasets:DPOTrainer,KTOTrainer,RewardTrainer,SFTTrainer,GRPOTrainer,RLOOTrainer) now accepteval_datasetas aDatasetDictorIterableDatasetDict, in addition to the previously supported types. The relevant type annotations and docstrings are updated for clarity.Expanded and improved test coverage:
New and updated tests in all trainer test files verify initialization and behavior when
eval_datasetis aDatasetDictorIterableDatasetDict, including checks that splits are tokenized independently and that keys are handled as expected.For trainers that do not support streaming datasets (
GRPOTrainer,RLOOTrainer), tests are added to ensure that passing anIterableDatasetDictraises a clearNotImplementedError.Consistency and minor imports cleanup:
DatasetDictandIterableDatasetDictwhere needed for clarity and consistency.This change improves the flexibility and robustness of evaluation dataset handling in TRL trainers, especially for users working with Hugging Face Datasets in both map-style and streaming modes.
Note
Low Risk
Mostly annotations, docs, and tests; no new eval preparation logic in the diff.
Overview
Stable trainers (SFT, DPO, KTO, Reward, GRPO, RLOO) now document and type
eval_datasetas accepting Hugging FaceDatasetDictandIterableDatasetDict, not only plaindictor single datasets—matching commonload_datasetoutputs without a split.Imports and
__init__annotations/docstrings are updated across those trainers; behavior for multi-split eval (each split prepared at init) is unchanged but now covered by tests (map and streaming where supported). GRPO and RLOO tests assertIterableDatasetDictstill raises the existing streamingNotImplementedError.Reviewed by Cursor Bugbot for commit d76596c. Bugbot is set up for automated code reviews on this repo. Configure here.