From b4964b88706689e76bd09454f91f1107039d0d24 Mon Sep 17 00:00:00 2001 From: stevhliu Date: Fri, 10 Jul 2026 09:31:36 -0700 Subject: [PATCH] alias --- src/diffusers/loaders/single_file.py | 4 +++- src/diffusers/loaders/single_file_model.py | 4 +++- src/diffusers/models/adapter.py | 2 +- src/diffusers/models/auto_model.py | 2 +- src/diffusers/models/controlnets/multicontrolnet.py | 2 +- src/diffusers/models/controlnets/multicontrolnet_union.py | 2 +- src/diffusers/models/modeling_utils.py | 4 +++- src/diffusers/modular_pipelines/modular_pipeline_utils.py | 3 ++- src/diffusers/pipelines/auto_pipeline.py | 8 ++++---- src/diffusers/pipelines/pipeline_utils.py | 8 ++++++-- 10 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/diffusers/loaders/single_file.py b/src/diffusers/loaders/single_file.py index e1cc7f5afe1e..881ff9b96a4c 100644 --- a/src/diffusers/loaders/single_file.py +++ b/src/diffusers/loaders/single_file.py @@ -281,7 +281,7 @@ def from_single_file(cls, pretrained_model_link_or_path, **kwargs) -> Self: - A link to the `.ckpt` file (for example `"https://huggingface.co//blob/main/.ckpt"`) on the Hub. - A path to a *file* containing all pipeline weights. - torch_dtype (`str` or `torch.dtype`, *optional*): + dtype (`str` or `torch.dtype`, *optional*): Override the default `torch.dtype` and load the model with another dtype. force_download (`bool`, *optional*, defaults to `False`): 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: local_files_only = kwargs.pop("local_files_only", False) revision = kwargs.pop("revision", None) torch_dtype = kwargs.pop("torch_dtype", None) + dtype = kwargs.pop("dtype", None) + torch_dtype = dtype if dtype is not None else torch_dtype disable_mmap = kwargs.pop("disable_mmap", False) is_legacy_loading = False diff --git a/src/diffusers/loaders/single_file_model.py b/src/diffusers/loaders/single_file_model.py index 9c8508914f3d..56770fd9b6c3 100644 --- a/src/diffusers/loaders/single_file_model.py +++ b/src/diffusers/loaders/single_file_model.py @@ -277,7 +277,7 @@ def from_single_file(cls, pretrained_model_link_or_path_or_dict: str | None = No original_config (`str`, *optional*): Dict or path to a yaml file containing the configuration for the model in its original format. If a dict is provided, it will be used to initialize the model configuration. - torch_dtype (`torch.dtype`, *optional*): + dtype (`torch.dtype`, *optional*): Override the default `torch.dtype` and load the model with another dtype. force_download (`bool`, *optional*, defaults to `False`): 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 revision = kwargs.pop("revision", None) config_revision = kwargs.pop("config_revision", None) torch_dtype = kwargs.pop("torch_dtype", None) + dtype = kwargs.pop("dtype", None) + torch_dtype = dtype if dtype is not None else torch_dtype quantization_config = kwargs.pop("quantization_config", None) low_cpu_mem_usage = kwargs.pop("low_cpu_mem_usage", _LOW_CPU_MEM_USAGE_DEFAULT) device = kwargs.pop("device", None) diff --git a/src/diffusers/models/adapter.py b/src/diffusers/models/adapter.py index d387859ffbd1..1d146e5575c7 100644 --- a/src/diffusers/models/adapter.py +++ b/src/diffusers/models/adapter.py @@ -166,7 +166,7 @@ def from_pretrained(cls, pretrained_model_path: str | os.PathLike | None, **kwar pretrained_model_path (`os.PathLike`): A path to a *directory* containing model weights saved using [`~diffusers.models.adapter.MultiAdapter.save_pretrained`], e.g., `./my_model_directory/adapter`. - torch_dtype (`torch.dtype`, *optional*): + dtype (`torch.dtype`, *optional*): Override the default `torch.dtype` and load the model under this dtype. output_loading_info(`bool`, *optional*, defaults to `False`): Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages. diff --git a/src/diffusers/models/auto_model.py b/src/diffusers/models/auto_model.py index d3010266ef70..83ba3bca3c1a 100644 --- a/src/diffusers/models/auto_model.py +++ b/src/diffusers/models/auto_model.py @@ -173,7 +173,7 @@ def from_pretrained(cls, pretrained_model_or_path: str | os.PathLike | None = No cache_dir (`str | os.PathLike`, *optional*): Path to a directory where a downloaded pretrained model configuration is cached if the standard cache is not used. - torch_dtype (`torch.dtype`, *optional*): + dtype (`torch.dtype`, *optional*): Override the default `torch.dtype` and load the model with another dtype. force_download (`bool`, *optional*, defaults to `False`): Whether or not to force the (re-)download of the model weights and configuration files, overriding the diff --git a/src/diffusers/models/controlnets/multicontrolnet.py b/src/diffusers/models/controlnets/multicontrolnet.py index 995637c965d3..0ba9f9264f7b 100644 --- a/src/diffusers/models/controlnets/multicontrolnet.py +++ b/src/diffusers/models/controlnets/multicontrolnet.py @@ -163,7 +163,7 @@ def from_pretrained(cls, pretrained_model_path: str | os.PathLike | None, **kwar A path to a *directory* containing model weights saved using [`~models.controlnets.multicontrolnet.MultiControlNetModel.save_pretrained`], e.g., `./my_model_directory/controlnet`. - torch_dtype (`torch.dtype`, *optional*): + dtype (`torch.dtype`, *optional*): Override the default `torch.dtype` and load the model under this dtype. output_loading_info(`bool`, *optional*, defaults to `False`): Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages. diff --git a/src/diffusers/models/controlnets/multicontrolnet_union.py b/src/diffusers/models/controlnets/multicontrolnet_union.py index 577492074243..92fe1b0019f2 100644 --- a/src/diffusers/models/controlnets/multicontrolnet_union.py +++ b/src/diffusers/models/controlnets/multicontrolnet_union.py @@ -180,7 +180,7 @@ def from_pretrained(cls, pretrained_model_path: str | os.PathLike | None, **kwar A path to a *directory* containing model weights saved using [`~models.controlnets.multicontrolnet.MultiControlNetUnionModel.save_pretrained`], e.g., `./my_model_directory/controlnet`. - torch_dtype (`torch.dtype`, *optional*): + dtype (`torch.dtype`, *optional*): Override the default `torch.dtype` and load the model under this dtype. output_loading_info(`bool`, *optional*, defaults to `False`): Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages. diff --git a/src/diffusers/models/modeling_utils.py b/src/diffusers/models/modeling_utils.py index 650ab4c7fcda..d79994de6efb 100644 --- a/src/diffusers/models/modeling_utils.py +++ b/src/diffusers/models/modeling_utils.py @@ -892,7 +892,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: str | os.PathLike | None cache_dir (`str | os.PathLike`, *optional*): Path to a directory where a downloaded pretrained model configuration is cached if the standard cache is not used. - torch_dtype (`torch.dtype`, *optional*): + dtype (`torch.dtype`, *optional*): Override the default `torch.dtype` and load the model with another dtype. force_download (`bool`, *optional*, defaults to `False`): 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 token = kwargs.pop("token", None) revision = kwargs.pop("revision", None) torch_dtype = kwargs.pop("torch_dtype", None) + dtype = kwargs.pop("dtype", None) + torch_dtype = dtype if dtype is not None else torch_dtype subfolder = kwargs.pop("subfolder", None) device_map = kwargs.pop("device_map", None) max_memory = kwargs.pop("max_memory", None) diff --git a/src/diffusers/modular_pipelines/modular_pipeline_utils.py b/src/diffusers/modular_pipelines/modular_pipeline_utils.py index 656ab253ccc2..7aa61c55ef1f 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline_utils.py +++ b/src/diffusers/modular_pipelines/modular_pipeline_utils.py @@ -311,10 +311,11 @@ def load(self, **kwargs) -> Any: from diffusers import AutoModel - # `torch_dtype` is not an accepted parameter for tokenizers and processors. + # `dtype`/`torch_dtype` is not an accepted parameter for tokenizers and processors. # As a result, it gets stored in `init_kwargs`, which are written to the config # during save. This causes JSON serialization to fail when saving the component. if self.type_hint is not None and not issubclass(self.type_hint, (torch.nn.Module, AutoModel)): + kwargs.pop("dtype", None) kwargs.pop("torch_dtype", None) if self.type_hint is None: diff --git a/src/diffusers/pipelines/auto_pipeline.py b/src/diffusers/pipelines/auto_pipeline.py index 5fe97a969a3a..ebeff02e6fbd 100644 --- a/src/diffusers/pipelines/auto_pipeline.py +++ b/src/diffusers/pipelines/auto_pipeline.py @@ -426,7 +426,7 @@ def from_pretrained(cls, pretrained_model_or_path, **kwargs): - A path to a *directory* (for example `./my_pipeline_directory/`) containing pipeline weights saved using [`~DiffusionPipeline.save_pretrained`]. - torch_dtype (`torch.dtype`, *optional*): + dtype (`torch.dtype`, *optional*): Override the default `torch.dtype` and load the model with another dtype. force_download (`bool`, *optional*, defaults to `False`): 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): - A path to a *directory* (for example `./my_pipeline_directory/`) containing pipeline weights saved using [`~DiffusionPipeline.save_pretrained`]. - torch_dtype (`str` or `torch.dtype`, *optional*): + dtype (`str` or `torch.dtype`, *optional*): Override the default `torch.dtype` and load the model with another dtype. force_download (`bool`, *optional*, defaults to `False`): 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): - A path to a *directory* (for example `./my_pipeline_directory/`) containing pipeline weights saved using [`~DiffusionPipeline.save_pretrained`]. - torch_dtype (`str` or `torch.dtype`, *optional*): + dtype (`str` or `torch.dtype`, *optional*): Override the default `torch.dtype` and load the model with another dtype. force_download (`bool`, *optional*, defaults to `False`): 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): - A path to a *directory* (for example `./my_pipeline_directory/`) containing pipeline weights saved using [`~DiffusionPipeline.save_pretrained`]. - torch_dtype (`torch.dtype`, *optional*): + dtype (`torch.dtype`, *optional*): Override the default `torch.dtype` and load the model with another dtype. force_download (`bool`, *optional*, defaults to `False`): Whether or not to force the (re-)download of the model weights and configuration files, overriding the diff --git a/src/diffusers/pipelines/pipeline_utils.py b/src/diffusers/pipelines/pipeline_utils.py index 7b653caa0657..f1bf0efe4881 100644 --- a/src/diffusers/pipelines/pipeline_utils.py +++ b/src/diffusers/pipelines/pipeline_utils.py @@ -639,7 +639,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: str | os.PathLike, **kwa saved using [`~DiffusionPipeline.save_pretrained`]. - A path to a *directory* (for example `./my_pipeline_directory/`) containing a dduf file - torch_dtype (`torch.dtype` or `dict[str, Union[str, torch.dtype]]`, *optional*): + dtype (`torch.dtype` or `dict[str, Union[str, torch.dtype]]`, *optional*): Override the default `torch.dtype` and load the model with another dtype. To load submodels with different dtype pass a `dict` (for example `{'transformer': torch.bfloat16, 'vae': torch.float16}`). 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 revision = kwargs.pop("revision", None) from_flax = kwargs.pop("from_flax", False) torch_dtype = kwargs.pop("torch_dtype", None) + dtype = kwargs.pop("dtype", None) + torch_dtype = dtype if dtype is not None else torch_dtype custom_pipeline = kwargs.pop("custom_pipeline", None) custom_revision = kwargs.pop("custom_revision", None) provider = kwargs.pop("provider", None) @@ -2121,7 +2123,9 @@ def from_pipe(cls, pipeline, **kwargs): """ original_config = dict(pipeline.config) - torch_dtype = kwargs.pop("torch_dtype", torch.float32) + torch_dtype = kwargs.pop("torch_dtype", None) + dtype = kwargs.pop("dtype", None) + torch_dtype = dtype if dtype is not None else (torch_dtype if torch_dtype is not None else torch.float32) trust_remote_code = kwargs.pop("trust_remote_code", False) # derive the pipeline class to instantiate