-
Notifications
You must be signed in to change notification settings - Fork 6.5k
[Utils] add utilities for checking if certain utilities are properly documented #7763
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
25033da
add; utility to check if attn_procs,norms,acts are properly documented.
sayakpaul 9398e0f
add support listing to the workflows.
sayakpaul 132c68b
Merge branch 'main' into feat/check-doc-listing
sayakpaul 57ca5be
change to 2024.
sayakpaul 8532285
Merge branch 'main' into feat/check-doc-listing
sayakpaul b5c9aeb
small fixes.
sayakpaul 40128ac
Merge branch 'main' into feat/check-doc-listing
sayakpaul c625166
does adding detailed docstrings help?
sayakpaul 8b58696
Merge branch 'main' into feat/check-doc-listing
sayakpaul 80d0a7f
Merge branch 'main' into feat/check-doc-listing
sayakpaul d064b11
Merge branch 'main' into feat/check-doc-listing
sayakpaul 45daa98
Merge branch 'main' into feat/check-doc-listing
sayakpaul 5663ba5
fix
sayakpaul 0653e2d
Merge branch 'main' into feat/check-doc-listing
sayakpaul dac63dd
uncomment image processor check
sayakpaul 900cd1c
quality
sayakpaul 6dc3d19
Merge branch 'main' into feat/check-doc-listing
sayakpaul 8449186
fix, thanks to @mishig.
sayakpaul af2370b
Apply suggestions from code review
sayakpaul c4c9fc4
Merge branch 'main' into feat/check-doc-listing
sayakpaul 15b2f57
style
sayakpaul 12c9ac4
Merge branch 'main' into feat/check-doc-listing
sayakpaul f3443d0
Merge branch 'main' into feat/check-doc-listing
sayakpaul b8b0fd1
Merge branch 'main' into feat/check-doc-listing
sayakpaul 63989af
resolve conflicts.
sayakpaul 4227392
JointAttnProcessor2_0
sayakpaul 0034db2
fixes
sayakpaul eb5a8b2
resolve conflicts.
sayakpaul a2aa752
fixes
sayakpaul 005a2e9
fixes
sayakpaul b653eaa
fixes
sayakpaul 75136e6
fixes
sayakpaul 7eb617a
fixes
sayakpaul 80be186
Merge branch 'main' into feat/check-doc-listing
sayakpaul ef03777
Merge branch 'main' into feat/check-doc-listing
sayakpaul 53a3361
fixes
sayakpaul be989a6
Update docs/source/en/api/normalization.md
sayakpaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # coding=utf-8 | ||
| # Copyright 2024 The HuggingFace Inc. team. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """ | ||
| Utility that checks that modules like attention processors are listed in the documentation file. | ||
|
|
||
| ```bash | ||
| python utils/check_support_list.py | ||
| ``` | ||
|
|
||
| It has no auto-fix mode. | ||
| """ | ||
| import os | ||
| import re | ||
|
|
||
|
|
||
| # All paths are set with the intent you should run this script from the root of the repo with the command | ||
| # python utils/check_doctest_list.py | ||
| REPO_PATH = "." | ||
|
|
||
|
|
||
| def check_attention_processors(): | ||
| with open(os.path.join(REPO_PATH, "docs/source/en/api/attnprocessor.md"), "r") as f: | ||
| doctext = f.read() | ||
| matches = re.findall(r"\[\[autodoc\]\]\s([^\n]+)", doctext) | ||
| documented_attention_processors = [match.split(".")[-1] for match in matches] | ||
|
|
||
| with open(os.path.join(REPO_PATH, "src/diffusers/models/attention_processor.py"), "r") as f: | ||
| doctext = f.read() | ||
| processor_classes = re.findall(r"class\s+(\w+Processor(?:\d*_?\d*))[(:]", doctext) | ||
| processor_classes = [proc for proc in processor_classes if "LoRA" not in proc and proc != "Attention"] | ||
|
|
||
| for processor in processor_classes: | ||
| if processor not in documented_attention_processors: | ||
| raise ValueError( | ||
| f"{processor} should be in listed in the attention processor documentation but is not. Please update the documentation." | ||
| ) | ||
|
|
||
|
|
||
| def check_image_processors(): | ||
| with open(os.path.join(REPO_PATH, "docs/source/en/api/image_processor.md"), "r") as f: | ||
| doctext = f.read() | ||
| matches = re.findall(r"\[\[autodoc\]\]\s([^\n]+)", doctext) | ||
| documented_image_processors = [match.split(".")[-1] for match in matches] | ||
|
|
||
| with open(os.path.join(REPO_PATH, "src/diffusers/image_processor.py"), "r") as f: | ||
| doctext = f.read() | ||
| processor_classes = re.findall(r"class\s+(\w+Processor(?:\d*_?\d*))[(:]", doctext) | ||
|
|
||
| for processor in processor_classes: | ||
| if processor not in documented_image_processors: | ||
| raise ValueError( | ||
| f"{processor} should be in listed in the image processor documentation but is not. Please update the documentation." | ||
| ) | ||
|
|
||
|
|
||
| def check_activations(): | ||
| with open(os.path.join(REPO_PATH, "docs/source/en/api/activations.md"), "r") as f: | ||
| doctext = f.read() | ||
| matches = re.findall(r"\[\[autodoc\]\]\s([^\n]+)", doctext) | ||
| documented_activations = [match.split(".")[-1] for match in matches] | ||
|
|
||
| with open(os.path.join(REPO_PATH, "src/diffusers/models/activations.py"), "r") as f: | ||
| doctext = f.read() | ||
| activation_classes = re.findall(r"class\s+(\w+)\s*\(.*?nn\.Module.*?\):", doctext) | ||
|
|
||
| for activation in activation_classes: | ||
| if activation not in documented_activations: | ||
| raise ValueError( | ||
| f"{activation} should be in listed in the activations documentation but is not. Please update the documentation." | ||
| ) | ||
|
|
||
|
|
||
| def check_normalizations(): | ||
| with open(os.path.join(REPO_PATH, "docs/source/en/api/normalization.md"), "r") as f: | ||
| doctext = f.read() | ||
| matches = re.findall(r"\[\[autodoc\]\]\s([^\n]+)", doctext) | ||
| documented_normalizations = [match.split(".")[-1] for match in matches] | ||
|
|
||
| with open(os.path.join(REPO_PATH, "src/diffusers/models/normalization.py"), "r") as f: | ||
| doctext = f.read() | ||
| normalization_classes = re.findall(r"class\s+(\w+)\s*\(.*?nn\.Module.*?\):", doctext) | ||
|
|
||
| for norm in normalization_classes: | ||
| if norm not in documented_normalizations: | ||
| raise ValueError( | ||
| f"{norm} should be in listed in the normalizations documentation but is not. Please update the documentation." | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| check_attention_processors() | ||
| check_image_processors() | ||
| check_activations() | ||
| check_normalizations() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LayerNormis the reason why doc-builder is not building.I've inspected a bit.
All other norms are diffuser defined classes:
whereas
LayerNormseems to be alias to pytorch defined class (and doc-builder autodoc does not work with pytorch defined classes):diffusers/src/diffusers/models/normalization.py
Line 198 in 900cd1c
Therefore, as a simple fix: I'd suggest replacing
[[autodoc]] models.normalization.LayerNormwith something like:You can also use LayerNorm and add markdown link to pytorch layernorm docThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mishig25. I think it'd be okay to remove LayerNorm from our doc because our implementation is really a special case and is already supported in the latest versions of PyTorch.