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

[Type Hint] Unet Models #330

Merged
merged 2 commits into from
Sep 3, 2022

Conversation

sidthekidder
Copy link
Contributor

Adds type hint to init in 1. and 2. for issue #287

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Sep 2, 2022

The documentation is not available anymore as the PR was closed or merged.

@@ -30,7 +30,7 @@ def __init__(
attention_head_dim=8,
norm_num_groups=32,
norm_eps=1e-5,
):
) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice None is the correct return type here according to https://stackoverflow.com/questions/46779046/correct-type-annotation-for-init (no @anton-l ?)

@sidthekidder, could you maybe also give all the init values some type hints? I've shown one example above :-)

Copy link
Member

Choose a reason for hiding this comment

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

@patrickvonplaten yeah, but it has become more of a soft requirement for __init__, as it can only return None. E.g. in mypy: python/mypy#604
So no worries if we don't annotate them :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah agree here think it's also cleaner to not have a -> None type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, no return annotation for the constructor is cleaner - removed None!

@@ -30,7 +30,7 @@ def __init__(
attention_head_dim=8,
norm_num_groups=32,
norm_eps=1e-5,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
norm_eps=1e-5,
norm_eps: float =1e-5,

Copy link
Contributor

Choose a reason for hiding this comment

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

Hello

From issue #287, I see that type hints are required for all the variables. So would you be adding the type hints for other variables as well? Or is this PR out of scope for all of them?

Here are some examples:

flip_sin_to_cos: bool=True,
down_block_types: tuple[str]=("DownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D"),
block_out_channels: tuple[int]=(224, 448, 672, 896),
act_fn: str="silu"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the examples @vishnu-anirudh and @patrickvonplaten - I added type hints for other __init__ variables as well.

@@ -30,7 +30,7 @@ def __init__(
norm_eps=1e-5,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
norm_eps=1e-5,
norm_eps: float =1e-5,

Could you give all those values some type hints as well? :-)

@patrickvonplaten
Copy link
Contributor

Super cool - thanks a lot @sidthekidder ❤️

@patrickvonplaten patrickvonplaten merged commit b1fe170 into huggingface:main Sep 3, 2022
natolambert pushed a commit that referenced this pull request Sep 7, 2022
* add void check

* remove void, add types for params
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* add void check

* remove void, add types for params
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.

5 participants