Skip to content

[GRPO] Reference model initialization bug fix #3397

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

Merged
merged 1 commit into from
May 1, 2025

Conversation

LeonEricsson
Copy link
Collaborator

@LeonEricsson LeonEricsson commented May 1, 2025

What does this PR do?

The existing issue

The current check for if FSDP is enabled is incorrect

elif is_deepspeed_zero3_enabled() or args.fsdp_config is not None:

as the fsdp_config is always post initialized to a dictionary. You can easily test this with

from trl import GRPOConfig, GRPOTrainer, TrlParser


model_name_or_path = "Qwen/Qwen2.5-0.5B-Instruct"
parser = TrlParser(GRPOConfig)
(training_args,) = parser.parse_args_into_dataclasses()

trainer = GRPOTrainer(model=model_name_or_path, reward_funcs=[], args=training_args)

and printing the ref_model

Solution

I propose to move the ref_model initialization till after Trainer has been initialized, leaving the check to Accelerate, and then using self.is_fsdp_enabled. But I am open to alternatives, we could use args.fsdp, or the ACCELERATE_USE_FSDP environment variable.

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?
  • 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.

@LeonEricsson
Copy link
Collaborator Author

LeonEricsson commented May 1, 2025

@kashif is there something I missed in #3260?

@kashif
Copy link
Collaborator

kashif commented May 1, 2025

yes that looks good!

@LeonEricsson LeonEricsson marked this pull request as ready for review May 1, 2025 08:54
@kashif kashif merged commit 13fa840 into huggingface:main May 1, 2025
6 checks passed
@shivam15s shivam15s mentioned this pull request May 1, 2025
5 tasks
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