Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/diffusers/pipelines/pipeline_loading_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,13 +801,7 @@ def load_sub_model(
# add kwargs to loading method
diffusers_module = importlib.import_module(__name__.split(".")[0])
loading_kwargs = {}
if issubclass(class_obj, torch.nn.Module):
loading_kwargs["torch_dtype"] = torch_dtype
if issubclass(class_obj, diffusers_module.OnnxRuntimeModel):
loading_kwargs["provider"] = provider
loading_kwargs["sess_options"] = sess_options
loading_kwargs["provider_options"] = provider_options


is_diffusers_model = issubclass(class_obj, diffusers_module.ModelMixin)

if is_transformers_available():
Expand All @@ -820,6 +814,17 @@ def load_sub_model(
and issubclass(class_obj, PreTrainedModel)
and transformers_version >= version.parse("4.20.0")
)

# For transformers models, use 'dtype' instead of 'torch_dtype' to avoid deprecation warnings
if issubclass(class_obj, torch.nn.Module):
if is_transformers_model:
loading_kwargs["dtype"] = torch_dtype
else:
loading_kwargs["torch_dtype"] = torch_dtype
if issubclass(class_obj, diffusers_module.OnnxRuntimeModel):
loading_kwargs["provider"] = provider
loading_kwargs["sess_options"] = sess_options
loading_kwargs["provider_options"] = provider_options

# When loading a transformers model, if the device_map is None, the weights will be initialized as opposed to diffusers.
# To make default loading faster we set the `low_cpu_mem_usage=low_cpu_mem_usage` flag which is `True` by default.
Expand Down