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

Scale loss before backward #35207

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

qgallouedec
Copy link
Member

What does this PR do?

Fixes huggingface/trl#2456

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?

@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 qgallouedec marked this pull request as ready for review December 11, 2024 11:15
Copy link
Contributor

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

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

This one feels more like the right solution. Do the slow tests pass under this? (There is one in there for grad accum)

Copy link
Contributor

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

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

Yes because in reality this is exactly the right solution: since we are no longer relying on accelerate to div the loss, we need to do so before backward() if we don't know our num items in the batch

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

LGTM !

@qgallouedec
Copy link
Member Author

qgallouedec commented Dec 11, 2024

Do the slow tests pass under this?

They pass locally. I get errors but I think they aren't related:

============================== short test summary info ==============================
FAILED tests/trainer/test_trainer.py::TrainerIntegrationTest::test_auto_batch_size_finder - AttributeError: 'DownloadConfig' object has no attribute 'use_auth_token'
FAILED tests/trainer/test_trainer.py::TrainerIntegrationTest::test_auto_batch_size_with_deepspeed - ModuleNotFoundError: No module named 'mpi4py'
FAILED tests/trainer/test_trainer.py::TrainerIntegrationTest::test_use_liger_kernel_patching - AssertionError: False is not true
FAILED tests/trainer/test_trainer_seq2seq.py::Seq2seqTrainerTester::test_finetune_bert2bert - TypeError: BertModel.forward() got an unexpected keyword argument 'num_items_in_batch'
======== 4 failed, 250 passed, 82 skipped, 89 warnings in 203.93s (0:03:23) =========

@qgallouedec
Copy link
Member Author

@ArthurZucker @muellerzr @SunMarc I'll let you merge when you think it's good.

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.

Probaly mistake in DPOTrainer when compute/log grad_norm
4 participants