Skip to content

Commit f502538

Browse files
sayakpaulstevhliuyiyixuxu
authored
[WIP] chore: add utilities to check if call/forward methods are documented. (#13758)
* chore: add utilities to check if call/forward methods are documented. * Fix missing forward/__call__ docstring entries (#13769) add missing * style. --------- Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com> Co-authored-by: YiYi Xu <yixu310@gmail.com>
1 parent fece08a commit f502538

211 files changed

Lines changed: 2502 additions & 164 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pr_modular_tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ jobs:
7373
python utils/check_copies.py
7474
python utils/check_dummies.py
7575
python utils/check_support_list.py
76+
python utils/check_forward_call_docstrings.py
7677
make deps_table_check_updated
7778
- name: Check if failure
7879
if: ${{ failure() }}

.github/workflows/pr_tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ jobs:
6868
python utils/check_copies.py
6969
python utils/check_dummies.py
7070
python utils/check_support_list.py
71+
python utils/check_forward_call_docstrings.py
7172
make deps_table_check_updated
7273
- name: Check if failure
7374
if: ${{ failure() }}

.github/workflows/pr_tests_gpu.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ jobs:
6969
python utils/check_copies.py
7070
python utils/check_dummies.py
7171
python utils/check_support_list.py
72+
python utils/check_forward_call_docstrings.py
7273
make deps_table_check_updated
7374
- name: Check if failure
7475
if: ${{ failure() }}

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ repo-consistency:
3636
python utils/check_dummies.py
3737
python utils/check_repo.py
3838
python utils/check_inits.py
39+
python utils/check_forward_call_docstrings.py
3940

4041
# this target runs checks on all files
4142

@@ -74,6 +75,10 @@ fix-copies:
7475
modular-autodoctrings:
7576
python utils/modular_auto_docstring.py
7677

78+
# Verify forward() / __call__() arguments are documented in their docstrings
79+
check-forward-call-docstrings:
80+
python utils/check_forward_call_docstrings.py
81+
7782
# Run tests for the library
7883

7984
test:

src/diffusers/models/adapter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ def forward(self, x: torch.Tensor) -> list[torch.Tensor]:
269269
each representing information extracted at a different scale from the input. The length of the list is
270270
determined by the number of downsample blocks in the Adapter, as specified by the `channels` and
271271
`num_res_blocks` parameters during initialization.
272+
273+
Args:
274+
x (`torch.Tensor`):
275+
The input tensor to process through the adapter model.
272276
"""
273277
return self.adapter(x)
274278

src/diffusers/models/autoencoders/autoencoder_asym_kl.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ def forward(
166166
Whether to sample from the posterior.
167167
return_dict (`bool`, *optional*, defaults to `True`):
168168
Whether or not to return a [`DecoderOutput`] instead of a plain tuple.
169+
generator (`torch.Generator`, *optional*):
170+
A [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) to make sampling
171+
deterministic.
169172
"""
170173
x = sample
171174
posterior = self.encode(x).latent_dist

src/diffusers/models/autoencoders/autoencoder_dc.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,12 @@ def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutp
706706
return DecoderOutput(sample=decoded)
707707

708708
def forward(self, sample: torch.Tensor, return_dict: bool = True) -> torch.Tensor:
709+
r"""
710+
Args:
711+
sample (`torch.Tensor`): Input sample.
712+
return_dict (`bool`, *optional*, defaults to `True`):
713+
Whether or not to return a [`DecoderOutput`] instead of a plain tuple.
714+
"""
709715
encoded = self.encode(sample, return_dict=False)[0]
710716
decoded = self.decode(encoded, return_dict=False)[0]
711717
if not return_dict:

src/diffusers/models/autoencoders/autoencoder_kl.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ def forward(
424424
Whether to sample from the posterior.
425425
return_dict (`bool`, *optional*, defaults to `True`):
426426
Whether or not to return a [`DecoderOutput`] instead of a plain tuple.
427+
generator (`torch.Generator`, *optional*):
428+
A [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) to make sampling
429+
deterministic.
427430
"""
428431
x = sample
429432
posterior = self.encode(x).latent_dist

src/diffusers/models/autoencoders/autoencoder_kl_cogvideox.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,17 @@ def forward(
14091409
return_dict: bool = True,
14101410
generator: torch.Generator | None = None,
14111411
) -> torch.Tensor | torch.Tensor:
1412+
r"""
1413+
Args:
1414+
sample (`torch.Tensor`): Input sample.
1415+
sample_posterior (`bool`, *optional*, defaults to `False`):
1416+
Whether to sample from the posterior.
1417+
return_dict (`bool`, *optional*, defaults to `True`):
1418+
Whether or not to return a [`DecoderOutput`] instead of a plain tuple.
1419+
generator (`torch.Generator`, *optional*):
1420+
A [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) to make sampling
1421+
deterministic.
1422+
"""
14121423
x = sample
14131424
posterior = self.encode(x).latent_dist
14141425
if sample_posterior:

src/diffusers/models/autoencoders/autoencoder_kl_cosmos.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,17 @@ def forward(
10781078
return_dict: bool = True,
10791079
generator: torch.Generator | None = None,
10801080
) -> tuple[torch.Tensor] | DecoderOutput:
1081+
r"""
1082+
Args:
1083+
sample (`torch.Tensor`): Input sample.
1084+
sample_posterior (`bool`, *optional*, defaults to `False`):
1085+
Whether to sample from the posterior.
1086+
return_dict (`bool`, *optional*, defaults to `True`):
1087+
Whether or not to return a [`DecoderOutput`] instead of a plain tuple.
1088+
generator (`torch.Generator`, *optional*):
1089+
A [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) to make sampling
1090+
deterministic.
1091+
"""
10811092
x = sample
10821093
posterior = self.encode(x).latent_dist
10831094
if sample_posterior:

0 commit comments

Comments
 (0)