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

Enable Gradient Accumulation fix across all models + trainer fully in forward() #34283

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

muellerzr
Copy link
Contributor

What does this PR do?

Since most users still want OOTB, this trickles the loss kwargs to the rest of the models so that causal loss can be calculated properly

Fixes # (issue)

Fully fixes #34263 / finishes #34191 & #34198

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?

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.

@ArthurZucker

@muellerzr muellerzr added Core: Modeling Internals of the library; Models. trainer labels Oct 21, 2024
Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Nice, I don't see Llama being modified, that's probably because it now has FlashAttentionKwargs type dict as kwargs. We can create ExtraKwargs, a nested dict with both flash kwargs and loss kwargs and default loss kwargs can be type dict?
🤗

@muellerzr
Copy link
Contributor Author

@ArthurZucker LlamaForCausalLM isn't there bc you did it in your PR 😉

@@ -3610,8 +3612,11 @@ def compute_loss(self, model, inputs, return_outputs=False, num_items_in_batch=N
labels = inputs.pop("labels")
else:
labels = None
# if num_items_in_batch is not None:
# inputs["num_items_in_batch"] = num_items_in_batch
if self.model_accepts_loss_kwargs:

Choose a reason for hiding this comment

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

This if condition doesn't seem to work for PeftModel class (it only has kwargs not loss_kwargs 🫠 )

I tried just changing that condition to if True and ran some tests, and the loss calculation worked perfectly for a LORA on a Llama 3 1B.

I'm wondering if there's a safe/non-breaking way to support peft models here as well?

@man-shar
Copy link

Awesome work by all of you on this. Insane dev speed over the past few days 🙏 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core: Modeling Internals of the library; Models. trainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New GA fix causes training loss multiple times higher across the board (5x to 10x higher)
3 participants