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

Before update the tr_loss, make sure tr_loss_step is in the same device. #1439

Merged

Conversation

pengwei715
Copy link
Contributor

@pengwei715 pengwei715 commented Mar 18, 2024

What does this PR do?

Fixes: #958
Fixes: #1399

It's a very strong assumption that tr_loss and tr_loss_step are on the same device. arg.device may not be as same as the current device.

For example, the dpo_trainer is child class of trainer. If you are running a DPO training job with one node multiple GPUs. If you set the device_map='auto'. The tr_loss_step could be on different device after computing the dpo_loss.

Based on the feedback of @guy1992l, @younesbelkada, @amyeroberts, I have open a PR in the transformers Trainer class to do a assert checking.

huggingface/transformers#29695

This PR is put the tr_loss_step to the self.args.device before update.

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 or the forum? 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, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@younesbelkada
@amyeroberts
@guy1992l

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
Contributor

@guy1992l guy1992l left a comment

Choose a reason for hiding this comment

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

a suggestion

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

Great ! Thanks so much @pengwei715 @guy1992l !

@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.

@younesbelkada younesbelkada requested a review from kashif March 19, 2024 09:24
@younesbelkada
Copy link
Contributor

just double checking @kashif is this all good in your opinion?

@younesbelkada younesbelkada merged commit f976c6d into huggingface:main Mar 19, 2024
9 checks passed
lapp0 pushed a commit to lapp0/trl that referenced this pull request May 10, 2024
…ce. (huggingface#1439)

* before update the loss from dpo, make sure it's in the same device of tr_loss

* Update trl/trainer/dpo_trainer.py

Co-authored-by: guy1992l <[email protected]>

---------

Co-authored-by: guy1992l <[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
5 participants