Skip to content

Commit 5d848ec

Browse files
authored
[Tests] Update a deprecated parameter in test files and fix several typos (huggingface#7277)
* Add properties and `IPAdapterTesterMixin` tests for `StableDiffusionPanoramaPipeline` * Fix variable name typo and update comments * Update deprecated `output_type="numpy"` to "np" in test files * Discard changes to src/diffusers/pipelines/stable_diffusion_panorama/pipeline_stable_diffusion_panorama.py * Update test_stable_diffusion_panorama.py * Update numbers in README.md * Update get_guidance_scale_embedding method to use timesteps instead of w * Update number of checkpoints in README.md * Add type hints and fix var name * Fix PyTorch's convention for inplace functions * Fix a typo * Revert "Fix PyTorch's convention for inplace functions" This reverts commit 74350cf. * Fix typos * Indent * Refactor get_guidance_scale_embedding method in LEditsPPPipelineStableDiffusionXL class
1 parent 4974b84 commit 5d848ec

File tree

69 files changed

+272
-244
lines changed

Some content is hidden

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

69 files changed

+272
-244
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Please refer to the [How to use Stable Diffusion in Apple Silicon](https://huggi
7777

7878
## Quickstart
7979

80-
Generating outputs is super easy with 🤗 Diffusers. To generate an image from text, use the `from_pretrained` method to load any pretrained diffusion model (browse the [Hub](https://huggingface.co/models?library=diffusers&sort=downloads) for 19000+ checkpoints):
80+
Generating outputs is super easy with 🤗 Diffusers. To generate an image from text, use the `from_pretrained` method to load any pretrained diffusion model (browse the [Hub](https://huggingface.co/models?library=diffusers&sort=downloads) for 22000+ checkpoints):
8181

8282
```python
8383
from diffusers import DiffusionPipeline
@@ -219,7 +219,7 @@ Also, say 👋 in our public Discord channel <a href="https://discord.gg/G7tWnz9
219219
- https://github.com/deep-floyd/IF
220220
- https://github.com/bentoml/BentoML
221221
- https://github.com/bmaltais/kohya_ss
222-
- +8000 other amazing GitHub repositories 💪
222+
- +9000 other amazing GitHub repositories 💪
223223

224224
Thank you for using us ❤️.
225225

examples/research_projects/onnxruntime/unconditional_image_generation/train_unconditional.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ def transform_images(examples):
637637
generator=generator,
638638
batch_size=args.eval_batch_size,
639639
num_inference_steps=args.ddpm_num_inference_steps,
640-
output_type="numpy",
640+
output_type="np",
641641
).images
642642

643643
if args.use_ema:

examples/unconditional_image_generation/train_unconditional.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ def transform_images(examples):
648648
generator=generator,
649649
batch_size=args.eval_batch_size,
650650
num_inference_steps=args.ddpm_num_inference_steps,
651-
output_type="numpy",
651+
output_type="np",
652652
).images
653653

654654
if args.use_ema:

src/diffusers/models/attention.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def forward(
293293
) -> torch.FloatTensor:
294294
if cross_attention_kwargs is not None:
295295
if cross_attention_kwargs.get("scale", None) is not None:
296-
logger.warning("Passing `scale` to `cross_attention_kwargs` is depcrecated. `scale` will be ignored.")
296+
logger.warning("Passing `scale` to `cross_attention_kwargs` is deprecated. `scale` will be ignored.")
297297

298298
# Notice that normalization is always applied before the real computation in the following blocks.
299299
# 0. Self-Attention

src/diffusers/models/transformers/transformer_2d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def forward(
308308
"""
309309
if cross_attention_kwargs is not None:
310310
if cross_attention_kwargs.get("scale", None) is not None:
311-
logger.warning("Passing `scale` to `cross_attention_kwargs` is depcrecated. `scale` will be ignored.")
311+
logger.warning("Passing `scale` to `cross_attention_kwargs` is deprecated. `scale` will be ignored.")
312312
# ensure attention_mask is a bias, and give it a singleton query_tokens dimension.
313313
# we may have done this conversion already, e.g. if we came here via UNet2DConditionModel#forward.
314314
# we can tell by counting dims; if ndim == 2: it's a mask rather than a bias.

src/diffusers/models/unets/unet_2d_blocks.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ def forward(
846846
) -> torch.FloatTensor:
847847
if cross_attention_kwargs is not None:
848848
if cross_attention_kwargs.get("scale", None) is not None:
849-
logger.warning("Passing `scale` to `cross_attention_kwargs` is depcrecated. `scale` will be ignored.")
849+
logger.warning("Passing `scale` to `cross_attention_kwargs` is deprecated. `scale` will be ignored.")
850850

851851
hidden_states = self.resnets[0](hidden_states, temb)
852852
for attn, resnet in zip(self.attentions, self.resnets[1:]):
@@ -986,7 +986,7 @@ def forward(
986986
) -> torch.FloatTensor:
987987
cross_attention_kwargs = cross_attention_kwargs if cross_attention_kwargs is not None else {}
988988
if cross_attention_kwargs.get("scale", None) is not None:
989-
logger.warning("Passing `scale` to `cross_attention_kwargs` is depcrecated. `scale` will be ignored.")
989+
logger.warning("Passing `scale` to `cross_attention_kwargs` is deprecated. `scale` will be ignored.")
990990

991991
if attention_mask is None:
992992
# if encoder_hidden_states is defined: we are doing cross-attn, so we should use cross-attn mask.
@@ -1116,7 +1116,7 @@ def forward(
11161116
) -> Tuple[torch.FloatTensor, Tuple[torch.FloatTensor, ...]]:
11171117
cross_attention_kwargs = cross_attention_kwargs if cross_attention_kwargs is not None else {}
11181118
if cross_attention_kwargs.get("scale", None) is not None:
1119-
logger.warning("Passing `scale` to `cross_attention_kwargs` is depcrecated. `scale` will be ignored.")
1119+
logger.warning("Passing `scale` to `cross_attention_kwargs` is deprecated. `scale` will be ignored.")
11201120

11211121
output_states = ()
11221122

@@ -1241,7 +1241,7 @@ def forward(
12411241
) -> Tuple[torch.FloatTensor, Tuple[torch.FloatTensor, ...]]:
12421242
if cross_attention_kwargs is not None:
12431243
if cross_attention_kwargs.get("scale", None) is not None:
1244-
logger.warning("Passing `scale` to `cross_attention_kwargs` is depcrecated. `scale` will be ignored.")
1244+
logger.warning("Passing `scale` to `cross_attention_kwargs` is deprecated. `scale` will be ignored.")
12451245

12461246
output_states = ()
12471247

@@ -1986,7 +1986,7 @@ def forward(
19861986
) -> Tuple[torch.FloatTensor, Tuple[torch.FloatTensor, ...]]:
19871987
cross_attention_kwargs = cross_attention_kwargs if cross_attention_kwargs is not None else {}
19881988
if cross_attention_kwargs.get("scale", None) is not None:
1989-
logger.warning("Passing `scale` to `cross_attention_kwargs` is depcrecated. `scale` will be ignored.")
1989+
logger.warning("Passing `scale` to `cross_attention_kwargs` is deprecated. `scale` will be ignored.")
19901990

19911991
output_states = ()
19921992

@@ -2201,7 +2201,7 @@ def forward(
22012201
) -> Tuple[torch.FloatTensor, Tuple[torch.FloatTensor, ...]]:
22022202
cross_attention_kwargs = cross_attention_kwargs if cross_attention_kwargs is not None else {}
22032203
if cross_attention_kwargs.get("scale", None) is not None:
2204-
logger.warning("Passing `scale` to `cross_attention_kwargs` is depcrecated. `scale` will be ignored.")
2204+
logger.warning("Passing `scale` to `cross_attention_kwargs` is deprecated. `scale` will be ignored.")
22052205

22062206
output_states = ()
22072207

@@ -2483,7 +2483,7 @@ def forward(
24832483
) -> torch.FloatTensor:
24842484
if cross_attention_kwargs is not None:
24852485
if cross_attention_kwargs.get("scale", None) is not None:
2486-
logger.warning("Passing `scale` to `cross_attention_kwargs` is depcrecated. `scale` will be ignored.")
2486+
logger.warning("Passing `scale` to `cross_attention_kwargs` is deprecated. `scale` will be ignored.")
24872487

24882488
is_freeu_enabled = (
24892489
getattr(self, "s1", None)
@@ -3312,7 +3312,7 @@ def forward(
33123312
) -> torch.FloatTensor:
33133313
cross_attention_kwargs = cross_attention_kwargs if cross_attention_kwargs is not None else {}
33143314
if cross_attention_kwargs.get("scale", None) is not None:
3315-
logger.warning("Passing `scale` to `cross_attention_kwargs` is depcrecated. `scale` will be ignored.")
3315+
logger.warning("Passing `scale` to `cross_attention_kwargs` is deprecated. `scale` will be ignored.")
33163316

33173317
if attention_mask is None:
33183318
# if encoder_hidden_states is defined: we are doing cross-attn, so we should use cross-attn mask.
@@ -3694,7 +3694,7 @@ def forward(
36943694
) -> torch.FloatTensor:
36953695
cross_attention_kwargs = cross_attention_kwargs if cross_attention_kwargs is not None else {}
36963696
if cross_attention_kwargs.get("scale", None) is not None:
3697-
logger.warning("Passing `scale` to `cross_attention_kwargs` is depcrecated. `scale` will be ignored.")
3697+
logger.warning("Passing `scale` to `cross_attention_kwargs` is deprecated. `scale` will be ignored.")
36983698

36993699
# 1. Self-Attention
37003700
if self.add_self_attention:

src/diffusers/models/unets/unet_3d_blocks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ def forward(
11831183
):
11841184
if cross_attention_kwargs is not None:
11851185
if cross_attention_kwargs.get("scale", None) is not None:
1186-
logger.warning("Passing `scale` to `cross_attention_kwargs` is depcrecated. `scale` will be ignored.")
1186+
logger.warning("Passing `scale` to `cross_attention_kwargs` is deprecated. `scale` will be ignored.")
11871187

11881188
output_states = ()
11891189

@@ -1367,7 +1367,7 @@ def forward(
13671367
) -> torch.FloatTensor:
13681368
if cross_attention_kwargs is not None:
13691369
if cross_attention_kwargs.get("scale", None) is not None:
1370-
logger.warning("Passing `scale` to `cross_attention_kwargs` is depcrecated. `scale` will be ignored.")
1370+
logger.warning("Passing `scale` to `cross_attention_kwargs` is deprecated. `scale` will be ignored.")
13711371

13721372
is_freeu_enabled = (
13731373
getattr(self, "s1", None)
@@ -1707,7 +1707,7 @@ def forward(
17071707
) -> torch.FloatTensor:
17081708
if cross_attention_kwargs is not None:
17091709
if cross_attention_kwargs.get("scale", None) is not None:
1710-
logger.warning("Passing `scale` to `cross_attention_kwargs` is depcrecated. `scale` will be ignored.")
1710+
logger.warning("Passing `scale` to `cross_attention_kwargs` is deprecated. `scale` will be ignored.")
17111711

17121712
hidden_states = self.resnets[0](hidden_states, temb)
17131713

src/diffusers/pipelines/amused/pipeline_amused_img2img.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def __call__(
127127
on the amount of noise initially added. When `strength` is 1, added noise is maximum and the denoising
128128
process runs for the full number of iterations specified in `num_inference_steps`. A value of 1
129129
essentially ignores `image`.
130-
num_inference_steps (`int`, *optional*, defaults to 16):
130+
num_inference_steps (`int`, *optional*, defaults to 12):
131131
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
132132
expense of slower inference.
133133
guidance_scale (`float`, *optional*, defaults to 10.0):
@@ -191,7 +191,7 @@ def __call__(
191191
negative_prompt_embeds is None and negative_encoder_hidden_states is not None
192192
):
193193
raise ValueError(
194-
"pass either both `negatve_prompt_embeds` and `negative_encoder_hidden_states` or neither"
194+
"pass either both `negative_prompt_embeds` and `negative_encoder_hidden_states` or neither"
195195
)
196196

197197
if (prompt is None and prompt_embeds is None) or (prompt is not None and prompt_embeds is not None):

src/diffusers/pipelines/controlnet/pipeline_controlnet.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -824,20 +824,22 @@ def prepare_latents(self, batch_size, num_channels_latents, height, width, dtype
824824
return latents
825825

826826
# Copied from diffusers.pipelines.latent_consistency_models.pipeline_latent_consistency_text2img.LatentConsistencyModelPipeline.get_guidance_scale_embedding
827-
def get_guidance_scale_embedding(self, w, embedding_dim=512, dtype=torch.float32):
827+
def get_guidance_scale_embedding(
828+
self, w: torch.Tensor, embedding_dim: int = 512, dtype: torch.dtype = torch.float32
829+
) -> torch.FloatTensor:
828830
"""
829831
See https://github.com/google-research/vdm/blob/dc27b98a554f65cdc654b800da5aa1846545d41b/model_vdm.py#L298
830832
831833
Args:
832-
timesteps (`torch.Tensor`):
833-
generate embedding vectors at these timesteps
834+
w (`torch.Tensor`):
835+
Generate embedding vectors with a specified guidance scale to subsequently enrich timestep embeddings.
834836
embedding_dim (`int`, *optional*, defaults to 512):
835-
dimension of the embeddings to generate
836-
dtype:
837-
data type of the generated embeddings
837+
Dimension of the embeddings to generate.
838+
dtype (`torch.dtype`, *optional*, defaults to `torch.float32`):
839+
Data type of the generated embeddings.
838840
839841
Returns:
840-
`torch.FloatTensor`: Embedding vectors with shape `(len(timesteps), embedding_dim)`
842+
`torch.FloatTensor`: Embedding vectors with shape `(len(w), embedding_dim)`.
841843
"""
842844
assert len(w.shape) == 1
843845
w = w * 1000.0

src/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -869,20 +869,22 @@ def upcast_vae(self):
869869
self.vae.decoder.mid_block.to(dtype)
870870

871871
# Copied from diffusers.pipelines.latent_consistency_models.pipeline_latent_consistency_text2img.LatentConsistencyModelPipeline.get_guidance_scale_embedding
872-
def get_guidance_scale_embedding(self, w, embedding_dim=512, dtype=torch.float32):
872+
def get_guidance_scale_embedding(
873+
self, w: torch.Tensor, embedding_dim: int = 512, dtype: torch.dtype = torch.float32
874+
) -> torch.FloatTensor:
873875
"""
874876
See https://github.com/google-research/vdm/blob/dc27b98a554f65cdc654b800da5aa1846545d41b/model_vdm.py#L298
875877
876878
Args:
877-
timesteps (`torch.Tensor`):
878-
generate embedding vectors at these timesteps
879+
w (`torch.Tensor`):
880+
Generate embedding vectors with a specified guidance scale to subsequently enrich timestep embeddings.
879881
embedding_dim (`int`, *optional*, defaults to 512):
880-
dimension of the embeddings to generate
881-
dtype:
882-
data type of the generated embeddings
882+
Dimension of the embeddings to generate.
883+
dtype (`torch.dtype`, *optional*, defaults to `torch.float32`):
884+
Data type of the generated embeddings.
883885
884886
Returns:
885-
`torch.FloatTensor`: Embedding vectors with shape `(len(timesteps), embedding_dim)`
887+
`torch.FloatTensor`: Embedding vectors with shape `(len(w), embedding_dim)`.
886888
"""
887889
assert len(w.shape) == 1
888890
w = w * 1000.0

0 commit comments

Comments
 (0)