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

Fix model_accepts_loss_kwargs for timm model #35257

Merged
merged 3 commits into from
Dec 27, 2024

Conversation

qubvel
Copy link
Member

@qubvel qubvel commented Dec 13, 2024

What does this PR do?

TimmWrapper model training is broken due to the num_items_in_batch param passed to the model forward. TimmWrapper model has **kwargs in the transformers model forward, but it goes straight to the timm model and not to the loss. This PR introduces a fix to avoid passing loss_kwargs even if **kwargs are in model forward.

Relevant to:

cc @ArthurZucker

@qubvel qubvel requested a review from ArthurZucker December 13, 2024 11:53
@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.

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.

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.

@qubvel
Copy link
Member Author

qubvel commented Dec 17, 2024

@ArthurZucker Do you mean to move it to the PretrainedModel level?

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_kwargs

And then in modeling:

class MyModel(PreTrainedModel):
    _accept_loss_kwargs = False

@ArthurZucker
Copy link
Collaborator

No for now let's merge as is! Not sure we'll need the abstraction for more models!

@qubvel qubvel merged commit 5c75087 into huggingface:main Dec 27, 2024
25 checks passed
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.

3 participants