Handle num_items_in_batch in Mistral's forward#34576
Open
gheinrich wants to merge 1 commit intohuggingface:mainfrom
Open
Handle num_items_in_batch in Mistral's forward#34576gheinrich wants to merge 1 commit intohuggingface:mainfrom
gheinrich wants to merge 1 commit intohuggingface:mainfrom
Conversation
This PR enables handling loss keyword arguments in the Mistral forward() method. Specifically, if `num_items_in_batch` is passed, the value is used to properly normalize the loss value. This relates to the Gradient Accumulation fix (huggingface#34191) Fixes huggingface#34575
adf418a to
a4faa09
Compare
Member
|
cc @muellerzr for the GA fix as well! |
Collaborator
ArthurZucker
left a comment
There was a problem hiding this comment.
Hey! This is not how we fixed it for other models 😉
see
transformers/src/transformers/models/llama/modeling_llama.py
Lines 1181 to 1183 in 820be50
Author
|
Hello, other models have the loss function defined in a parent class. Mistral models have it defined in the |
Collaborator
|
You need to pretty much copy-paste the code in Llama / other models 🤗 The parent class is the same for Mistral as well |
Contributor
|
Will be superseded/fulfilled with #35875 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR enables handling loss keyword arguments in the Mistral model's
forward()method.Specifically, if
num_items_in_batchis passed, the value is used to properly normalize the loss value.This relates to the Gradient Accumulation fix (#34191)
Fixes #34575
cc @ArthurZucker as it relates to text models.