Skip to content

[fix] Add return types - #14874

Merged
stevhliu merged 6 commits into
huggingface:mainfrom
stevhliu:return-types
Sep 30, 2026
Merged

stevhliu merged 6 commits into
huggingface:mainfrom
stevhliu:return-types

Conversation

@stevhliu

Copy link
Copy Markdown
Member

Adds standard return type annotation -> XPipelineOutput | tuple to non-deprecated pipeline __call__ and XOutput tuple[torch.Tensor] to ModelMixin.forward and submodule forward.

Skipped the modular pipeline blocks for now which currently say -> PipelineState, but every block returns (components, state) tuple. Should we do tuple[XModularPipeline, PipelineState] here, or [BlockState] for loop blocks?

@github-actions github-actions Bot added size/L PR with diff > 200 LOC models pipelines and removed size/L PR with diff > 200 LOC labels Sep 25, 2026
@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 github-actions Bot added the size/L PR with diff > 200 LOC label Sep 25, 2026
@sayakpaul sayakpaul added this to the Release 0.41.0 milestone Sep 28, 2026
@sayakpaul sayakpaul moved this to In Progress in Diffusers Roadmap Sep 28, 2026

@sayakpaul sayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice cool! Should we consider using a CI validation for it as well?

Should we do tuple[XModularPipeline, PipelineState] here, or [BlockState] for loop blocks?

Sure.

@stevhliu

Copy link
Copy Markdown
Member Author

@sayakpaul , i think the failing CI is related to huggingface/transformers#45783. i'll check it out further and let you know!

Comment on lines +25 to +31
A method is only checked on the class where it's written, not on classes that inherit it. Any annotation passes,
including `-> None`.

Run from the repository root:

python utils/check_return_annotations.py
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we get a nice list of functions (including their paths in the codebase) that are missing the return type in the annotation?

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.

yeah it should print out the below if something is missing:

src/diffusers/models/embeddings.py:1297: TimestepEmbedding.forward has no return type annotation
src/diffusers/pipelines/flux/pipeline_flux.py:602: FluxPipeline.__call__ has no return type annotation

Found 2 methods without a return type annotation. Add one to each method above.

Comment thread utils/check_return_annotations.py Outdated

@sayakpaul sayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for iterating. Just two additional comments.

@sayakpaul

Copy link
Copy Markdown
Member

@stevhliu feel free to resolve the conflicts and then merge :)

@stevhliu
stevhliu merged commit c60830e into huggingface:main Sep 30, 2026
19 checks passed
@stevhliu
stevhliu deleted the return-types branch September 30, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants