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

Fix FSDP error #1196

Merged

Conversation

mgerstgrasser
Copy link
Contributor

This fixes an error in reward training when the loss field of model output is non-empty, and model(...)[0] returns loss instead of logits. That can happen with FSDP. This PR changes it so the trainer explicitly grabs model(...)["logits"] instead.

Closes #1195

Fixes error when `loss` field of model output is non-empty, and indexing as [0] returns loss instead of logits. Can happen with FSDP.
Copy link
Contributor

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the fix, I propose to force-set return_dict=True in case users train their RM with return_dict being explicitly set to False in the config. Can you try that out? 🙏

trl/trainer/reward_trainer.py Show resolved Hide resolved
trl/trainer/reward_trainer.py Show resolved Hide resolved
@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.

@mgerstgrasser mgerstgrasser force-pushed the fix_reward_trainer_FSDP_error branch from c9ed225 to 989f4a4 Compare January 9, 2024 17:11
force return_dict

Co-authored-by: Younes Belkada <[email protected]>
@mgerstgrasser
Copy link
Contributor Author

Thanks a lot for the fix, I propose to force-set return_dict=True in case users train their RM with return_dict being explicitly set to False in the config. Can you try that out? 🙏

Yes, that works! Thanks for spotting that.

Copy link
Contributor

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

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

Thanks again for all your contributions @mgerstgrasser ! You are on fire!

@younesbelkada younesbelkada merged commit baf3c1c into huggingface:main Jan 9, 2024
9 checks passed
lapp0 pushed a commit to lapp0/trl that referenced this pull request May 10, 2024
* Fix FSDP error

Fixes error when `loss` field of model output is non-empty, and indexing as [0] returns loss instead of logits. Can happen with FSDP.

* Apply suggestions from code review

force return_dict

Co-authored-by: Younes Belkada <[email protected]>

---------

Co-authored-by: Younes Belkada <[email protected]>
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.

RewardTrainer fails with FSDP
3 participants