Skip to content

Add missing ModelOutput subclass return type hints#41219

Merged
vasqu merged 3 commits intohuggingface:mainfrom
tomaarsen:chore/return_type_hints
Dec 16, 2025
Merged

Add missing ModelOutput subclass return type hints#41219
vasqu merged 3 commits intohuggingface:mainfrom
tomaarsen:chore/return_type_hints

Conversation

@tomaarsen
Copy link
Member

What does this PR do?

This PR adds missing ModelOutput subclass return type hints. I'm running an analysis on the Model classes to see what kind of outputs are used for the various modalities, and I noticed a handful of architectures were missing them.

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

  • Tom Aarsen

@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.

@github-actions
Copy link
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: dac, deepseek_vl, deepseek_vl_hybrid, flava, grounding_dino, janus, maskformer, mm_grounding_dino, tvp, udop

@tomaarsen
Copy link
Member Author

I fixed the merge conflicts. I totally forgot about this PR, but it should still be valuable to improve the typings somewhat.

  • Tom Aarsen

Copy link
Contributor

@vasqu vasqu left a comment

Choose a reason for hiding this comment

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

LGTM, I'm just wondering whether you only want to target the base model with this PR / how consistent this needs to be, e.g.

class MMGroundingDinoForObjectDetection(MMGroundingDinoPreTrainedModel):
has no output type

@tomaarsen
Copy link
Member Author

@vasqu The script I wrote to check the type hints indeed only checked the base models, also because Sentence Transformers will in the future rely on the type hints of the base models. Extending it to the non-base classes would be nice, but I don't have the bandwidth for that now, as I'm aiming to get #42564 ready before the full v5.

  • Tom Aarsen

@vasqu
Copy link
Contributor

vasqu commented Dec 16, 2025

Gotcha, makes sense then. Let's merge, having more typing is better than nothing in the first place

@vasqu vasqu merged commit 6c7c992 into huggingface:main Dec 16, 2025
21 checks passed
SangbumChoi pushed a commit to SangbumChoi/transformers that referenced this pull request Jan 23, 2026
* Add missing ModelOutput subclass return type hints

* Fix incorrect type hint: FlavaOutput (nn.Module subclass) -> FlavaModelOutput
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