Skip to content

Commit 1079d18

Browse files
authored
Merge branch 'main' into bnb-multi-backend
2 parents 0d39ea4 + 3d70777 commit 1079d18

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

src/diffusers/loaders/textual_inversion.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def load_textual_inversion_state_dicts(pretrained_model_name_or_paths, **kwargs)
4040
force_download = kwargs.pop("force_download", False)
4141
proxies = kwargs.pop("proxies", None)
4242
local_files_only = kwargs.pop("local_files_only", None)
43-
token = kwargs.pop("token", None)
43+
hf_token = kwargs.pop("hf_token", None)
4444
revision = kwargs.pop("revision", None)
4545
subfolder = kwargs.pop("subfolder", None)
4646
weight_name = kwargs.pop("weight_name", None)
@@ -73,7 +73,7 @@ def load_textual_inversion_state_dicts(pretrained_model_name_or_paths, **kwargs)
7373
force_download=force_download,
7474
proxies=proxies,
7575
local_files_only=local_files_only,
76-
token=token,
76+
token=hf_token,
7777
revision=revision,
7878
subfolder=subfolder,
7979
user_agent=user_agent,
@@ -93,7 +93,7 @@ def load_textual_inversion_state_dicts(pretrained_model_name_or_paths, **kwargs)
9393
force_download=force_download,
9494
proxies=proxies,
9595
local_files_only=local_files_only,
96-
token=token,
96+
token=hf_token,
9797
revision=revision,
9898
subfolder=subfolder,
9999
user_agent=user_agent,
@@ -312,7 +312,7 @@ def load_textual_inversion(
312312
local_files_only (`bool`, *optional*, defaults to `False`):
313313
Whether to only load local model weights and configuration files or not. If set to `True`, the model
314314
won't be downloaded from the Hub.
315-
token (`str` or *bool*, *optional*):
315+
hf_token (`str` or *bool*, *optional*):
316316
The token to use as HTTP bearer authorization for remote files. If `True`, the token generated from
317317
`diffusers-cli login` (stored in `~/.huggingface`) is used.
318318
revision (`str`, *optional*, defaults to `"main"`):

src/diffusers/pipelines/pag/pipeline_pag_sana.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import inspect
1717
import re
1818
import urllib.parse as ul
19+
import warnings
1920
from typing import Callable, Dict, List, Optional, Tuple, Union
2021

2122
import torch
@@ -41,6 +42,7 @@
4142
ASPECT_RATIO_1024_BIN,
4243
)
4344
from ..pixart_alpha.pipeline_pixart_sigma import ASPECT_RATIO_2048_BIN
45+
from ..sana.pipeline_sana import ASPECT_RATIO_4096_BIN
4446
from .pag_utils import PAGMixin
4547

4648

@@ -639,7 +641,7 @@ def __call__(
639641
negative_prompt_attention_mask: Optional[torch.Tensor] = None,
640642
output_type: Optional[str] = "pil",
641643
return_dict: bool = True,
642-
clean_caption: bool = True,
644+
clean_caption: bool = False,
643645
use_resolution_binning: bool = True,
644646
callback_on_step_end: Optional[Callable[[int, int, Dict], None]] = None,
645647
callback_on_step_end_tensor_inputs: List[str] = ["latents"],
@@ -755,7 +757,9 @@ def __call__(
755757
callback_on_step_end_tensor_inputs = callback_on_step_end.tensor_inputs
756758

757759
if use_resolution_binning:
758-
if self.transformer.config.sample_size == 64:
760+
if self.transformer.config.sample_size == 128:
761+
aspect_ratio_bin = ASPECT_RATIO_4096_BIN
762+
elif self.transformer.config.sample_size == 64:
759763
aspect_ratio_bin = ASPECT_RATIO_2048_BIN
760764
elif self.transformer.config.sample_size == 32:
761765
aspect_ratio_bin = ASPECT_RATIO_1024_BIN
@@ -912,7 +916,14 @@ def __call__(
912916
image = latents
913917
else:
914918
latents = latents.to(self.vae.dtype)
915-
image = self.vae.decode(latents / self.vae.config.scaling_factor, return_dict=False)[0]
919+
try:
920+
image = self.vae.decode(latents / self.vae.config.scaling_factor, return_dict=False)[0]
921+
except torch.cuda.OutOfMemoryError as e:
922+
warnings.warn(
923+
f"{e}. \n"
924+
f"Try to use VAE tiling for large images. For example: \n"
925+
f"pipe.vae.enable_tiling(tile_sample_min_width=512, tile_sample_min_height=512)"
926+
)
916927
if use_resolution_binning:
917928
image = self.image_processor.resize_and_crop_tensor(image, orig_width, orig_height)
918929

src/diffusers/pipelines/sana/pipeline_sana.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import inspect
1717
import re
1818
import urllib.parse as ul
19+
import warnings
1920
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
2021

2122
import torch
@@ -953,7 +954,14 @@ def __call__(
953954
image = latents
954955
else:
955956
latents = latents.to(self.vae.dtype)
956-
image = self.vae.decode(latents / self.vae.config.scaling_factor, return_dict=False)[0]
957+
try:
958+
image = self.vae.decode(latents / self.vae.config.scaling_factor, return_dict=False)[0]
959+
except torch.cuda.OutOfMemoryError as e:
960+
warnings.warn(
961+
f"{e}. \n"
962+
f"Try to use VAE tiling for large images. For example: \n"
963+
f"pipe.vae.enable_tiling(tile_sample_min_width=512, tile_sample_min_height=512)"
964+
)
957965
if use_resolution_binning:
958966
image = self.image_processor.resize_and_crop_tensor(image, orig_width, orig_height)
959967

0 commit comments

Comments
 (0)