Skip to content

Simplify get_train_dataloader in GRPO and RLOO#5276

Merged
albertvillanova merged 1 commit into
huggingface:mainfrom
albertvillanova:simplify-get-train-dataloader
Mar 13, 2026
Merged

Simplify get_train_dataloader in GRPO and RLOO#5276
albertvillanova merged 1 commit into
huggingface:mainfrom
albertvillanova:simplify-get-train-dataloader

Conversation

@albertvillanova

@albertvillanova albertvillanova commented Mar 12, 2026

Copy link
Copy Markdown
Member

Simplify get_train_dataloader in GRPO and RLOO.

This PR refactors the data loader creation logic in both the GRPOTrainer and RLOOTrainer classes to improve maintainability and reduce code duplication. The changes simplify the get_train_dataloader methods by delegating to a shared _get_dataloader function, and remove unused imports related to datasets and worker seeding.

Note that transformers.Trainer.get_train_dataloader is refactored since v4.54.1 and we support >=4.56.2:

Refactoring and maintainability improvements:

  • Simplified get_train_dataloader methods in both GRPOTrainer and RLOOTrainer by replacing custom logic with a call to the shared _get_dataloader function, making the code easier to maintain and reducing duplication.

Import cleanup:

  • Removed unused imports of datasets, DataLoader, partial, and seed_worker from both trainer files, as well as the is_datasets_available utility, since these are no longer needed after the refactor.

Note

Medium Risk
Touches the training input pipeline for GRPOTrainer and RLOOTrainer; while intended to be behavior-preserving, any mismatch with prior DataLoader params (sampler/drop_last/worker seeding) could subtly affect batching or reproducibility.

Overview
Refactors GRPOTrainer and RLOOTrainer get_train_dataloader to delegate dataloader construction to the shared Trainer._get_dataloader, keeping the custom generation batch sizing (_train_batch_size * steps_per_generation) but removing the copy-pasted DataLoader setup.

Cleans up now-unused imports (datasets, DataLoader, seed_worker, partial, is_datasets_available) and trims the associated maintenance note text.

Written by Cursor Bugbot for commit 01b88cd. This will update automatically on new commits. Configure here.

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

@qgallouedec qgallouedec left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@albertvillanova albertvillanova merged commit 556646a into huggingface:main Mar 13, 2026
12 checks passed
songhappy pushed a commit to songhappy/trl that referenced this pull request Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants