Pass num_items_in_batch directly to loss computation#36753
Merged
qubvel merged 9 commits intoMar 20, 2025
Conversation
Contributor
|
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. When it is ready for review, please click the |
eljandoubi
marked this pull request as ready for review
March 16, 2025 13:59
qubvel
reviewed
Mar 18, 2025
qubvel
left a comment
Contributor
There was a problem hiding this comment.
Thank you @eljandoubi for opening a PR and fixing the issue! Just a small nit
Comment on lines
+645
to
+649
| loss = fixed_cross_entropy( | ||
| logits.reshape(-1, self.decoder.config.vocab_size), | ||
| labels.reshape(-1), | ||
| num_items_in_batch=num_items_in_batch, | ||
| ) |
Contributor
There was a problem hiding this comment.
We can use instead, see llama for example. All reshape/view ops will happen under the hood
loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.vocab_size, num_items_in_batch=num_items_in_batch)
Contributor
There was a problem hiding this comment.
A bit different, there is no need to make view while passing to the function, see my example above
Contributor
Author
There was a problem hiding this comment.
@qubvel I've updated my code, what do you think about it now?
ArthurZucker
approved these changes
Mar 20, 2025
Contributor
|
Thanks @eljandoubi |
zucchini-nlp
pushed a commit
to zucchini-nlp/transformers
that referenced
this pull request
May 14, 2025
* Pass num_items_in_batch directly to loss computation * use self loss instead * fix loss kwrgs * fix vocab size
4 tasks
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?
Fixes #36744
Models: