Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌊 Add error for iterable datasets in GRPOTrainer #3216

Merged
merged 2 commits into from
Apr 5, 2025

Conversation

qgallouedec
Copy link
Member

@qgallouedec qgallouedec commented Apr 2, 2025

What does this PR do?

See #3213

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a check in GRPOTrainer to raise an error when using iterable datasets, ensuring that only standard datasets are accepted.

  • Added a conditional block to detect IterableDataset usage in both train and evaluation datasets.
  • Provides a clear error message including a reference to an existing issue for context.
Comments suppressed due to low confidence (2)

trl/trainer/grpo_trainer.py:410

  • Please add unit tests that verify that providing an IterableDataset (and dicts containing IterableDatasets) to the trainer results in the proper NotImplementedError being raised.
if (

trl/trainer/grpo_trainer.py:418

  • Consider enhancing the error message with guidance or a link to the documentation for converting iterable datasets into a supported format, to help users resolve the issue.
raise NotImplementedError(

@qgallouedec qgallouedec requested a review from shirinyamani April 2, 2025 18:33
@HuggingFaceDocBuilderDev

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
Copy link
Member Author

import tempfile
from datasets import load_dataset
from trl import GRPOConfig, GRPOTrainer

dataset = load_dataset("trl-internal-testing/zen", "standard_prompt_only", split="train").to_iterable_dataset()

def dummy_reward_func(completions, **kwargs):
    return [0.0] * len(completions)

with tempfile.TemporaryDirectory() as tmp_dir:
    training_args = GRPOConfig(
        output_dir=tmp_dir,
        learning_rate=0.1,  # increase the learning rate to speed up the test
        per_device_train_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=32,  # reduce the completion length to reduce memory usage
        report_to="none",
    )
    trainer = GRPOTrainer(
        model="trl-internal-testing/tiny-Qwen2ForCausalLM-2.5",
        reward_funcs=dummy_reward_func,
        args=training_args,
        train_dataset=dataset,
    )
Traceback (most recent call last):
  File "/fsx/qgallouedec/trl/tests/test_raise.py", line 20, in <module>
    trainer = GRPOTrainer(
              ^^^^^^^^^^^^
  File "/fsx/qgallouedec/trl/trl/trainer/grpo_trainer.py", line 418, in __init__
    raise NotImplementedError(
NotImplementedError: Iterable datasets are not yet supported in GRPOTrainer. Please use a standard dataset instead.

@qgallouedec qgallouedec changed the title Add error for iterable datasets in GRPOTrainer 🌊 Add error for iterable datasets in GRPOTrainer Apr 2, 2025
@wilrop wilrop mentioned this pull request Apr 3, 2025
5 tasks
@qgallouedec qgallouedec enabled auto-merge (squash) April 5, 2025 22:40
@qgallouedec qgallouedec merged commit 31b54a6 into main Apr 5, 2025
8 of 10 checks passed
@qgallouedec qgallouedec deleted the raise-error-iterable branch April 5, 2025 22:41
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.

2 participants