Skip to content

Reorder decorators for autodoc and dataclass#45702

Open
zucchini-nlp wants to merge 2 commits intohuggingface:mainfrom
zucchini-nlp:autodoc-model-output
Open

Reorder decorators for autodoc and dataclass#45702
zucchini-nlp wants to merge 2 commits intohuggingface:mainfrom
zucchini-nlp:autodoc-model-output

Conversation

@zucchini-nlp
Copy link
Copy Markdown
Member

@zucchini-nlp zucchini-nlp commented Apr 29, 2026

What does this PR do?

Uncovered when working on smth else, reorders the decorators as per title to make sure the docs are added in correct __init__

With current order we are checking/setting the __init__.__doc__ on parent's __init__ for model outputs which are always dataclasses. It is because decorators are applied from bottom upwards, and autodoc is the first decorator called (before dataclass)

Thus, a model output class (e.g. AriaCausalLMOutputWithPast) has no __init__ when trying to auto-add docstring and we generate/add/modify the docstring of ModelOutput.__init__

That also uncovered an empty docstring for PeAudioVideo, fixed that one

Comment on lines -280 to -285
@dataclass
class MoECausalLMOutputWithPast(ModelOutput):
"""
Base class for causal language model (or autoregressive) outputs as well as Mixture of Expert's router hidden
states terms, to train a MoE model.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

was defined twice, and this one is not used anywhere in codebase. Kept ref for BC with remote code at the bottom

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yup sounds good

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

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
Copy Markdown
Contributor

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

run-slow: aimv2, albert, align, aria, autoformer, aya_vision, bert, big_bird, blip, blip_2, bridgetower, bros, canine, chameleon, clap, clip

Copy link
Copy Markdown
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.

Nothing speaks against this, however before we merge I'd like to add a rule to https://github.com/huggingface/transformers-mlinter that detects this. This is a low hanging fruit but super annoying cc @tarekziade

Comment on lines -280 to -285
@dataclass
class MoECausalLMOutputWithPast(ModelOutput):
"""
Base class for causal language model (or autoregressive) outputs as well as Mixture of Expert's router hidden
states terms, to train a MoE model.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yup sounds good

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