Fix model_accepts_loss_kwargs for timm model#35257
Merged
qubvel merged 3 commits intohuggingface:mainfrom Dec 27, 2024
Merged
Conversation
|
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. |
ArthurZucker
approved these changes
Dec 17, 2024
Collaborator
ArthurZucker
left a comment
There was a problem hiding this comment.
Okay, I think we might want to document accepts_loss_kwargs as it's scope right now is super small.
This can't be set to True by default, we can just add a property that checks the forward signature, unless _accept_loss_kwargs is set to false.
Contributor
Author
|
@ArthurZucker Do you mean to move it to the class PreTrainedModel:
_accept_loss_kwargs = None
@property
def accepts_loss_kwargs(self):
if self._accept_loss_kwargs is not None:
return self._accept_loss_kwargs
# otherwise check for signature here
...
return accept_loss_kwargsAnd then in modeling: class MyModel(PreTrainedModel):
_accept_loss_kwargs = False |
Collaborator
|
No for now let's merge as is! Not sure we'll need the abstraction for more models! |
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?
TimmWrappermodel training is broken due to thenum_items_in_batchparam passed to the model forward.TimmWrappermodel has**kwargsin thetransformersmodel forward, but it goes straight to thetimmmodel and not to the loss. This PR introduces a fix to avoid passing loss_kwargs even if**kwargsare in model forward.Relevant to:
trainer] fix the GAmodel_accepts_loss_kwargs#34915cc @ArthurZucker