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

Beautiful Doc string added into the UNetMidBlock2D class. #5389

Merged
merged 25 commits into from
Oct 18, 2023

Conversation

hi-sushanta
Copy link
Contributor

@hi-sushanta hi-sushanta commented Oct 13, 2023

Once more time I added a new doc string into the model file among the UNetMidBlock2D class.

Chaged Code Looks Like:
Screenshot from 2023-10-13 21-32-43

Before submitting

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.

hi-sushanta and others added 17 commits October 5, 2023 06:34
…standing other developers what are doing and where it's using.
This changes suggest by maintener.

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
Add suggested text

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
I changed the Parameter to Args text.
proper indentation set in this file.
a little bit of change in the act_fun argument line.
similar doc-string add to have in the original diffusion repository.
Added Beutifull doc-string into the UNetMidBlock2D class.
@hi-sushanta hi-sushanta changed the title Doc string Beautiful Doc string added into the UNetMidBlock2D class. Oct 15, 2023
Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

Thank you!

Good for me to merge once the CI is green.

attn_groups (`Optional[int]`, *optional*, defaults to None): The number of groups for the attention blocks.
resnet_pre_norm (`bool`, *optional*, defaults to `True`): Whether to use pre-normalization for the resnet blocks.
add_attention (`bool`, *optional*, defaults to `True`): Whether to add attention blocks.
attention_head_dim (`int`, *optional*, defaults to 1): The number of attention heads.
Copy link
Member

Choose a reason for hiding this comment

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

Checking with @patrickvonplaten:

Is attention_head_dim related to the number of attention heads?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the attention_head_dim parameter is related to the number of attention heads

Copy link
Collaborator

@DN6 DN6 Oct 17, 2023

Choose a reason for hiding this comment

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

attention_head_dim is the dimension of a single attention head and is used to calculate the number of attention heads in the block.

heads=in_channels // attention_head_dim,

So while it does contribute to determining the number of attention heads, it does not actually set the number of heads. I would change this to

attention_head_dim: Dimension of a single attention head. The number of attention heads is determined based on this value and the number of input channels.  

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, now I also update the doc string for the attention_head_dim parameter.

resnet_eps (`float`, *optional*, 1e-6 ): The epsilon value for the resnet blocks.
resnet_time_scale_shift (`str`, *optional*, defaults to `default`): The time scale shift for the resnet blocks.
resnet_act_fn (`str`, *optional*, defaults to `swish`): The activation function for the resnet blocks.
resnet_groups (`int`, *optional*, defaults to 32): The number of groups for the resnet blocks.
Copy link
Collaborator

@DN6 DN6 Oct 17, 2023

Choose a reason for hiding this comment

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

Could we maybe add some context on how the parameters are applied in the blocks?

e.g.
resnet_groups: The number of groups to use in the group normalization layers of the resnet.
resnet_timescale_shift: The type of normalization to apply to the time embeddings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I understand, Now I added a new one that looks like that if it's OK.

  • resnet_groups: The number of groups to use in the group normalization layers of the resnet blocks. This can help to improve performance and reduce memory usage.

  • resnet_time_scale_shift: The type of normalization to apply to the time embeddings. This can help to improve the performance of the model on tasks with long-range temporal dependencies.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @hi-sushanta. I think the phrase "improve performance of the model" is dependent on a number of factors, and reducing the number of groups doesn't necessarily lead to memory savings. So I would remove those additional sentences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I am done to remove additional sentences.

I replaced the definition in this parameter resnet_time_scale_shift and resnet_groups.
I remove additional sentences into the resnet_groups argument.
I replaced my definition with the maintainer definition in the attention_head_dim parameter.
Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

Thank you for working on it!

@sayakpaul sayakpaul requested a review from DN6 October 18, 2023 03:42
@DN6
Copy link
Collaborator

DN6 commented Oct 18, 2023

Hi @hi-sushanta Can you please run make style && make quality on your PR so that the code quality checks pass.

@hi-sushanta
Copy link
Contributor Author

I already successfully reformatted the file using the black package. However, when I ran the make style && make quality commands, multiple other files were reformatted, even though I did not touch those files.

@patrickvonplaten patrickvonplaten merged commit 36a0bac into huggingface:main Oct 18, 2023
10 of 11 checks passed
@hi-sushanta hi-sushanta deleted the doc-string branch October 19, 2023 01:06
mhetrerajat pushed a commit to mhetrerajat/diffusers that referenced this pull request Oct 23, 2023
…e#5389)

* I added a new doc string to the class. This is more flexible to understanding other developers what are doing and where it's using.

* Update src/diffusers/models/unet_2d_blocks.py

This changes suggest by maintener.

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>

* Update src/diffusers/models/unet_2d_blocks.py

Add suggested text

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>

* Update unet_2d_blocks.py

I changed the Parameter to Args text.

* Update unet_2d_blocks.py

proper indentation set in this file.

* Update unet_2d_blocks.py

a little bit of change in the act_fun argument line.

* I run the black command to reformat style in the code

* Update unet_2d_blocks.py

similar doc-string add to have in the original diffusion repository.

* Update unet_2d_blocks.py

Added Beutifull doc-string into the UNetMidBlock2D class.

* Update unet_2d_blocks.py

I replaced the definition in this parameter resnet_time_scale_shift and resnet_groups.

* Update unet_2d_blocks.py

I remove additional sentences into the resnet_groups argument.

* Update unet_2d_blocks.py

I replaced my definition with the maintainer definition in the attention_head_dim parameter.

* I am using black package for reformated my file

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
Co-authored-by: YiYi Xu <yixu310@gmail.com>
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
…e#5389)

* I added a new doc string to the class. This is more flexible to understanding other developers what are doing and where it's using.

* Update src/diffusers/models/unet_2d_blocks.py

This changes suggest by maintener.

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>

* Update src/diffusers/models/unet_2d_blocks.py

Add suggested text

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>

* Update unet_2d_blocks.py

I changed the Parameter to Args text.

* Update unet_2d_blocks.py

proper indentation set in this file.

* Update unet_2d_blocks.py

a little bit of change in the act_fun argument line.

* I run the black command to reformat style in the code

* Update unet_2d_blocks.py

similar doc-string add to have in the original diffusion repository.

* Update unet_2d_blocks.py

Added Beutifull doc-string into the UNetMidBlock2D class.

* Update unet_2d_blocks.py

I replaced the definition in this parameter resnet_time_scale_shift and resnet_groups.

* Update unet_2d_blocks.py

I remove additional sentences into the resnet_groups argument.

* Update unet_2d_blocks.py

I replaced my definition with the maintainer definition in the attention_head_dim parameter.

* I am using black package for reformated my file

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
Co-authored-by: YiYi Xu <yixu310@gmail.com>
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
…e#5389)

* I added a new doc string to the class. This is more flexible to understanding other developers what are doing and where it's using.

* Update src/diffusers/models/unet_2d_blocks.py

This changes suggest by maintener.

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>

* Update src/diffusers/models/unet_2d_blocks.py

Add suggested text

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>

* Update unet_2d_blocks.py

I changed the Parameter to Args text.

* Update unet_2d_blocks.py

proper indentation set in this file.

* Update unet_2d_blocks.py

a little bit of change in the act_fun argument line.

* I run the black command to reformat style in the code

* Update unet_2d_blocks.py

similar doc-string add to have in the original diffusion repository.

* Update unet_2d_blocks.py

Added Beutifull doc-string into the UNetMidBlock2D class.

* Update unet_2d_blocks.py

I replaced the definition in this parameter resnet_time_scale_shift and resnet_groups.

* Update unet_2d_blocks.py

I remove additional sentences into the resnet_groups argument.

* Update unet_2d_blocks.py

I replaced my definition with the maintainer definition in the attention_head_dim parameter.

* I am using black package for reformated my file

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
Co-authored-by: YiYi Xu <yixu310@gmail.com>
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