Skip to content

Commit b4964b8

Browse files
committed
alias
1 parent 284419b commit b4964b8

10 files changed

Lines changed: 25 additions & 14 deletions

File tree

src/diffusers/loaders/single_file.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def from_single_file(cls, pretrained_model_link_or_path, **kwargs) -> Self:
281281
- A link to the `.ckpt` file (for example
282282
`"https://huggingface.co/<repo_id>/blob/main/<path_to_file>.ckpt"`) on the Hub.
283283
- A path to a *file* containing all pipeline weights.
284-
torch_dtype (`str` or `torch.dtype`, *optional*):
284+
dtype (`str` or `torch.dtype`, *optional*):
285285
Override the default `torch.dtype` and load the model with another dtype.
286286
force_download (`bool`, *optional*, defaults to `False`):
287287
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
@@ -361,6 +361,8 @@ def from_single_file(cls, pretrained_model_link_or_path, **kwargs) -> Self:
361361
local_files_only = kwargs.pop("local_files_only", False)
362362
revision = kwargs.pop("revision", None)
363363
torch_dtype = kwargs.pop("torch_dtype", None)
364+
dtype = kwargs.pop("dtype", None)
365+
torch_dtype = dtype if dtype is not None else torch_dtype
364366
disable_mmap = kwargs.pop("disable_mmap", False)
365367

366368
is_legacy_loading = False

src/diffusers/loaders/single_file_model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def from_single_file(cls, pretrained_model_link_or_path_or_dict: str | None = No
277277
original_config (`str`, *optional*):
278278
Dict or path to a yaml file containing the configuration for the model in its original format.
279279
If a dict is provided, it will be used to initialize the model configuration.
280-
torch_dtype (`torch.dtype`, *optional*):
280+
dtype (`torch.dtype`, *optional*):
281281
Override the default `torch.dtype` and load the model with another dtype.
282282
force_download (`bool`, *optional*, defaults to `False`):
283283
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
@@ -351,6 +351,8 @@ def from_single_file(cls, pretrained_model_link_or_path_or_dict: str | None = No
351351
revision = kwargs.pop("revision", None)
352352
config_revision = kwargs.pop("config_revision", None)
353353
torch_dtype = kwargs.pop("torch_dtype", None)
354+
dtype = kwargs.pop("dtype", None)
355+
torch_dtype = dtype if dtype is not None else torch_dtype
354356
quantization_config = kwargs.pop("quantization_config", None)
355357
low_cpu_mem_usage = kwargs.pop("low_cpu_mem_usage", _LOW_CPU_MEM_USAGE_DEFAULT)
356358
device = kwargs.pop("device", None)

src/diffusers/models/adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def from_pretrained(cls, pretrained_model_path: str | os.PathLike | None, **kwar
166166
pretrained_model_path (`os.PathLike`):
167167
A path to a *directory* containing model weights saved using
168168
[`~diffusers.models.adapter.MultiAdapter.save_pretrained`], e.g., `./my_model_directory/adapter`.
169-
torch_dtype (`torch.dtype`, *optional*):
169+
dtype (`torch.dtype`, *optional*):
170170
Override the default `torch.dtype` and load the model under this dtype.
171171
output_loading_info(`bool`, *optional*, defaults to `False`):
172172
Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.

src/diffusers/models/auto_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def from_pretrained(cls, pretrained_model_or_path: str | os.PathLike | None = No
173173
cache_dir (`str | os.PathLike`, *optional*):
174174
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
175175
is not used.
176-
torch_dtype (`torch.dtype`, *optional*):
176+
dtype (`torch.dtype`, *optional*):
177177
Override the default `torch.dtype` and load the model with another dtype.
178178
force_download (`bool`, *optional*, defaults to `False`):
179179
Whether or not to force the (re-)download of the model weights and configuration files, overriding the

src/diffusers/models/controlnets/multicontrolnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def from_pretrained(cls, pretrained_model_path: str | os.PathLike | None, **kwar
163163
A path to a *directory* containing model weights saved using
164164
[`~models.controlnets.multicontrolnet.MultiControlNetModel.save_pretrained`], e.g.,
165165
`./my_model_directory/controlnet`.
166-
torch_dtype (`torch.dtype`, *optional*):
166+
dtype (`torch.dtype`, *optional*):
167167
Override the default `torch.dtype` and load the model under this dtype.
168168
output_loading_info(`bool`, *optional*, defaults to `False`):
169169
Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.

src/diffusers/models/controlnets/multicontrolnet_union.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def from_pretrained(cls, pretrained_model_path: str | os.PathLike | None, **kwar
180180
A path to a *directory* containing model weights saved using
181181
[`~models.controlnets.multicontrolnet.MultiControlNetUnionModel.save_pretrained`], e.g.,
182182
`./my_model_directory/controlnet`.
183-
torch_dtype (`torch.dtype`, *optional*):
183+
dtype (`torch.dtype`, *optional*):
184184
Override the default `torch.dtype` and load the model under this dtype.
185185
output_loading_info(`bool`, *optional*, defaults to `False`):
186186
Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.

src/diffusers/models/modeling_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: str | os.PathLike | None
892892
cache_dir (`str | os.PathLike`, *optional*):
893893
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
894894
is not used.
895-
torch_dtype (`torch.dtype`, *optional*):
895+
dtype (`torch.dtype`, *optional*):
896896
Override the default `torch.dtype` and load the model with another dtype.
897897
force_download (`bool`, *optional*, defaults to `False`):
898898
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
@@ -1018,6 +1018,8 @@ def from_pretrained(cls, pretrained_model_name_or_path: str | os.PathLike | None
10181018
token = kwargs.pop("token", None)
10191019
revision = kwargs.pop("revision", None)
10201020
torch_dtype = kwargs.pop("torch_dtype", None)
1021+
dtype = kwargs.pop("dtype", None)
1022+
torch_dtype = dtype if dtype is not None else torch_dtype
10211023
subfolder = kwargs.pop("subfolder", None)
10221024
device_map = kwargs.pop("device_map", None)
10231025
max_memory = kwargs.pop("max_memory", None)

src/diffusers/modular_pipelines/modular_pipeline_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,11 @@ def load(self, **kwargs) -> Any:
311311

312312
from diffusers import AutoModel
313313

314-
# `torch_dtype` is not an accepted parameter for tokenizers and processors.
314+
# `dtype`/`torch_dtype` is not an accepted parameter for tokenizers and processors.
315315
# As a result, it gets stored in `init_kwargs`, which are written to the config
316316
# during save. This causes JSON serialization to fail when saving the component.
317317
if self.type_hint is not None and not issubclass(self.type_hint, (torch.nn.Module, AutoModel)):
318+
kwargs.pop("dtype", None)
318319
kwargs.pop("torch_dtype", None)
319320

320321
if self.type_hint is None:

src/diffusers/pipelines/auto_pipeline.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def from_pretrained(cls, pretrained_model_or_path, **kwargs):
426426
- A path to a *directory* (for example `./my_pipeline_directory/`) containing pipeline weights
427427
saved using
428428
[`~DiffusionPipeline.save_pretrained`].
429-
torch_dtype (`torch.dtype`, *optional*):
429+
dtype (`torch.dtype`, *optional*):
430430
Override the default `torch.dtype` and load the model with another dtype.
431431
force_download (`bool`, *optional*, defaults to `False`):
432432
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
@@ -717,7 +717,7 @@ def from_pretrained(cls, pretrained_model_or_path, **kwargs):
717717
- A path to a *directory* (for example `./my_pipeline_directory/`) containing pipeline weights
718718
saved using
719719
[`~DiffusionPipeline.save_pretrained`].
720-
torch_dtype (`str` or `torch.dtype`, *optional*):
720+
dtype (`str` or `torch.dtype`, *optional*):
721721
Override the default `torch.dtype` and load the model with another dtype.
722722
force_download (`bool`, *optional*, defaults to `False`):
723723
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
@@ -1022,7 +1022,7 @@ def from_pretrained(cls, pretrained_model_or_path, **kwargs):
10221022
- A path to a *directory* (for example `./my_pipeline_directory/`) containing pipeline weights
10231023
saved using
10241024
[`~DiffusionPipeline.save_pretrained`].
1025-
torch_dtype (`str` or `torch.dtype`, *optional*):
1025+
dtype (`str` or `torch.dtype`, *optional*):
10261026
Override the default `torch.dtype` and load the model with another dtype.
10271027
force_download (`bool`, *optional*, defaults to `False`):
10281028
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
@@ -1312,7 +1312,7 @@ def from_pretrained(cls, pretrained_model_or_path, **kwargs):
13121312
- A path to a *directory* (for example `./my_pipeline_directory/`) containing pipeline weights
13131313
saved using
13141314
[`~DiffusionPipeline.save_pretrained`].
1315-
torch_dtype (`torch.dtype`, *optional*):
1315+
dtype (`torch.dtype`, *optional*):
13161316
Override the default `torch.dtype` and load the model with another dtype.
13171317
force_download (`bool`, *optional*, defaults to `False`):
13181318
Whether or not to force the (re-)download of the model weights and configuration files, overriding the

src/diffusers/pipelines/pipeline_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: str | os.PathLike, **kwa
639639
saved using
640640
[`~DiffusionPipeline.save_pretrained`].
641641
- A path to a *directory* (for example `./my_pipeline_directory/`) containing a dduf file
642-
torch_dtype (`torch.dtype` or `dict[str, Union[str, torch.dtype]]`, *optional*):
642+
dtype (`torch.dtype` or `dict[str, Union[str, torch.dtype]]`, *optional*):
643643
Override the default `torch.dtype` and load the model with another dtype. To load submodels with
644644
different dtype pass a `dict` (for example `{'transformer': torch.bfloat16, 'vae': torch.float16}`).
645645
Set the default dtype for unspecified components with `default` (for example `{'transformer':
@@ -769,6 +769,8 @@ def from_pretrained(cls, pretrained_model_name_or_path: str | os.PathLike, **kwa
769769
revision = kwargs.pop("revision", None)
770770
from_flax = kwargs.pop("from_flax", False)
771771
torch_dtype = kwargs.pop("torch_dtype", None)
772+
dtype = kwargs.pop("dtype", None)
773+
torch_dtype = dtype if dtype is not None else torch_dtype
772774
custom_pipeline = kwargs.pop("custom_pipeline", None)
773775
custom_revision = kwargs.pop("custom_revision", None)
774776
provider = kwargs.pop("provider", None)
@@ -2121,7 +2123,9 @@ def from_pipe(cls, pipeline, **kwargs):
21212123
"""
21222124

21232125
original_config = dict(pipeline.config)
2124-
torch_dtype = kwargs.pop("torch_dtype", torch.float32)
2126+
torch_dtype = kwargs.pop("torch_dtype", None)
2127+
dtype = kwargs.pop("dtype", None)
2128+
torch_dtype = dtype if dtype is not None else (torch_dtype if torch_dtype is not None else torch.float32)
21252129
trust_remote_code = kwargs.pop("trust_remote_code", False)
21262130

21272131
# derive the pipeline class to instantiate

0 commit comments

Comments
 (0)