From 7b53aa1484844dd9845b8cb0eeed39b747c3b129 Mon Sep 17 00:00:00 2001 From: DN6 Date: Thu, 29 Oct 2026 16:11:47 +0530 Subject: [PATCH 1/6] [core] Enforce minimum supported versions in availability checks --- src/diffusers/loaders/ip_adapter.py | 25 ----- src/diffusers/loaders/single_file_model.py | 4 +- src/diffusers/loaders/transformer_flux.py | 14 +-- src/diffusers/loaders/transformer_sd3.py | 14 +-- src/diffusers/loaders/unet.py | 13 --- src/diffusers/models/activations.py | 8 +- src/diffusers/models/attention_processor.py | 14 +-- src/diffusers/models/model_loading_utils.py | 7 +- src/diffusers/models/modeling_utils.py | 37 +------- src/diffusers/models/normalization.py | 39 +------- .../models/transformers/transformer_ltx.py | 8 +- .../models/transformers/transformer_ltx2.py | 14 +-- .../transformer_sana_wm_refiner.py | 14 +-- src/diffusers/models/upsampling.py | 11 --- .../modular_pipelines/modular_pipeline.py | 4 +- src/diffusers/pipelines/ace_step/__init__.py | 5 +- src/diffusers/pipelines/audioldm2/__init__.py | 5 +- .../pipelines/audioldm2/pipeline_audioldm2.py | 3 +- .../controlnet/pipeline_controlnet.py | 5 +- .../controlnet/pipeline_controlnet_sd_xl.py | 9 +- .../pipeline_controlnet_union_sd_xl.py | 5 +- .../pipelines/deprecated/audioldm/__init__.py | 5 +- .../controlnet_xs/pipeline_controlnet_xs.py | 5 +- .../pipeline_controlnet_xs_sd_xl.py | 5 +- .../pipelines/deprecated/musicldm/__init__.py | 5 +- .../deprecated/musicldm/pipeline_musicldm.py | 3 +- .../pipelines/deprecated/unclip/__init__.py | 5 +- .../versatile_diffusion/__init__.py | 5 +- .../pag/pipeline_pag_controlnet_sd.py | 9 +- .../pag/pipeline_pag_controlnet_sd_xl.py | 9 +- src/diffusers/pipelines/pipeline_utils.py | 25 +---- .../pipelines/stable_audio/__init__.py | 5 +- .../stable_cascade/pipeline_stable_cascade.py | 4 +- .../pipeline_stable_cascade_combined.py | 8 +- .../pipelines/stable_diffusion/__init__.py | 9 +- src/diffusers/quantizers/bfl/bfl_quantizer.py | 4 +- .../quantizers/bitsandbytes/bnb_quantizer.py | 10 +- .../quantizers/gguf/gguf_quantizer.py | 6 +- .../quantizers/quantization_config.py | 6 +- .../quantizers/quanto/quanto_quantizer.py | 25 ++--- .../quantizers/sdnq/sdnq_quantizer.py | 17 +--- .../quantizers/torchao/torchao_quantizer.py | 11 +-- src/diffusers/utils/import_utils.py | 91 ++++++++++--------- src/diffusers/utils/outputs.py | 21 ++--- src/diffusers/utils/torch_utils.py | 2 +- tests/others/test_dependencies.py | 21 +++++ 46 files changed, 156 insertions(+), 418 deletions(-) diff --git a/src/diffusers/loaders/ip_adapter.py b/src/diffusers/loaders/ip_adapter.py index 5f8d3f48c997..aab341cccdee 100644 --- a/src/diffusers/loaders/ip_adapter.py +++ b/src/diffusers/loaders/ip_adapter.py @@ -27,7 +27,6 @@ _get_model_file, _is_valid_type, is_accelerate_available, - is_torch_version, is_transformers_available, is_transformers_version, logging, @@ -152,12 +151,6 @@ def load_ip_adapter( " install accelerate\n```\n." ) - if low_cpu_mem_usage is True and not is_torch_version(">=", "1.9.0"): - raise NotImplementedError( - "Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set" - " `low_cpu_mem_usage=False`." - ) - user_agent = {"file_type": "attn_procs_weights", "framework": "pytorch"} state_dicts = [] for pretrained_model_name_or_path_or_dict, weight_name, subfolder in zip( @@ -451,12 +444,6 @@ def load_ip_adapter( " install accelerate\n```\n." ) - if low_cpu_mem_usage is True and not is_torch_version(">=", "1.9.0"): - raise NotImplementedError( - "Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set" - " `low_cpu_mem_usage=False`." - ) - user_agent = { "file_type": "attn_procs_weights", "framework": "pytorch", @@ -711,12 +698,6 @@ def load_ip_adapter( " install accelerate\n```\n." ) - if low_cpu_mem_usage is True and not is_torch_version(">=", "1.9.0"): - raise NotImplementedError( - "Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set" - " `low_cpu_mem_usage=False`." - ) - user_agent = {"file_type": "attn_procs_weights", "framework": "pytorch"} state_dicts = [] for pretrained_model_name_or_path_or_dict, weight_name, subfolder in zip( @@ -996,12 +977,6 @@ def load_ip_adapter( " install accelerate\n```\n." ) - if low_cpu_mem_usage is True and not is_torch_version(">=", "1.9.0"): - raise NotImplementedError( - "Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set" - " `low_cpu_mem_usage=False`." - ) - user_agent = {"file_type": "attn_procs_weights", "framework": "pytorch"} if not isinstance(pretrained_model_name_or_path_or_dict, dict): diff --git a/src/diffusers/loaders/single_file_model.py b/src/diffusers/loaders/single_file_model.py index 610e377d3ab9..2ffaf3cb37c0 100644 --- a/src/diffusers/loaders/single_file_model.py +++ b/src/diffusers/loaders/single_file_model.py @@ -27,7 +27,7 @@ _expand_device_map, ) from ..quantizers import DiffusersAutoQuantizer -from ..utils import deprecate, is_accelerate_available, is_torch_version, logging +from ..utils import deprecate, is_accelerate_available, logging from ..utils.torch_utils import empty_device_cache from .single_file_utils import ( SingleFileComponentError, @@ -80,7 +80,7 @@ from ..models.model_loading_utils import load_model_dict_into_meta -if is_torch_version(">=", "1.9.0") and is_accelerate_available(): +if is_accelerate_available(): _LOW_CPU_MEM_USAGE_DEFAULT = True else: _LOW_CPU_MEM_USAGE_DEFAULT = False diff --git a/src/diffusers/loaders/transformer_flux.py b/src/diffusers/loaders/transformer_flux.py index 632f6601a6f6..e06ada822b4d 100644 --- a/src/diffusers/loaders/transformer_flux.py +++ b/src/diffusers/loaders/transformer_flux.py @@ -19,7 +19,7 @@ ) from ..models.model_loading_utils import load_model_dict_into_meta from ..models.modeling_utils import _LOW_CPU_MEM_USAGE_DEFAULT -from ..utils import is_accelerate_available, is_torch_version, logging +from ..utils import is_accelerate_available, logging from ..utils.torch_utils import empty_device_cache @@ -48,12 +48,6 @@ def _convert_ip_adapter_image_proj_to_diffusers(self, state_dict, low_cpu_mem_us " install accelerate\n```\n." ) - if low_cpu_mem_usage is True and not is_torch_version(">=", "1.9.0"): - raise NotImplementedError( - "Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set" - " `low_cpu_mem_usage=False`." - ) - updated_state_dict = {} image_projection = None init_context = init_empty_weights if low_cpu_mem_usage else nullcontext @@ -102,12 +96,6 @@ def _convert_ip_adapter_attn_to_diffusers(self, state_dicts, low_cpu_mem_usage=_ " install accelerate\n```\n." ) - if low_cpu_mem_usage is True and not is_torch_version(">=", "1.9.0"): - raise NotImplementedError( - "Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set" - " `low_cpu_mem_usage=False`." - ) - # set ip-adapter cross-attention processors & load state_dict attn_procs = {} key_id = 0 diff --git a/src/diffusers/loaders/transformer_sd3.py b/src/diffusers/loaders/transformer_sd3.py index 7fc90bf7dda4..6f16f5db0c0e 100644 --- a/src/diffusers/loaders/transformer_sd3.py +++ b/src/diffusers/loaders/transformer_sd3.py @@ -17,7 +17,7 @@ from ..models.embeddings import IPAdapterTimeImageProjection from ..models.model_loading_utils import load_model_dict_into_meta from ..models.modeling_utils import _LOW_CPU_MEM_USAGE_DEFAULT -from ..utils import is_accelerate_available, is_torch_version, logging +from ..utils import is_accelerate_available, logging from ..utils.torch_utils import empty_device_cache @@ -43,12 +43,6 @@ def _convert_ip_adapter_attn_to_diffusers( " install accelerate\n```\n." ) - if low_cpu_mem_usage is True and not is_torch_version(">=", "1.9.0"): - raise NotImplementedError( - "Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set" - " `low_cpu_mem_usage=False`." - ) - # IP-Adapter cross attention parameters hidden_size = self.config.attention_head_dim * self.config.num_attention_heads ip_hidden_states_dim = self.config.attention_head_dim * self.config.num_attention_heads @@ -101,12 +95,6 @@ def _convert_ip_adapter_image_proj_to_diffusers( " install accelerate\n```\n." ) - if low_cpu_mem_usage is True and not is_torch_version(">=", "1.9.0"): - raise NotImplementedError( - "Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set" - " `low_cpu_mem_usage=False`." - ) - init_context = init_empty_weights if low_cpu_mem_usage else nullcontext # Convert to diffusers diff --git a/src/diffusers/loaders/unet.py b/src/diffusers/loaders/unet.py index 116d7d664647..cf3de1e424a5 100644 --- a/src/diffusers/loaders/unet.py +++ b/src/diffusers/loaders/unet.py @@ -35,7 +35,6 @@ from ..utils import ( _get_model_file, is_accelerate_available, - is_torch_version, logging, ) from ..utils.torch_utils import empty_device_cache @@ -390,12 +389,6 @@ def _convert_ip_adapter_image_proj_to_diffusers(self, state_dict, low_cpu_mem_us " install accelerate\n```\n." ) - if low_cpu_mem_usage is True and not is_torch_version(">=", "1.9.0"): - raise NotImplementedError( - "Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set" - " `low_cpu_mem_usage=False`." - ) - updated_state_dict = {} image_projection = None init_context = init_empty_weights if low_cpu_mem_usage else nullcontext @@ -615,12 +608,6 @@ def _convert_ip_adapter_attn_to_diffusers(self, state_dicts, low_cpu_mem_usage=_ " install accelerate\n```\n." ) - if low_cpu_mem_usage is True and not is_torch_version(">=", "1.9.0"): - raise NotImplementedError( - "Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set" - " `low_cpu_mem_usage=False`." - ) - # set ip-adapter cross-attention processors & load state_dict attn_procs = {} key_id = 1 diff --git a/src/diffusers/models/activations.py b/src/diffusers/models/activations.py index caff731dd599..2206426e66f1 100644 --- a/src/diffusers/models/activations.py +++ b/src/diffusers/models/activations.py @@ -18,7 +18,7 @@ from torch import nn from ..utils import deprecate -from ..utils.import_utils import is_torch_npu_available, is_torch_version +from ..utils.import_utils import is_torch_npu_available if is_torch_npu_available(): @@ -79,9 +79,6 @@ def __init__(self, dim_in: int, dim_out: int, approximate: str = "none", bias: b self.approximate = approximate def gelu(self, gate: torch.Tensor) -> torch.Tensor: - if gate.device.type == "mps" and is_torch_version("<", "2.0.0"): - # fp16 gelu not supported on mps before torch 2.0 - return F.gelu(gate.to(dtype=torch.float32), approximate=self.approximate).to(dtype=gate.dtype) return F.gelu(gate, approximate=self.approximate) def forward(self, hidden_states) -> torch.Tensor: @@ -105,9 +102,6 @@ def __init__(self, dim_in: int, dim_out: int, bias: bool = True): self.proj = nn.Linear(dim_in, dim_out * 2, bias=bias) def gelu(self, gate: torch.Tensor) -> torch.Tensor: - if gate.device.type == "mps" and is_torch_version("<", "2.0.0"): - # fp16 gelu not supported on mps before torch 2.0 - return F.gelu(gate.to(dtype=torch.float32)).to(dtype=gate.dtype) return F.gelu(gate) def forward(self, hidden_states, *args, **kwargs) -> torch.Tensor: diff --git a/src/diffusers/models/attention_processor.py b/src/diffusers/models/attention_processor.py index 62484a113f37..d01348639ee6 100755 --- a/src/diffusers/models/attention_processor.py +++ b/src/diffusers/models/attention_processor.py @@ -24,7 +24,7 @@ from ..image_processor import IPAdapterMaskProcessor from ..utils import deprecate, is_torch_xla_available, logging from ..utils.import_utils import is_torch_npu_available, is_torch_xla_version, is_xformers_available -from ..utils.torch_utils import is_torch_version, maybe_allow_in_graph +from ..utils.torch_utils import maybe_allow_in_graph logger = logging.get_logger(__name__) # pylint: disable=invalid-name @@ -2087,12 +2087,6 @@ def __call__( class AuraFlowAttnProcessor2_0: """Attention processor used typically in processing Aura Flow.""" - def __init__(self): - if not hasattr(F, "scaled_dot_product_attention") and is_torch_version("<", "2.1"): - raise ImportError( - "AuraFlowAttnProcessor2_0 requires PyTorch 2.0, to use it, please upgrade PyTorch to at least 2.1 or above as we use `scale` in `F.scaled_dot_product_attention()`. " - ) - def __call__( self, attn: Attention, @@ -2180,12 +2174,6 @@ def __call__( class FusedAuraFlowAttnProcessor2_0: """Attention processor used typically in processing Aura Flow with fused projections.""" - def __init__(self): - if not hasattr(F, "scaled_dot_product_attention") and is_torch_version("<", "2.1"): - raise ImportError( - "FusedAuraFlowAttnProcessor2_0 requires PyTorch 2.0, to use it, please upgrade PyTorch to at least 2.1 or above as we use `scale` in `F.scaled_dot_product_attention()`. " - ) - def __call__( self, attn: Attention, diff --git a/src/diffusers/models/model_loading_utils.py b/src/diffusers/models/model_loading_utils.py index b6d9d7997d81..56ae25e9fd63 100644 --- a/src/diffusers/models/model_loading_utils.py +++ b/src/diffusers/models/model_loading_utils.py @@ -42,7 +42,6 @@ is_accelerate_version, is_gguf_available, is_torch_available, - is_torch_version, logging, ) from ..utils.distributed_utils import is_torch_dist_rank_zero @@ -173,17 +172,15 @@ def load_state_dict( return load_gguf_checkpoint(checkpoint_file) else: extra_args = {} - weights_only_kwarg = {"weights_only": True} if is_torch_version(">=", "1.13") else {} # mmap can only be used with files serialized with zipfile-based format. if ( isinstance(checkpoint_file, str) and map_location != "meta" - and is_torch_version(">=", "2.1.0") and is_zipfile(checkpoint_file) and not disable_mmap ): extra_args = {"mmap": True} - return torch.load(checkpoint_file, map_location=map_location, **weights_only_kwarg, **extra_args) + return torch.load(checkpoint_file, map_location=map_location, weights_only=True, **extra_args) except Exception as e: try: with open(checkpoint_file) as f: @@ -549,8 +546,6 @@ def _load_state_dict_into_model( def load(module: torch.nn.Module, prefix: str = "", assign_to_params_buffers: bool = False): local_metadata = {} local_metadata["assign_to_params_buffers"] = assign_to_params_buffers - if assign_to_params_buffers and not is_torch_version(">=", "2.1"): - logger.info("You need to have torch>=2.1 in order to load the model with assign_to_params_buffers=True") args = (state_dict, prefix, local_metadata, True, [], [], error_msgs) module._load_from_state_dict(*args) diff --git a/src/diffusers/models/modeling_utils.py b/src/diffusers/models/modeling_utils.py index 469906613a5e..8692bbb179b7 100644 --- a/src/diffusers/models/modeling_utils.py +++ b/src/diffusers/models/modeling_utils.py @@ -58,7 +58,6 @@ is_bitsandbytes_version, is_flashpack_available, is_peft_available, - is_torch_version, logging, ) from ..utils.distributed_utils import is_torch_dist_rank_zero @@ -127,10 +126,7 @@ def __exit__(self, *args, **kwargs): "kaiming_normal": nn.init.kaiming_normal, } -if is_torch_version(">=", "1.9.0"): - _LOW_CPU_MEM_USAGE_DEFAULT = True -else: - _LOW_CPU_MEM_USAGE_DEFAULT = False +_LOW_CPU_MEM_USAGE_DEFAULT = True if is_accelerate_available(): @@ -313,11 +309,10 @@ def enable_gradient_checkpointing(self, gradient_checkpointing_func: Callable | if gradient_checkpointing_func is None: def _gradient_checkpointing_func(module, *args): - ckpt_kwargs = {"use_reentrant": False} if is_torch_version(">=", "1.11.0") else {} return torch.utils.checkpoint.checkpoint( module.__call__, *args, - **ckpt_kwargs, + use_reentrant=False, ) gradient_checkpointing_func = _gradient_checkpointing_func @@ -1091,19 +1086,6 @@ def from_pretrained(cls, pretrained_model_name_or_path: str | os.PathLike | None " `device_map=None`. You can install accelerate with `pip install accelerate`." ) - # Check if we can handle device_map and dispatching the weights - if device_map is not None and not is_torch_version(">=", "1.9.0"): - raise NotImplementedError( - "Loading and dispatching requires torch >= 1.9.0. Please either update your PyTorch version or set" - " `device_map=None`." - ) - - if low_cpu_mem_usage is True and not is_torch_version(">=", "1.9.0"): - raise NotImplementedError( - "Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set" - " `low_cpu_mem_usage=False`." - ) - if low_cpu_mem_usage is False and device_map is not None: raise ValueError( f"You cannot set `low_cpu_mem_usage` to `False` while using device_map={device_map} for loading and" @@ -1135,11 +1117,6 @@ def from_pretrained(cls, pretrained_model_name_or_path: str | os.PathLike | None elif not low_cpu_mem_usage: raise ValueError("Passing along a `device_map` requires `low_cpu_mem_usage=True`") - if low_cpu_mem_usage: - if device_map is not None and not is_torch_version(">=", "1.10"): - # The max memory utils require PyTorch >= 1.10 to have torch.cuda.mem_get_info. - raise ValueError("`low_cpu_mem_usage` and `device_map` require PyTorch >= 1.10.") - user_agent = { "diffusers": __version__, "file_type": "model", @@ -1567,11 +1544,6 @@ def cuda(self, *args, **kwargs): "Calling `cuda()` is not supported for `8-bit` quantized models with the installed version of bitsandbytes. " f"The current device is `{self.device}`. If you intended to move the model, please install bitsandbytes >= 0.48.0." ) - elif getattr(self, "is_loaded_in_4bit", False) and is_bitsandbytes_version("<", "0.43.2"): - raise ValueError( - "Calling `cuda()` is not supported for `4-bit` quantized models with the installed version of bitsandbytes. " - f"The current device is `{self.device}`. If you intended to move the model, please install bitsandbytes >= 0.43.2." - ) # Checks if group offloading is enabled if _is_group_offload_enabled(self): @@ -1626,11 +1598,6 @@ def to(self, *args, **kwargs): "Calling `to()` is not supported for `8-bit` quantized models with the installed version of bitsandbytes. " f"The current device is `{self.device}`. If you intended to move the model, please install bitsandbytes >= 0.48.0." ) - elif getattr(self, "is_loaded_in_4bit", False) and is_bitsandbytes_version("<", "0.43.2"): - raise ValueError( - "Calling `to()` is not supported for `4-bit` quantized models with the installed version of bitsandbytes. " - f"The current device is `{self.device}`. If you intended to move the model, please install bitsandbytes >= 0.43.2." - ) if _is_group_offload_enabled(self) and device_arg_or_kwarg_present: logger.warning( f"The module '{self.__class__.__name__}' is group offloaded and moving it using `.to()` is not supported." diff --git a/src/diffusers/models/normalization.py b/src/diffusers/models/normalization.py index 4b4ba78dc679..cd4b3fd167ee 100644 --- a/src/diffusers/models/normalization.py +++ b/src/diffusers/models/normalization.py @@ -19,7 +19,7 @@ import torch.nn as nn import torch.nn.functional as F -from ..utils import is_torch_npu_available, is_torch_version +from ..utils import is_torch_npu_available from .activations import get_activation from .embeddings import CombinedTimestepLabelEmbeddings, PixArtAlphaCombinedTimestepSizeEmbeddings @@ -469,42 +469,7 @@ def forward( return hidden_states, encoder_hidden_states, gate[:, None, :], enc_gate[:, None, :] -if is_torch_version(">=", "2.1.0"): - LayerNorm = nn.LayerNorm -else: - # Has optional bias parameter compared to torch layer norm - # TODO: replace with torch layernorm once min required torch version >= 2.1 - class LayerNorm(nn.Module): - r""" - LayerNorm with the bias parameter. - - Args: - dim (`int`): Dimensionality to use for the parameters. - eps (`float`, defaults to 1e-5): Epsilon factor. - elementwise_affine (`bool`, defaults to `True`): - Boolean flag to denote if affine transformation should be applied. - bias (`bias`, defaults to `True`): Boolean flag to denote if bias should be use. - """ - - def __init__(self, dim, eps: float = 1e-5, elementwise_affine: bool = True, bias: bool = True): - super().__init__() - - self.eps = eps - - if isinstance(dim, numbers.Integral): - dim = (dim,) - - self.dim = torch.Size(dim) - - if elementwise_affine: - self.weight = nn.Parameter(torch.ones(dim)) - self.bias = nn.Parameter(torch.zeros(dim)) if bias else None - else: - self.weight = None - self.bias = None - - def forward(self, input) -> torch.Tensor: - return F.layer_norm(input, self.dim, self.weight, self.bias, self.eps) +LayerNorm = nn.LayerNorm class RMSNorm(nn.Module): diff --git a/src/diffusers/models/transformers/transformer_ltx.py b/src/diffusers/models/transformers/transformer_ltx.py index c33e0f6141fc..c8d8239eb2c9 100644 --- a/src/diffusers/models/transformers/transformer_ltx.py +++ b/src/diffusers/models/transformers/transformer_ltx.py @@ -22,7 +22,7 @@ from ...configuration_utils import ConfigMixin, register_to_config from ...loaders import FromOriginalModelMixin, PeftAdapterMixin -from ...utils import apply_lora_scale, deprecate, is_torch_version, logging +from ...utils import apply_lora_scale, deprecate, logging from ...utils.torch_utils import maybe_allow_in_graph from .._modeling_parallel import ContextParallelInput, ContextParallelOutput from ..attention import AttentionMixin, AttentionModuleMixin, FeedForward @@ -54,12 +54,6 @@ class LTXVideoAttnProcessor: _attention_backend = None _parallel_config = None - def __init__(self): - if is_torch_version("<", "2.0"): - raise ValueError( - "LTX attention processors require a minimum PyTorch version of 2.0. Please upgrade your PyTorch installation." - ) - def __call__( self, attn: "LTXAttention", diff --git a/src/diffusers/models/transformers/transformer_ltx2.py b/src/diffusers/models/transformers/transformer_ltx2.py index e5462e4b047a..1eae1b1a7967 100644 --- a/src/diffusers/models/transformers/transformer_ltx2.py +++ b/src/diffusers/models/transformers/transformer_ltx2.py @@ -22,7 +22,7 @@ from ...configuration_utils import ConfigMixin, register_to_config from ...loaders import FromOriginalModelMixin, PeftAdapterMixin -from ...utils import BaseOutput, apply_lora_scale, is_torch_version, logging +from ...utils import BaseOutput, apply_lora_scale, logging from .._modeling_parallel import ContextParallelInput, ContextParallelOutput from ..attention import AttentionMixin, AttentionModuleMixin, FeedForward from ..attention_dispatch import dispatch_attention_fn @@ -152,12 +152,6 @@ class LTX2AudioVideoAttnProcessor: _attention_backend = None _parallel_config = None - def __init__(self): - if is_torch_version("<", "2.0"): - raise ValueError( - "LTX attention processors require a minimum PyTorch version of 2.0. Please upgrade your PyTorch installation." - ) - def __call__( self, attn: "LTX2Attention", @@ -236,12 +230,6 @@ class LTX2PerturbedAttnProcessor: _attention_backend = None _parallel_config = None - def __init__(self): - if is_torch_version("<", "2.0"): - raise ValueError( - "LTX attention processors require a minimum PyTorch version of 2.0. Please upgrade your PyTorch installation." - ) - def __call__( self, attn: "LTX2Attention", diff --git a/src/diffusers/models/transformers/transformer_sana_wm_refiner.py b/src/diffusers/models/transformers/transformer_sana_wm_refiner.py index 892eca5eb8e7..0d479afb64f6 100644 --- a/src/diffusers/models/transformers/transformer_sana_wm_refiner.py +++ b/src/diffusers/models/transformers/transformer_sana_wm_refiner.py @@ -19,7 +19,7 @@ from ...configuration_utils import ConfigMixin, register_to_config from ...loaders import FromOriginalModelMixin, PeftAdapterMixin -from ...utils import apply_lora_scale, is_torch_version, logging +from ...utils import apply_lora_scale, logging from ..attention import AttentionMixin, AttentionModuleMixin, FeedForward from ..attention_dispatch import dispatch_attention_fn from ..cache_utils import CacheMixin @@ -136,12 +136,6 @@ class SanaWMLTX2AudioVideoAttnProcessor: _attention_backend = None _parallel_config = None - def __init__(self): - if is_torch_version("<", "2.0"): - raise ValueError( - "LTX attention processors require a minimum PyTorch version of 2.0. Please upgrade your PyTorch installation." - ) - def __call__( self, attn: "SanaWMLTX2Attention", @@ -221,12 +215,6 @@ class SanaWMLTX2PerturbedAttnProcessor: _attention_backend = None _parallel_config = None - def __init__(self): - if is_torch_version("<", "2.0"): - raise ValueError( - "LTX attention processors require a minimum PyTorch version of 2.0. Please upgrade your PyTorch installation." - ) - def __call__( self, attn: "SanaWMLTX2Attention", diff --git a/src/diffusers/models/upsampling.py b/src/diffusers/models/upsampling.py index 36f22250a873..3c52ddc5fa4b 100644 --- a/src/diffusers/models/upsampling.py +++ b/src/diffusers/models/upsampling.py @@ -17,7 +17,6 @@ import torch.nn.functional as F from ..utils import deprecate -from ..utils.import_utils import is_torch_version from .normalization import RMSNorm @@ -150,12 +149,6 @@ def forward(self, hidden_states: torch.Tensor, output_size: int | None = None, * if self.use_conv_transpose: return self.conv(hidden_states) - # Cast to float32 to as 'upsample_nearest2d_out_frame' op does not support bfloat16 until PyTorch 2.1 - # https://github.com/pytorch/pytorch/issues/86679#issuecomment-1783978767 - dtype = hidden_states.dtype - if dtype == torch.bfloat16 and is_torch_version("<", "2.1"): - hidden_states = hidden_states.to(torch.float32) - # upsample_nearest_nhwc fails with large batch sizes. see https://github.com/huggingface/diffusers/issues/984 if hidden_states.shape[0] >= 64: hidden_states = hidden_states.contiguous() @@ -176,10 +169,6 @@ def forward(self, hidden_states: torch.Tensor, output_size: int | None = None, * else: hidden_states = F.interpolate(hidden_states, size=output_size, mode="nearest") - # Cast back to original dtype - if dtype == torch.bfloat16 and is_torch_version("<", "2.1"): - hidden_states = hidden_states.to(dtype) - # TODO(Suraj, Patrick) - clean up after weight dicts are correctly renamed if self.use_conv: if self.name == "conv": diff --git a/src/diffusers/modular_pipelines/modular_pipeline.py b/src/diffusers/modular_pipelines/modular_pipeline.py index a534aa20c68e..e1a59acc146e 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline.py +++ b/src/diffusers/modular_pipelines/modular_pipeline.py @@ -2725,7 +2725,7 @@ def to(self, *args, **kwargs) -> Self: # throw warning if pipeline is in "offloaded"-mode but user tries to manually set to GPU. def module_is_sequentially_offloaded(module): - if not is_accelerate_available() or is_accelerate_version("<", "0.14.0"): + if not is_accelerate_available(): return False _, _, is_loaded_in_8bit_bnb = _check_bnb_status(module) @@ -2740,7 +2740,7 @@ def module_is_sequentially_offloaded(module): ) def module_is_offloaded(module): - if not is_accelerate_available() or is_accelerate_version("<", "0.17.0.dev0"): + if not is_accelerate_available(): return False return hasattr(module, "_hf_hook") and isinstance(module._hf_hook, accelerate.hooks.CpuOffload) diff --git a/src/diffusers/pipelines/ace_step/__init__.py b/src/diffusers/pipelines/ace_step/__init__.py index 4115a8822aed..f6a8eaa7f7dd 100644 --- a/src/diffusers/pipelines/ace_step/__init__.py +++ b/src/diffusers/pipelines/ace_step/__init__.py @@ -7,7 +7,6 @@ get_objects_from_module, is_torch_available, is_transformers_available, - is_transformers_version, ) @@ -15,7 +14,7 @@ _import_structure = {} try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.27.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ...utils import dummy_torch_and_transformers_objects @@ -32,7 +31,7 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT: try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.27.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ...utils.dummy_torch_and_transformers_objects import * diff --git a/src/diffusers/pipelines/audioldm2/__init__.py b/src/diffusers/pipelines/audioldm2/__init__.py index 23cd0e44f892..0eff290c3c3f 100644 --- a/src/diffusers/pipelines/audioldm2/__init__.py +++ b/src/diffusers/pipelines/audioldm2/__init__.py @@ -7,7 +7,6 @@ get_objects_from_module, is_torch_available, is_transformers_available, - is_transformers_version, ) @@ -15,7 +14,7 @@ _import_structure = {} try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.27.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ...utils import dummy_torch_and_transformers_objects @@ -28,7 +27,7 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT: try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.27.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ...utils.dummy_torch_and_transformers_objects import * diff --git a/src/diffusers/pipelines/audioldm2/pipeline_audioldm2.py b/src/diffusers/pipelines/audioldm2/pipeline_audioldm2.py index 401cfe7fe0b3..711b484c5faf 100644 --- a/src/diffusers/pipelines/audioldm2/pipeline_audioldm2.py +++ b/src/diffusers/pipelines/audioldm2/pipeline_audioldm2.py @@ -36,7 +36,6 @@ from ...schedulers import KarrasDiffusionSchedulers from ...utils import ( is_accelerate_available, - is_accelerate_version, is_librosa_available, logging, replace_example_docstring, @@ -230,7 +229,7 @@ def enable_model_cpu_offload(self, gpu_id: int | None = None, device: torch.devi method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with `enable_sequential_cpu_offload`, but performance is much better due to the iterative execution of the `unet`. """ - if is_accelerate_available() and is_accelerate_version(">=", "0.17.0.dev0"): + if is_accelerate_available(): from accelerate import cpu_offload_with_hook else: raise ImportError("`enable_model_cpu_offload` requires `accelerate v0.17.0` or higher.") diff --git a/src/diffusers/pipelines/controlnet/pipeline_controlnet.py b/src/diffusers/pipelines/controlnet/pipeline_controlnet.py index bc95c1efb940..02d622c0f8ab 100644 --- a/src/diffusers/pipelines/controlnet/pipeline_controlnet.py +++ b/src/diffusers/pipelines/controlnet/pipeline_controlnet.py @@ -37,7 +37,7 @@ scale_lora_layers, unscale_lora_layers, ) -from ...utils.torch_utils import empty_device_cache, is_compiled_module, is_torch_version, randn_tensor +from ...utils.torch_utils import empty_device_cache, is_compiled_module, randn_tensor from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin from ..stable_diffusion.pipeline_output import StableDiffusionPipelineOutput from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker @@ -1240,7 +1240,6 @@ def __call__( num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order is_unet_compiled = is_compiled_module(self.unet) is_controlnet_compiled = is_compiled_module(self.controlnet) - is_torch_higher_equal_2_1 = is_torch_version(">=", "2.1") with self.progress_bar(total=num_inference_steps) as progress_bar: for i, t in enumerate(timesteps): if self.interrupt: @@ -1248,7 +1247,7 @@ def __call__( # Relevant thread: # https://dev-discuss.pytorch.org/t/cudagraphs-in-pytorch-2-0/1428 - if (is_unet_compiled and is_controlnet_compiled) and is_torch_higher_equal_2_1: + if is_unet_compiled and is_controlnet_compiled: torch._inductor.cudagraph_mark_step_begin() # expand the latents if we are doing classifier free guidance latent_model_input = torch.cat([latents] * 2) if self.do_classifier_free_guidance else latents diff --git a/src/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py b/src/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py index 3c75d15ea6e9..da62eb994a8d 100644 --- a/src/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +++ b/src/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py @@ -49,7 +49,7 @@ scale_lora_layers, unscale_lora_layers, ) -from ...utils.torch_utils import get_module_execution_device, is_compiled_module, is_torch_version, randn_tensor +from ...utils.torch_utils import get_module_execution_device, is_compiled_module, randn_tensor from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin from ..stable_diffusion_xl.pipeline_output import StableDiffusionXLPipelineOutput @@ -1448,7 +1448,6 @@ def __call__( is_unet_compiled = is_compiled_module(self.unet) is_controlnet_compiled = is_compiled_module(self.controlnet) - is_torch_higher_equal_2_1 = is_torch_version(">=", "2.1") with self.progress_bar(total=num_inference_steps) as progress_bar: for i, t in enumerate(timesteps): if self.interrupt: @@ -1456,11 +1455,7 @@ def __call__( # Relevant thread: # https://dev-discuss.pytorch.org/t/cudagraphs-in-pytorch-2-0/1428 - if ( - torch.cuda.is_available() - and (is_unet_compiled and is_controlnet_compiled) - and is_torch_higher_equal_2_1 - ): + if torch.cuda.is_available() and (is_unet_compiled and is_controlnet_compiled): torch._inductor.cudagraph_mark_step_begin() # expand the latents if we are doing classifier free guidance latent_model_input = torch.cat([latents] * 2) if self.do_classifier_free_guidance else latents diff --git a/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl.py b/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl.py index 2177f30b3e72..9aeafd3a117e 100644 --- a/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl.py +++ b/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl.py @@ -54,7 +54,7 @@ scale_lora_layers, unscale_lora_layers, ) -from ...utils.torch_utils import get_module_execution_device, is_compiled_module, is_torch_version, randn_tensor +from ...utils.torch_utils import get_module_execution_device, is_compiled_module, randn_tensor from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin from ..stable_diffusion_xl.pipeline_output import StableDiffusionXLPipelineOutput @@ -1443,7 +1443,6 @@ def __call__( is_unet_compiled = is_compiled_module(self.unet) is_controlnet_compiled = is_compiled_module(self.controlnet) - is_torch_higher_equal_2_1 = is_torch_version(">=", "2.1") control_type_repeat_factor = ( batch_size * num_images_per_prompt * (2 if self.do_classifier_free_guidance else 1) @@ -1470,7 +1469,7 @@ def __call__( # Relevant thread: # https://dev-discuss.pytorch.org/t/cudagraphs-in-pytorch-2-0/1428 - if (is_unet_compiled and is_controlnet_compiled) and is_torch_higher_equal_2_1: + if is_unet_compiled and is_controlnet_compiled: torch._inductor.cudagraph_mark_step_begin() # expand the latents if we are doing classifier free guidance latent_model_input = torch.cat([latents] * 2) if self.do_classifier_free_guidance else latents diff --git a/src/diffusers/pipelines/deprecated/audioldm/__init__.py b/src/diffusers/pipelines/deprecated/audioldm/__init__.py index 75b11bf2789f..2ea33a2ab3f3 100644 --- a/src/diffusers/pipelines/deprecated/audioldm/__init__.py +++ b/src/diffusers/pipelines/deprecated/audioldm/__init__.py @@ -6,7 +6,6 @@ _LazyModule, is_torch_available, is_transformers_available, - is_transformers_version, ) @@ -14,7 +13,7 @@ _import_structure = {} try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.27.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ....utils.dummy_torch_and_transformers_objects import ( @@ -28,7 +27,7 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT: try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.27.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ....utils.dummy_torch_and_transformers_objects import ( diff --git a/src/diffusers/pipelines/deprecated/controlnet_xs/pipeline_controlnet_xs.py b/src/diffusers/pipelines/deprecated/controlnet_xs/pipeline_controlnet_xs.py index 049f4994a4cf..c01fe4a9e42c 100644 --- a/src/diffusers/pipelines/deprecated/controlnet_xs/pipeline_controlnet_xs.py +++ b/src/diffusers/pipelines/deprecated/controlnet_xs/pipeline_controlnet_xs.py @@ -36,7 +36,7 @@ scale_lora_layers, unscale_lora_layers, ) -from ....utils.torch_utils import empty_device_cache, is_compiled_module, is_torch_version, randn_tensor +from ....utils.torch_utils import empty_device_cache, is_compiled_module, randn_tensor from ...pipeline_utils import DeprecatedPipelineMixin, DiffusionPipeline, StableDiffusionMixin from ...stable_diffusion.pipeline_output import StableDiffusionPipelineOutput from ...stable_diffusion.safety_checker import StableDiffusionSafetyChecker @@ -846,12 +846,11 @@ def __call__( num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order self._num_timesteps = len(timesteps) is_controlnet_compiled = is_compiled_module(self.unet) - is_torch_higher_equal_2_1 = is_torch_version(">=", "2.1") with self.progress_bar(total=num_inference_steps) as progress_bar: for i, t in enumerate(timesteps): # Relevant thread: # https://dev-discuss.pytorch.org/t/cudagraphs-in-pytorch-2-0/1428 - if torch.cuda.is_available() and is_controlnet_compiled and is_torch_higher_equal_2_1: + if torch.cuda.is_available() and is_controlnet_compiled: torch._inductor.cudagraph_mark_step_begin() # expand the latents if we are doing classifier free guidance latent_model_input = torch.cat([latents] * 2) if do_classifier_free_guidance else latents diff --git a/src/diffusers/pipelines/deprecated/controlnet_xs/pipeline_controlnet_xs_sd_xl.py b/src/diffusers/pipelines/deprecated/controlnet_xs/pipeline_controlnet_xs_sd_xl.py index 2d3944090721..53b36871bbba 100644 --- a/src/diffusers/pipelines/deprecated/controlnet_xs/pipeline_controlnet_xs_sd_xl.py +++ b/src/diffusers/pipelines/deprecated/controlnet_xs/pipeline_controlnet_xs_sd_xl.py @@ -42,7 +42,7 @@ scale_lora_layers, unscale_lora_layers, ) -from ....utils.torch_utils import get_module_execution_device, is_compiled_module, is_torch_version, randn_tensor +from ....utils.torch_utils import get_module_execution_device, is_compiled_module, randn_tensor from ...pipeline_utils import DeprecatedPipelineMixin, DiffusionPipeline from ...stable_diffusion_xl.pipeline_output import StableDiffusionXLPipelineOutput @@ -1027,12 +1027,11 @@ def __call__( num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order self._num_timesteps = len(timesteps) is_controlnet_compiled = is_compiled_module(self.unet) - is_torch_higher_equal_2_1 = is_torch_version(">=", "2.1") with self.progress_bar(total=num_inference_steps) as progress_bar: for i, t in enumerate(timesteps): # Relevant thread: # https://dev-discuss.pytorch.org/t/cudagraphs-in-pytorch-2-0/1428 - if is_controlnet_compiled and is_torch_higher_equal_2_1: + if is_controlnet_compiled: torch._inductor.cudagraph_mark_step_begin() # expand the latents if we are doing classifier free guidance latent_model_input = torch.cat([latents] * 2) if do_classifier_free_guidance else latents diff --git a/src/diffusers/pipelines/deprecated/musicldm/__init__.py b/src/diffusers/pipelines/deprecated/musicldm/__init__.py index bc9f8d550401..fa5cddab128a 100644 --- a/src/diffusers/pipelines/deprecated/musicldm/__init__.py +++ b/src/diffusers/pipelines/deprecated/musicldm/__init__.py @@ -7,7 +7,6 @@ get_objects_from_module, is_torch_available, is_transformers_available, - is_transformers_version, ) @@ -15,7 +14,7 @@ _import_structure = {} try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.27.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ....utils import dummy_torch_and_transformers_objects # noqa F403 @@ -27,7 +26,7 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT: try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.27.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: diff --git a/src/diffusers/pipelines/deprecated/musicldm/pipeline_musicldm.py b/src/diffusers/pipelines/deprecated/musicldm/pipeline_musicldm.py index 93acc4612cac..1248773b252e 100644 --- a/src/diffusers/pipelines/deprecated/musicldm/pipeline_musicldm.py +++ b/src/diffusers/pipelines/deprecated/musicldm/pipeline_musicldm.py @@ -30,7 +30,6 @@ from ....schedulers import KarrasDiffusionSchedulers from ....utils import ( is_accelerate_available, - is_accelerate_version, is_librosa_available, logging, replace_example_docstring, @@ -402,7 +401,7 @@ def enable_model_cpu_offload(self, gpu_id=0): lower than with `enable_sequential_cpu_offload`, but performance is much better due to the iterative execution of the `unet`. """ - if is_accelerate_available() and is_accelerate_version(">=", "0.17.0.dev0"): + if is_accelerate_available(): from accelerate import cpu_offload_with_hook else: raise ImportError("`enable_model_cpu_offload` requires `accelerate v0.17.0` or higher.") diff --git a/src/diffusers/pipelines/deprecated/unclip/__init__.py b/src/diffusers/pipelines/deprecated/unclip/__init__.py index 7444df491273..f817ce50b8fc 100644 --- a/src/diffusers/pipelines/deprecated/unclip/__init__.py +++ b/src/diffusers/pipelines/deprecated/unclip/__init__.py @@ -6,7 +6,6 @@ _LazyModule, is_torch_available, is_transformers_available, - is_transformers_version, ) @@ -14,7 +13,7 @@ _import_structure = {} try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.25.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ....utils.dummy_torch_and_transformers_objects import UnCLIPImageVariationPipeline, UnCLIPPipeline @@ -30,7 +29,7 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT: try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.25.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ....utils.dummy_torch_and_transformers_objects import * # noqa F403 diff --git a/src/diffusers/pipelines/deprecated/versatile_diffusion/__init__.py b/src/diffusers/pipelines/deprecated/versatile_diffusion/__init__.py index 8ea6ef6e2f65..e85e8cc268b4 100644 --- a/src/diffusers/pipelines/deprecated/versatile_diffusion/__init__.py +++ b/src/diffusers/pipelines/deprecated/versatile_diffusion/__init__.py @@ -6,7 +6,6 @@ _LazyModule, is_torch_available, is_transformers_available, - is_transformers_version, ) @@ -14,7 +13,7 @@ _import_structure = {} try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.25.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ....utils.dummy_torch_and_transformers_objects import ( @@ -42,7 +41,7 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT: try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.25.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ....utils.dummy_torch_and_transformers_objects import ( diff --git a/src/diffusers/pipelines/pag/pipeline_pag_controlnet_sd.py b/src/diffusers/pipelines/pag/pipeline_pag_controlnet_sd.py index 7b6abb32acc5..309970442693 100644 --- a/src/diffusers/pipelines/pag/pipeline_pag_controlnet_sd.py +++ b/src/diffusers/pipelines/pag/pipeline_pag_controlnet_sd.py @@ -36,7 +36,7 @@ scale_lora_layers, unscale_lora_layers, ) -from ...utils.torch_utils import empty_device_cache, is_compiled_module, is_torch_version, randn_tensor +from ...utils.torch_utils import empty_device_cache, is_compiled_module, randn_tensor from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin from ..stable_diffusion.pipeline_output import StableDiffusionPipelineOutput from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker @@ -1228,16 +1228,11 @@ def __call__( num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order is_unet_compiled = is_compiled_module(self.unet) is_controlnet_compiled = is_compiled_module(self.controlnet) - is_torch_higher_equal_2_1 = is_torch_version(">=", "2.1") with self.progress_bar(total=num_inference_steps) as progress_bar: for i, t in enumerate(timesteps): # Relevant thread: # https://dev-discuss.pytorch.org/t/cudagraphs-in-pytorch-2-0/1428 - if ( - torch.cuda.is_available() - and (is_unet_compiled and is_controlnet_compiled) - and is_torch_higher_equal_2_1 - ): + if torch.cuda.is_available() and (is_unet_compiled and is_controlnet_compiled): torch._inductor.cudagraph_mark_step_begin() # expand the latents if we are doing classifier free guidance latent_model_input = torch.cat([latents] * (prompt_embeds.shape[0] // latents.shape[0])) diff --git a/src/diffusers/pipelines/pag/pipeline_pag_controlnet_sd_xl.py b/src/diffusers/pipelines/pag/pipeline_pag_controlnet_sd_xl.py index 27c3c2f4ded9..c7f72f16defb 100644 --- a/src/diffusers/pipelines/pag/pipeline_pag_controlnet_sd_xl.py +++ b/src/diffusers/pipelines/pag/pipeline_pag_controlnet_sd_xl.py @@ -49,7 +49,7 @@ scale_lora_layers, unscale_lora_layers, ) -from ...utils.torch_utils import get_module_execution_device, is_compiled_module, is_torch_version, randn_tensor +from ...utils.torch_utils import get_module_execution_device, is_compiled_module, randn_tensor from ..pipeline_utils import DiffusionPipeline, StableDiffusionMixin from ..stable_diffusion_xl.pipeline_output import StableDiffusionXLPipelineOutput from .pag_utils import PAGMixin @@ -1485,16 +1485,11 @@ def __call__( is_unet_compiled = is_compiled_module(self.unet) is_controlnet_compiled = is_compiled_module(self.controlnet) - is_torch_higher_equal_2_1 = is_torch_version(">=", "2.1") with self.progress_bar(total=num_inference_steps) as progress_bar: for i, t in enumerate(timesteps): # Relevant thread: # https://dev-discuss.pytorch.org/t/cudagraphs-in-pytorch-2-0/1428 - if ( - torch.cuda.is_available() - and (is_unet_compiled and is_controlnet_compiled) - and is_torch_higher_equal_2_1 - ): + if torch.cuda.is_available() and (is_unet_compiled and is_controlnet_compiled): torch._inductor.cudagraph_mark_step_begin() # expand the latents if we are doing classifier free guidance latent_model_input = torch.cat([latents] * (prompt_embeds.shape[0] // latents.shape[0])) diff --git a/src/diffusers/pipelines/pipeline_utils.py b/src/diffusers/pipelines/pipeline_utils.py index 750fed48cbd0..869fbb78128f 100644 --- a/src/diffusers/pipelines/pipeline_utils.py +++ b/src/diffusers/pipelines/pipeline_utils.py @@ -70,7 +70,6 @@ is_bitsandbytes_version, is_hpu_available, is_torch_npu_available, - is_torch_version, is_transformers_version, logging, numpy_to_pil, @@ -465,7 +464,7 @@ def to(self, *args, **kwargs) -> Self: # throw warning if pipeline is in "offloaded"-mode but user tries to manually set to GPU. def module_is_sequentially_offloaded(module): - if not is_accelerate_available() or is_accelerate_version("<", "0.14.0"): + if not is_accelerate_available(): return False _, _, is_loaded_in_8bit_bnb = _check_bnb_status(module) @@ -483,7 +482,7 @@ def module_is_sequentially_offloaded(module): ) def module_is_offloaded(module): - if not is_accelerate_available() or is_accelerate_version("<", "0.17.0.dev0"): + if not is_accelerate_available(): return False return hasattr(module, "_hf_hook") and isinstance(module._hf_hook, accelerate.hooks.CpuOffload) @@ -822,18 +821,6 @@ def from_pretrained(cls, pretrained_model_name_or_path: str | os.PathLike, **kwa if quantization_config is not None and not isinstance(quantization_config, PipelineQuantizationConfig): raise ValueError("`quantization_config` must be an instance of `PipelineQuantizationConfig`.") - if low_cpu_mem_usage is True and not is_torch_version(">=", "1.9.0"): - raise NotImplementedError( - "Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set" - " `low_cpu_mem_usage=False`." - ) - - if device_map is not None and not is_torch_version(">=", "1.9.0"): - raise NotImplementedError( - "Loading and dispatching requires torch >= 1.9.0. Please either update your PyTorch version or set" - " `device_map=None`." - ) - if device_map is not None and not is_accelerate_available(): raise NotImplementedError( "Using `device_map` requires the `accelerate` library. Please install it using: `pip install accelerate`." @@ -847,10 +834,6 @@ def from_pretrained(cls, pretrained_model_name_or_path: str | os.PathLike, **kwa f"{device_map} not supported. Supported strategies are: {', '.join(SUPPORTED_DEVICE_MAP)}" ) - if device_map is not None and device_map in SUPPORTED_DEVICE_MAP: - if is_accelerate_version("<", "0.28.0"): - raise NotImplementedError("Device placement requires `accelerate` version `0.28.0` or later.") - if low_cpu_mem_usage is False and device_map is not None: raise ValueError( f"You cannot set `low_cpu_mem_usage` to False while using device_map={device_map} for loading and" @@ -1200,7 +1183,7 @@ def enable_model_cpu_offload(self, gpu_id: int | None = None, device: torch.devi "Model CPU offload cannot be enabled because no `model_cpu_offload_seq` class attribute is set." ) - if is_accelerate_available() and is_accelerate_version(">=", "0.17.0.dev0"): + if is_accelerate_available(): from accelerate import cpu_offload_with_hook else: raise ImportError("`enable_model_cpu_offload` requires `accelerate v0.17.0` or higher.") @@ -1308,7 +1291,7 @@ def enable_sequential_cpu_offload(self, gpu_id: int | None = None, device: torch self._maybe_raise_error_if_group_offload_active(raise_error=True) self._maybe_raise_error_if_tensor_parallel_active() - if is_accelerate_available() and is_accelerate_version(">=", "0.14.0"): + if is_accelerate_available(): from accelerate import cpu_offload else: raise ImportError("`enable_sequential_cpu_offload` requires `accelerate v0.14.0` or higher") diff --git a/src/diffusers/pipelines/stable_audio/__init__.py b/src/diffusers/pipelines/stable_audio/__init__.py index dfdd419ae991..b0233f6f19c5 100644 --- a/src/diffusers/pipelines/stable_audio/__init__.py +++ b/src/diffusers/pipelines/stable_audio/__init__.py @@ -7,7 +7,6 @@ get_objects_from_module, is_torch_available, is_transformers_available, - is_transformers_version, ) @@ -15,7 +14,7 @@ _import_structure = {} try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.27.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ...utils import dummy_torch_and_transformers_objects @@ -28,7 +27,7 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT: try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.27.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ...utils.dummy_torch_and_transformers_objects import * diff --git a/src/diffusers/pipelines/stable_cascade/pipeline_stable_cascade.py b/src/diffusers/pipelines/stable_cascade/pipeline_stable_cascade.py index c7af35aa955e..6221ab624e6e 100644 --- a/src/diffusers/pipelines/stable_cascade/pipeline_stable_cascade.py +++ b/src/diffusers/pipelines/stable_cascade/pipeline_stable_cascade.py @@ -21,7 +21,7 @@ from ...models import StableCascadeUNet from ...schedulers import DDPMWuerstchenScheduler -from ...utils import is_torch_version, is_torch_xla_available, logging, replace_example_docstring +from ...utils import is_torch_xla_available, logging, replace_example_docstring from ...utils.torch_utils import randn_tensor from ..deprecated.wuerstchen.modeling_paella_vq_model import PaellaVQModel from ..pipeline_utils import DeprecatedPipelineMixin, DiffusionPipeline, ImagePipelineOutput @@ -394,8 +394,6 @@ def __call__( device = self._execution_device dtype = self.decoder.dtype self._guidance_scale = guidance_scale - if is_torch_version("<", "2.2.0") and dtype == torch.bfloat16: - raise ValueError("`StableCascadeDecoderPipeline` requires torch>=2.2.0 when using `torch.bfloat16` dtype.") # 1. Check inputs. Raise error if not correct self.check_inputs( diff --git a/src/diffusers/pipelines/stable_cascade/pipeline_stable_cascade_combined.py b/src/diffusers/pipelines/stable_cascade/pipeline_stable_cascade_combined.py index a1d2ca6c56b3..dc5e773563d5 100644 --- a/src/diffusers/pipelines/stable_cascade/pipeline_stable_cascade_combined.py +++ b/src/diffusers/pipelines/stable_cascade/pipeline_stable_cascade_combined.py @@ -20,7 +20,7 @@ from ...models import StableCascadeUNet from ...schedulers import DDPMWuerstchenScheduler -from ...utils import is_torch_version, replace_example_docstring +from ...utils import replace_example_docstring from ..deprecated.wuerstchen.modeling_paella_vq_model import PaellaVQModel from ..pipeline_utils import DeprecatedPipelineMixin, DiffusionPipeline, ImagePipelineOutput from .pipeline_stable_cascade import StableCascadeDecoderPipeline @@ -270,12 +270,6 @@ def __call__( [`~pipelines.ImagePipelineOutput`] or `tuple` [`~pipelines.ImagePipelineOutput`] if `return_dict` is True, otherwise a `tuple`. When returning a tuple, the first element is a list with the generated images. """ - dtype = self.decoder_pipe.decoder.dtype - if is_torch_version("<", "2.2.0") and dtype == torch.bfloat16: - raise ValueError( - "`StableCascadeCombinedPipeline` requires torch>=2.2.0 when using `torch.bfloat16` dtype." - ) - prior_outputs = self.prior_pipe( prompt=prompt if prompt_embeds is None else None, images=images, diff --git a/src/diffusers/pipelines/stable_diffusion/__init__.py b/src/diffusers/pipelines/stable_diffusion/__init__.py index 263457a76489..7997c36a434c 100644 --- a/src/diffusers/pipelines/stable_diffusion/__init__.py +++ b/src/diffusers/pipelines/stable_diffusion/__init__.py @@ -8,7 +8,6 @@ is_onnx_available, is_torch_available, is_transformers_available, - is_transformers_version, ) @@ -36,7 +35,7 @@ _import_structure["safety_checker"] = ["StableDiffusionSafetyChecker"] _import_structure["stable_unclip_image_normalizer"] = ["StableUnCLIPImageNormalizer"] try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.25.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ...utils.dummy_torch_and_transformers_objects import ( @@ -47,7 +46,7 @@ else: _import_structure["pipeline_stable_diffusion_image_variation"] = ["StableDiffusionImageVariationPipeline"] try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.26.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ...utils.dummy_torch_and_transformers_objects import ( @@ -108,7 +107,7 @@ from .stable_unclip_image_normalizer import StableUnCLIPImageNormalizer try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.25.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ...utils.dummy_torch_and_transformers_objects import ( @@ -120,7 +119,7 @@ ) try: - if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.26.0")): + if not (is_transformers_available() and is_torch_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: from ...utils.dummy_torch_and_transformers_objects import StableDiffusionDepth2ImgPipeline diff --git a/src/diffusers/quantizers/bfl/bfl_quantizer.py b/src/diffusers/quantizers/bfl/bfl_quantizer.py index 8802144fa593..f421171aec17 100644 --- a/src/diffusers/quantizers/bfl/bfl_quantizer.py +++ b/src/diffusers/quantizers/bfl/bfl_quantizer.py @@ -16,7 +16,7 @@ from typing import TYPE_CHECKING, Any -from ...utils import get_module_from_name, is_accelerate_available, is_accelerate_version, is_torch_available +from ...utils import get_module_from_name, is_accelerate_available, is_torch_available from ..base import DiffusersQuantizer @@ -47,7 +47,7 @@ def __init__(self, quantization_config, **kwargs): self.keep_in_fp32_modules = [] def validate_environment(self, *args, **kwargs): - if not is_accelerate_available() or is_accelerate_version("<", "0.26.0"): + if not is_accelerate_available(): raise ImportError( "Loading BFL quantized checkpoints requires `accelerate` installed in your environment: `pip install 'accelerate>=0.26.0'`" ) diff --git a/src/diffusers/quantizers/bitsandbytes/bnb_quantizer.py b/src/diffusers/quantizers/bitsandbytes/bnb_quantizer.py index 63d2680b3d33..3b96d4245a21 100644 --- a/src/diffusers/quantizers/bitsandbytes/bnb_quantizer.py +++ b/src/diffusers/quantizers/bitsandbytes/bnb_quantizer.py @@ -27,9 +27,7 @@ from ...utils import ( is_accelerate_available, - is_accelerate_version, is_bitsandbytes_available, - is_bitsandbytes_version, is_torch_available, logging, ) @@ -63,11 +61,11 @@ def __init__(self, quantization_config, **kwargs): def validate_environment(self, *args, **kwargs): if not (torch.cuda.is_available() or torch.xpu.is_available() or torch.mps.is_available()): raise RuntimeError("No GPU found. A GPU is needed for quantization.") - if not is_accelerate_available() or is_accelerate_version("<", "0.26.0"): + if not is_accelerate_available(): raise ImportError( "Using `bitsandbytes` 4-bit quantization requires Accelerate: `pip install 'accelerate>=0.26.0'`" ) - if not is_bitsandbytes_available() or is_bitsandbytes_version("<", "0.43.3"): + if not is_bitsandbytes_available(): raise ImportError( "Using `bitsandbytes` 4-bit quantization requires the latest version of bitsandbytes: `pip install -U bitsandbytes`" ) @@ -381,11 +379,11 @@ def supports_parallel_loading(self) -> bool: def validate_environment(self, *args, **kwargs): if not (torch.cuda.is_available() or torch.xpu.is_available()): raise RuntimeError("No GPU found. A GPU is needed for quantization.") - if not is_accelerate_available() or is_accelerate_version("<", "0.26.0"): + if not is_accelerate_available(): raise ImportError( "Using `bitsandbytes` 8-bit quantization requires Accelerate: `pip install 'accelerate>=0.26.0'`" ) - if not is_bitsandbytes_available() or is_bitsandbytes_version("<", "0.43.3"): + if not is_bitsandbytes_available(): raise ImportError( "Using `bitsandbytes` 8-bit quantization requires the latest version of bitsandbytes: `pip install -U bitsandbytes`" ) diff --git a/src/diffusers/quantizers/gguf/gguf_quantizer.py b/src/diffusers/quantizers/gguf/gguf_quantizer.py index e2bee2e4023d..2ac49208f8e9 100644 --- a/src/diffusers/quantizers/gguf/gguf_quantizer.py +++ b/src/diffusers/quantizers/gguf/gguf_quantizer.py @@ -12,9 +12,7 @@ from ...utils import ( get_module_from_name, is_accelerate_available, - is_accelerate_version, is_gguf_available, - is_gguf_version, is_torch_available, logging, ) @@ -51,11 +49,11 @@ def __init__(self, quantization_config, **kwargs): self.modules_to_not_convert = [self.modules_to_not_convert] def validate_environment(self, *args, **kwargs): - if not is_accelerate_available() or is_accelerate_version("<", "0.26.0"): + if not is_accelerate_available(): raise ImportError( "Loading GGUF Parameters requires `accelerate` installed in your environment: `pip install 'accelerate>=0.26.0'`" ) - if not is_gguf_available() or is_gguf_version("<", "0.10.0"): + if not is_gguf_available(): raise ImportError( "To load GGUF format files you must have `gguf` installed in your environment: `pip install gguf>=0.10.0`" ) diff --git a/src/diffusers/quantizers/quantization_config.py b/src/diffusers/quantizers/quantization_config.py index 5777ab45fa7a..9bd4fce3c3ec 100644 --- a/src/diffusers/quantizers/quantization_config.py +++ b/src/diffusers/quantizers/quantization_config.py @@ -33,7 +33,7 @@ from packaging import version -from ..utils import deprecate, is_torch_available, is_torchao_version, logging +from ..utils import deprecate, is_torch_available, is_torchao_available, logging if is_torch_available(): @@ -619,7 +619,7 @@ def __init__( self.post_init() def post_init(self): - if is_torchao_version("<", "0.15.0"): + if not is_torchao_available(): raise ValueError("TorchAoConfig requires torchao >= 0.15.0. Please upgrade with `pip install -U torchao`.") from torchao.quantization.quant_api import AOBaseConfig @@ -644,7 +644,7 @@ def to_dict(self): @classmethod def from_dict(cls, config_dict, return_unused_kwargs=False, **kwargs): """Create configuration from a dictionary.""" - if not is_torchao_version(">=", "0.15.0"): + if not is_torchao_available(): raise NotImplementedError("TorchAoConfig requires torchao >= 0.15.0 for construction from dict") config_dict = config_dict.copy() quant_type = config_dict.pop("quant_type") diff --git a/src/diffusers/quantizers/quanto/quanto_quantizer.py b/src/diffusers/quantizers/quanto/quanto_quantizer.py index 92bbecbb1b53..b86fc5923924 100644 --- a/src/diffusers/quantizers/quanto/quanto_quantizer.py +++ b/src/diffusers/quantizers/quanto/quanto_quantizer.py @@ -1,12 +1,9 @@ from typing import TYPE_CHECKING, Any -from diffusers.utils.import_utils import is_optimum_quanto_version - from ...utils import ( deprecate, get_module_from_name, is_accelerate_available, - is_accelerate_version, is_optimum_quanto_available, is_torch_available, logging, @@ -57,11 +54,6 @@ def validate_environment(self, *args, **kwargs): raise ImportError( "Loading an optimum-quanto quantized model requires optimum-quanto library (`pip install optimum-quanto`)" ) - if not is_optimum_quanto_version(">=", "0.2.6"): - raise ImportError( - "Loading an optimum-quanto quantized model requires `optimum-quanto>=0.2.6`. " - "Please upgrade your installation with `pip install --upgrade optimum-quanto" - ) if not is_accelerate_available(): raise ImportError( @@ -121,16 +113,13 @@ def adjust_max_memory(self, max_memory: dict[str, int | str]) -> dict[str, int | return max_memory def adjust_target_dtype(self, target_dtype: "torch.dtype") -> "torch.dtype": - if is_accelerate_version(">=", "0.27.0"): - mapping = { - "int8": torch.int8, - "float8": CustomDtype.FP8, - "int4": CustomDtype.INT4, - "int2": CustomDtype.INT2, - } - target_dtype = mapping[self.quantization_config.weights_dtype] - - return target_dtype + mapping = { + "int8": torch.int8, + "float8": CustomDtype.FP8, + "int4": CustomDtype.INT4, + "int2": CustomDtype.INT2, + } + return mapping[self.quantization_config.weights_dtype] def update_torch_dtype(self, torch_dtype: "torch.dtype" = None) -> "torch.dtype": if torch_dtype is None: diff --git a/src/diffusers/quantizers/sdnq/sdnq_quantizer.py b/src/diffusers/quantizers/sdnq/sdnq_quantizer.py index 7d040e899399..fa4b4f775a27 100644 --- a/src/diffusers/quantizers/sdnq/sdnq_quantizer.py +++ b/src/diffusers/quantizers/sdnq/sdnq_quantizer.py @@ -12,32 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os from functools import lru_cache -from ...utils import is_sdnq_available, is_sdnq_version, logging +from ...utils import is_sdnq_available, logging from ..base import DiffusersQuantizer logger = logging.get_logger(__name__) -# Recommended sdnq version. Older versions load/save most SDNQ checkpoints fine; only some of the -# latest ones require this version, so a mismatch is a warning, not a hard error. -_RECOMMENDED_SDNQ_VERSION = "0.2.2" - def _check_sdnq_requirement(): if not is_sdnq_available(): raise ImportError( - f"Loading or creating an SDNQ quantized model requires the sdnq library: " - f"`pip install 'sdnq>={_RECOMMENDED_SDNQ_VERSION}'`" - ) - - if is_sdnq_version("<", _RECOMMENDED_SDNQ_VERSION) and not os.getenv("DIFFUSERS_NO_ADVISORY_WARNINGS"): - logger.warning( - f"Your installed sdnq is older than {_RECOMMENDED_SDNQ_VERSION}. Most SDNQ checkpoints will still " - f"load and save fine, but some of the latest ones require sdnq>={_RECOMMENDED_SDNQ_VERSION}. " - f"If you hit issues, upgrade with `pip install -U sdnq`." + "Loading or creating an SDNQ quantized model requires the sdnq library: `pip install 'sdnq>=0.2.2'`" ) diff --git a/src/diffusers/quantizers/torchao/torchao_quantizer.py b/src/diffusers/quantizers/torchao/torchao_quantizer.py index e31db9faa068..fc1be63d23d5 100644 --- a/src/diffusers/quantizers/torchao/torchao_quantizer.py +++ b/src/diffusers/quantizers/torchao/torchao_quantizer.py @@ -29,7 +29,6 @@ get_module_from_name, is_safetensors_available, is_torch_available, - is_torch_version, is_torchao_available, is_torchao_version, logging, @@ -51,8 +50,7 @@ import torch import torch.nn as nn -# `validate_environment` asks for torchao >= 0.15 before quantizing, and older versions have no `FqnToConfig`. -if is_torchao_available() and is_torchao_version(">=", "0.15.0"): +if is_torchao_available(): from torchao.quantization import FqnToConfig, quantize_ if is_torchao_version(">=", "0.16.0"): @@ -99,12 +97,7 @@ def _update_torch_safe_globals(): torch.serialization.add_safe_globals(safe_globals=safe_globals) -if ( - is_torch_available() - and is_torch_version(">=", "2.6.0") - and is_torchao_available() - and is_torchao_version(">=", "0.15.0") -): +if is_torch_available() and is_torchao_available(): _update_torch_safe_globals() diff --git a/src/diffusers/utils/import_utils.py b/src/diffusers/utils/import_utils.py index baf1077bbcf3..cfea1ffd2691 100644 --- a/src/diffusers/utils/import_utils.py +++ b/src/diffusers/utils/import_utils.py @@ -27,8 +27,10 @@ from typing import Any from huggingface_hub.utils import is_jinja_available # noqa: F401 +from packaging.requirements import Requirement from packaging.version import Version, parse +from ..dependency_versions_table import deps from . import logging @@ -57,9 +59,25 @@ _is_google_colab = "google.colab" in sys.modules or any(k.startswith("COLAB_") for k in os.environ) +_PKG_TO_DEPS_KEY = { + "torch": "torch", + "transformers": "transformers", + "accelerate": "accelerate", + "peft": "peft", + "safetensors": "safetensors", + "bitsandbytes": "bitsandbytes", + "gguf": "gguf", + "torchao": "torchao", + "optimum": "optimum_quanto", + "modelopt": "nvidia_modelopt[hf]", + "sdnq": "sdnq", + "auto_round": "auto-round", +} + def _is_package_available(pkg_name: str, get_dist_name: bool = False) -> tuple[bool, str]: global _package_map + import_name = pkg_name pkg_exists = importlib.util.find_spec(pkg_name) is not None pkg_version = "N/A" @@ -91,6 +109,15 @@ def _is_package_available(pkg_name: str, get_dist_name: bool = False) -> tuple[b except (ImportError, importlib_metadata.PackageNotFoundError): pkg_exists = False + if pkg_exists and import_name in _PKG_TO_DEPS_KEY: + requirement = Requirement(deps[_PKG_TO_DEPS_KEY[import_name]]) + if not requirement.specifier.contains(parse(pkg_version).base_version): + logger.warning( + f"Disabling {import_name} because diffusers requires `{requirement}` but found version {pkg_version}. " + f"Upgrade it with `pip install -U '{requirement}'`." + ) + pkg_exists = False + return pkg_exists, pkg_version @@ -458,9 +485,9 @@ def is_av_available(): """ # docstyle-ignore -PYTORCH_IMPORT_ERROR = """ -{0} requires the PyTorch library but it was not found in your environment. Checkout the instructions on the -installation page: https://pytorch.org/get-started/locally/ and follow the ones that match your environment. +PYTORCH_IMPORT_ERROR = f""" +{{0}} requires `{deps["torch"]}` but a compatible version was not found in your environment. Checkout the instructions +on the installation page: https://pytorch.org/get-started/locally/ and follow the ones that match your environment. """ # docstyle-ignore @@ -488,9 +515,9 @@ def is_av_available(): """ # docstyle-ignore -TRANSFORMERS_IMPORT_ERROR = """ -{0} requires the transformers library but it was not found in your environment. You can install it with pip: `pip -install transformers` +TRANSFORMERS_IMPORT_ERROR = f""" +{{0}} requires `{deps["transformers"]}` but a compatible version was not found in your environment. You can install it +with pip: `pip install -U '{deps["transformers"]}'` """ # docstyle-ignore @@ -547,13 +574,13 @@ def is_av_available(): """ # docstyle-ignore -PEFT_IMPORT_ERROR = """ -{0} requires the peft library but it was not found in your environment. You can install it with pip: `pip install peft` +PEFT_IMPORT_ERROR = f""" +{{0}} requires `{deps["peft"]}` but a compatible version was not found in your environment. You can install it with pip: `pip install -U '{deps["peft"]}'` """ # docstyle-ignore -SAFETENSORS_IMPORT_ERROR = """ -{0} requires the safetensors library but it was not found in your environment. You can install it with pip: `pip install safetensors` +SAFETENSORS_IMPORT_ERROR = f""" +{{0}} requires `{deps["safetensors"]}` but a compatible version was not found in your environment. You can install it with pip: `pip install -U '{deps["safetensors"]}'` """ # docstyle-ignore @@ -563,8 +590,8 @@ def is_av_available(): # docstyle-ignore -BITSANDBYTES_IMPORT_ERROR = """ -{0} requires the bitsandbytes library but it was not found in your environment. You can install it with pip: `pip install bitsandbytes` +BITSANDBYTES_IMPORT_ERROR = f""" +{{0}} requires `{deps["bitsandbytes"]}` but a compatible version was not found in your environment. You can install it with pip: `pip install -U '{deps["bitsandbytes"]}'` """ # docstyle-ignore @@ -573,22 +600,22 @@ def is_av_available(): """ # docstyle-ignore -GGUF_IMPORT_ERROR = """ -{0} requires the gguf library but it was not found in your environment. You can install it with pip: `pip install gguf` +GGUF_IMPORT_ERROR = f""" +{{0}} requires `{deps["gguf"]}` but a compatible version was not found in your environment. You can install it with pip: `pip install -U '{deps["gguf"]}'` """ -TORCHAO_IMPORT_ERROR = """ -{0} requires the torchao library but it was not found in your environment. You can install it with pip: `pip install -torchao` +TORCHAO_IMPORT_ERROR = f""" +{{0}} requires `{deps["torchao"]}` but a compatible version was not found in your environment. You can install it with +pip: `pip install -U '{deps["torchao"]}'` """ -QUANTO_IMPORT_ERROR = """ -{0} requires the optimum-quanto library but it was not found in your environment. You can install it with pip: `pip -install optimum-quanto` +QUANTO_IMPORT_ERROR = f""" +{{0}} requires `{deps["optimum_quanto"]}` but a compatible version was not found in your environment. You can install it +with pip: `pip install -U '{deps["optimum_quanto"]}'` """ -SDNQ_IMPORT_ERROR = """ -{0} requires the sdnq library but it was not found in your environment. You can install it with pip: `pip install sdnq` +SDNQ_IMPORT_ERROR = f""" +{{0}} requires `{deps["sdnq"]}` but a compatible version was not found in your environment. You can install it with pip: `pip install -U '{deps["sdnq"]}'` """ # docstyle-ignore @@ -657,26 +684,6 @@ def requires_backends(obj, backends): if failed: raise ImportError("".join(failed)) - if name in [ - "VersatileDiffusionTextToImagePipeline", - "VersatileDiffusionPipeline", - "VersatileDiffusionDualGuidedPipeline", - "StableDiffusionImageVariationPipeline", - "UnCLIPPipeline", - ] and is_transformers_version("<", "4.25.0"): - raise ImportError( - f"You need to install `transformers>=4.25` in order to use {name}: \n```\n pip install" - " --upgrade transformers \n```" - ) - - if name in ["StableDiffusionDepth2ImgPipeline", "StableDiffusionPix2PixZeroPipeline"] and is_transformers_version( - "<", "4.26.0" - ): - raise ImportError( - f"You need to install `transformers>=4.26` in order to use {name}: \n```\n pip install" - " --upgrade transformers \n```" - ) - class DummyObject(type): """ diff --git a/src/diffusers/utils/outputs.py b/src/diffusers/utils/outputs.py index 84c025d79773..1ea6ce6f152a 100644 --- a/src/diffusers/utils/outputs.py +++ b/src/diffusers/utils/outputs.py @@ -21,7 +21,7 @@ import numpy as np -from .import_utils import is_torch_available, is_torch_version +from .import_utils import is_torch_available def is_tensor(x) -> bool: @@ -56,19 +56,12 @@ def __init_subclass__(cls) -> None: if is_torch_available(): import torch.utils._pytree - if is_torch_version("<", "2.2"): - torch.utils._pytree._register_pytree_node( - cls, - torch.utils._pytree._dict_flatten, - lambda values, context: cls(**torch.utils._pytree._dict_unflatten(values, context)), - ) - else: - torch.utils._pytree.register_pytree_node( - cls, - torch.utils._pytree._dict_flatten, - lambda values, context: cls(**torch.utils._pytree._dict_unflatten(values, context)), - serialized_type_name=f"{cls.__module__}.{cls.__name__}", - ) + torch.utils._pytree.register_pytree_node( + cls, + torch.utils._pytree._dict_flatten, + lambda values, context: cls(**torch.utils._pytree._dict_unflatten(values, context)), + serialized_type_name=f"{cls.__module__}.{cls.__name__}", + ) def __post_init__(self) -> None: class_fields = fields(self) diff --git a/src/diffusers/utils/torch_utils.py b/src/diffusers/utils/torch_utils.py index 801044c58106..35ad366c6204 100644 --- a/src/diffusers/utils/torch_utils.py +++ b/src/diffusers/utils/torch_utils.py @@ -114,7 +114,7 @@ def randn_tensor( def is_compiled_module(module) -> bool: """Check whether the module was compiled with torch.compile()""" - if is_torch_version("<", "2.0.0") or not hasattr(torch, "_dynamo"): + if not hasattr(torch, "_dynamo"): return False return isinstance(module, torch._dynamo.eval_frame.OptimizedModule) diff --git a/tests/others/test_dependencies.py b/tests/others/test_dependencies.py index 924f5418cc40..990c68a92852 100644 --- a/tests/others/test_dependencies.py +++ b/tests/others/test_dependencies.py @@ -85,3 +85,24 @@ def test_pipeline_module_imports(self): if failures: pytest.fail("Unguarded optional-dependency imports found:\n" + "\n".join(failures)) + + def test_min_version_deps_are_in_deps_table(self): + from diffusers.dependency_versions_table import deps + from diffusers.utils.import_utils import _PKG_TO_DEPS_KEY + + for pkg_name, deps_key in _PKG_TO_DEPS_KEY.items(): + assert deps_key in deps, f"{deps_key} (for {pkg_name}) is not in the deps table!" + + def test_package_below_min_version_is_unavailable(self, monkeypatch): + from diffusers.utils import import_utils + + monkeypatch.setitem(import_utils.deps, "gguf", "gguf>=0.10.0") + monkeypatch.setattr(import_utils.importlib.util, "find_spec", lambda name: object()) + monkeypatch.setattr(import_utils.importlib_metadata, "version", lambda name: "0.9.0") + assert import_utils._is_package_available("gguf") == (False, "0.9.0") + + monkeypatch.setattr(import_utils.importlib_metadata, "version", lambda name: "0.10.0") + assert import_utils._is_package_available("gguf") == (True, "0.10.0") + + monkeypatch.setattr(import_utils.importlib_metadata, "version", lambda name: "0.10.0a0+abc") + assert import_utils._is_package_available("gguf") == (True, "0.10.0a0+abc") From 7496f658310303b86bac8c513c5ccc484c41a5d4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 30 Oct 2026 09:10:33 +0000 Subject: [PATCH 2/6] Apply style fixes --- src/diffusers/utils/import_utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/diffusers/utils/import_utils.py b/src/diffusers/utils/import_utils.py index cfea1ffd2691..475688294357 100644 --- a/src/diffusers/utils/import_utils.py +++ b/src/diffusers/utils/import_utils.py @@ -610,12 +610,13 @@ def is_av_available(): """ QUANTO_IMPORT_ERROR = f""" -{{0}} requires `{deps["optimum_quanto"]}` but a compatible version was not found in your environment. You can install it -with pip: `pip install -U '{deps["optimum_quanto"]}'` +{{0}} requires `{deps["optimum_quanto"]}` but a compatible version was not found in your environment. You can install +it with pip: `pip install -U '{deps["optimum_quanto"]}'` """ SDNQ_IMPORT_ERROR = f""" -{{0}} requires `{deps["sdnq"]}` but a compatible version was not found in your environment. You can install it with pip: `pip install -U '{deps["sdnq"]}'` +{{0}} requires `{deps["sdnq"]}` but a compatible version was not found in your environment. You can install it with +pip: `pip install -U '{deps["sdnq"]}'` """ # docstyle-ignore From 5f2b51fed2ad2957ee78fe51168fb45ce49e060d Mon Sep 17 00:00:00 2001 From: DN6 Date: Tue, 3 Nov 2026 20:55:32 +0530 Subject: [PATCH 3/6] Address review: version-parse fallback, accelerate messages, inline nn.LayerNorm, remaining floor checks --- src/diffusers/loaders/single_file.py | 36 +----- src/diffusers/models/attention_dispatch.py | 22 +--- src/diffusers/models/normalization.py | 7 +- .../transformers/transformer_cogview4.py | 4 +- .../transformers/transformer_glm_image.py | 4 +- .../pipelines/audioldm2/pipeline_audioldm2.py | 2 +- .../deprecated/musicldm/pipeline_musicldm.py | 2 +- .../pipelines/kolors/text_encoder.py | 121 ++---------------- .../pipelines/pipeline_loading_utils.py | 29 +---- src/diffusers/pipelines/pipeline_utils.py | 4 +- src/diffusers/quantizers/bfl/bfl_quantizer.py | 2 +- .../quantizers/bitsandbytes/bnb_quantizer.py | 4 +- .../quantizers/gguf/gguf_quantizer.py | 2 +- .../quantizers/quantization_config.py | 10 -- .../quantizers/torchao/torchao_quantizer.py | 16 --- src/diffusers/utils/accelerate_utils.py | 9 -- src/diffusers/utils/constants.py | 21 +-- src/diffusers/utils/import_utils.py | 12 +- tests/others/test_dependencies.py | 3 + 19 files changed, 49 insertions(+), 261 deletions(-) diff --git a/src/diffusers/loaders/single_file.py b/src/diffusers/loaders/single_file.py index fe9565b0635c..4762fbf71e18 100644 --- a/src/diffusers/loaders/single_file.py +++ b/src/diffusers/loaders/single_file.py @@ -18,7 +18,6 @@ import torch from huggingface_hub import snapshot_download from huggingface_hub.utils import LocalEntryNotFoundError, validate_hf_hub_args -from packaging import version from typing_extensions import Self from ..utils import _maybe_remap_relocated_pipeline_class, deprecate, is_transformers_available, logging @@ -45,7 +44,6 @@ SINGLE_FILE_OPTIONAL_COMPONENTS = ["safety_checker"] if is_transformers_available(): - import transformers from transformers import PreTrainedModel, PreTrainedTokenizer @@ -77,21 +75,8 @@ def load_single_file_sub_model( library = importlib.import_module(library_name) class_obj = getattr(library, class_name) - if is_transformers_available(): - transformers_version = version.parse(version.parse(transformers.__version__).base_version) - else: - transformers_version = "N/A" - - is_transformers_model = ( - is_transformers_available() - and issubclass(class_obj, PreTrainedModel) - and transformers_version >= version.parse("4.20.0") - ) - is_tokenizer = ( - is_transformers_available() - and issubclass(class_obj, PreTrainedTokenizer) - and transformers_version >= version.parse("4.20.0") - ) + is_transformers_model = is_transformers_available() and issubclass(class_obj, PreTrainedModel) + is_tokenizer = is_transformers_available() and issubclass(class_obj, PreTrainedTokenizer) diffusers_module = importlib.import_module(__name__.split(".")[0]) is_diffusers_single_file_model = issubclass(class_obj, diffusers_module.FromOriginalModelMixin) @@ -188,26 +173,13 @@ def _map_component_types_to_config_dict(component_types): config_dict = {} component_types.pop("self", None) - if is_transformers_available(): - transformers_version = version.parse(version.parse(transformers.__version__).base_version) - else: - transformers_version = "N/A" - for component_name, component_value in component_types.items(): is_diffusers_model = issubclass(component_value[0], diffusers_module.ModelMixin) is_scheduler_enum = component_value[0].__name__ == "KarrasDiffusionSchedulers" is_scheduler = issubclass(component_value[0], diffusers_module.SchedulerMixin) - is_transformers_model = ( - is_transformers_available() - and issubclass(component_value[0], PreTrainedModel) - and transformers_version >= version.parse("4.20.0") - ) - is_transformers_tokenizer = ( - is_transformers_available() - and issubclass(component_value[0], PreTrainedTokenizer) - and transformers_version >= version.parse("4.20.0") - ) + is_transformers_model = is_transformers_available() and issubclass(component_value[0], PreTrainedModel) + is_transformers_tokenizer = is_transformers_available() and issubclass(component_value[0], PreTrainedTokenizer) if is_diffusers_model and component_name not in SINGLE_FILE_OPTIONAL_COMPONENTS: config_dict[component_name] = ["diffusers", component_value[0].__name__] diff --git a/src/diffusers/models/attention_dispatch.py b/src/diffusers/models/attention_dispatch.py index 3d2ae36bd9a2..48854474cc75 100644 --- a/src/diffusers/models/attention_dispatch.py +++ b/src/diffusers/models/attention_dispatch.py @@ -186,26 +186,8 @@ else: xops = None -# Version guard for PyTorch compatibility - custom_op was added in PyTorch 2.4 -if torch.__version__ >= "2.4.0": - _custom_op = torch.library.custom_op - _register_fake = torch.library.register_fake -else: - - def custom_op_no_op(name, fn=None, /, *, mutates_args, device_types=None, schema=None): - def wrap(func): - return func - - return wrap if fn is None else fn - - def register_fake_no_op(op, fn=None, /, *, lib=None, _stacklevel=1): - def wrap(func): - return func - - return wrap if fn is None else fn - - _custom_op = custom_op_no_op - _register_fake = register_fake_no_op +_custom_op = torch.library.custom_op +_register_fake = torch.library.register_fake # TODO(aryan): Add support for the following: diff --git a/src/diffusers/models/normalization.py b/src/diffusers/models/normalization.py index cd4b3fd167ee..8037fedc302c 100644 --- a/src/diffusers/models/normalization.py +++ b/src/diffusers/models/normalization.py @@ -337,7 +337,7 @@ def __init__( self.silu = nn.SiLU() self.linear = nn.Linear(conditioning_embedding_dim, embedding_dim * 2, bias=bias) if norm_type == "layer_norm": - self.norm = LayerNorm(embedding_dim, eps, elementwise_affine, bias) + self.norm = nn.LayerNorm(embedding_dim, eps, elementwise_affine, bias) elif norm_type == "rms_norm": self.norm = RMSNorm(embedding_dim, eps, elementwise_affine) else: @@ -374,7 +374,7 @@ def __init__( self.linear_1 = nn.Linear(conditioning_embedding_dim, embedding_dim, bias=bias) if norm_type == "layer_norm": - self.norm = LayerNorm(embedding_dim, eps, elementwise_affine, bias) + self.norm = nn.LayerNorm(embedding_dim, eps, elementwise_affine, bias) elif norm_type == "rms_norm": self.norm = RMSNorm(embedding_dim, eps=eps, elementwise_affine=elementwise_affine) else: @@ -469,9 +469,6 @@ def forward( return hidden_states, encoder_hidden_states, gate[:, None, :], enc_gate[:, None, :] -LayerNorm = nn.LayerNorm - - class RMSNorm(nn.Module): r""" RMS Norm as introduced in https://huggingface.co/papers/1910.07467 by Zhang et al. diff --git a/src/diffusers/models/transformers/transformer_cogview4.py b/src/diffusers/models/transformers/transformer_cogview4.py index 2856fffd2a63..6ee6583e5eb7 100644 --- a/src/diffusers/models/transformers/transformer_cogview4.py +++ b/src/diffusers/models/transformers/transformer_cogview4.py @@ -28,7 +28,7 @@ from ..embeddings import CogView3CombinedTimestepSizeEmbeddings from ..modeling_outputs import Transformer2DModelOutput from ..modeling_utils import ModelMixin -from ..normalization import LayerNorm, RMSNorm +from ..normalization import RMSNorm logger = logging.get_logger(__name__) # pylint: disable=invalid-name @@ -598,7 +598,7 @@ def __init__( super().__init__() self.linear = nn.Linear(conditioning_embedding_dim, embedding_dim * 2, bias=bias) if norm_type == "layer_norm": - self.norm = LayerNorm(embedding_dim, eps, elementwise_affine, bias) + self.norm = nn.LayerNorm(embedding_dim, eps, elementwise_affine, bias) elif norm_type == "rms_norm": self.norm = RMSNorm(embedding_dim, eps, elementwise_affine) else: diff --git a/src/diffusers/models/transformers/transformer_glm_image.py b/src/diffusers/models/transformers/transformer_glm_image.py index e2d883d2fecd..ce84b336103e 100644 --- a/src/diffusers/models/transformers/transformer_glm_image.py +++ b/src/diffusers/models/transformers/transformer_glm_image.py @@ -29,7 +29,7 @@ from ..embeddings import PixArtAlphaTextProjection, TimestepEmbedding, Timesteps from ..modeling_outputs import Transformer2DModelOutput from ..modeling_utils import ModelMixin -from ..normalization import LayerNorm, RMSNorm +from ..normalization import RMSNorm logger = logging.get_logger(__name__) # pylint: disable=invalid-name @@ -486,7 +486,7 @@ def __init__( super().__init__() self.linear = nn.Linear(conditioning_embedding_dim, embedding_dim * 2, bias=bias) if norm_type == "layer_norm": - self.norm = LayerNorm(embedding_dim, eps, elementwise_affine, bias) + self.norm = nn.LayerNorm(embedding_dim, eps, elementwise_affine, bias) elif norm_type == "rms_norm": self.norm = RMSNorm(embedding_dim, eps, elementwise_affine) else: diff --git a/src/diffusers/pipelines/audioldm2/pipeline_audioldm2.py b/src/diffusers/pipelines/audioldm2/pipeline_audioldm2.py index 711b484c5faf..b15eae9fc31a 100644 --- a/src/diffusers/pipelines/audioldm2/pipeline_audioldm2.py +++ b/src/diffusers/pipelines/audioldm2/pipeline_audioldm2.py @@ -232,7 +232,7 @@ def enable_model_cpu_offload(self, gpu_id: int | None = None, device: torch.devi if is_accelerate_available(): from accelerate import cpu_offload_with_hook else: - raise ImportError("`enable_model_cpu_offload` requires `accelerate v0.17.0` or higher.") + raise ImportError("`enable_model_cpu_offload` requires `accelerate`: `pip install accelerate`") torch_device = torch.device(device) device_index = torch_device.index diff --git a/src/diffusers/pipelines/deprecated/musicldm/pipeline_musicldm.py b/src/diffusers/pipelines/deprecated/musicldm/pipeline_musicldm.py index 1248773b252e..4044487612bc 100644 --- a/src/diffusers/pipelines/deprecated/musicldm/pipeline_musicldm.py +++ b/src/diffusers/pipelines/deprecated/musicldm/pipeline_musicldm.py @@ -404,7 +404,7 @@ def enable_model_cpu_offload(self, gpu_id=0): if is_accelerate_available(): from accelerate import cpu_offload_with_hook else: - raise ImportError("`enable_model_cpu_offload` requires `accelerate v0.17.0` or higher.") + raise ImportError("`enable_model_cpu_offload` requires `accelerate`: `pip install accelerate`") device_type = get_device() device = torch.device(f"{device_type}:{gpu_id}") diff --git a/src/diffusers/pipelines/kolors/text_encoder.py b/src/diffusers/pipelines/kolors/text_encoder.py index 434f4fed6fbb..541ece74f314 100644 --- a/src/diffusers/pipelines/kolors/text_encoder.py +++ b/src/diffusers/pipelines/kolors/text_encoder.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import math import torch import torch.nn.functional as F @@ -107,12 +106,6 @@ class CoreAttention(torch.nn.Module): def __init__(self, config: ChatGLMConfig, layer_number): super(CoreAttention, self).__init__() - self.apply_query_key_layer_scaling = config.apply_query_key_layer_scaling - self.attention_softmax_in_fp32 = config.attention_softmax_in_fp32 - if self.apply_query_key_layer_scaling: - self.attention_softmax_in_fp32 = True - self.layer_number = max(1, layer_number) - projection_size = config.kv_channels * config.num_attention_heads # Per attention head and per partition values. @@ -120,111 +113,21 @@ def __init__(self, config: ChatGLMConfig, layer_number): self.hidden_size_per_attention_head = projection_size // config.num_attention_heads self.num_attention_heads_per_partition = config.num_attention_heads - coeff = None - self.norm_factor = math.sqrt(self.hidden_size_per_attention_head) - if self.apply_query_key_layer_scaling: - coeff = self.layer_number - self.norm_factor *= coeff - self.coeff = coeff - - self.attention_dropout = torch.nn.Dropout(config.attention_dropout) - def forward(self, query_layer, key_layer, value_layer, attention_mask): - pytorch_major_version = int(torch.__version__.split(".")[0]) - if pytorch_major_version >= 2: - query_layer, key_layer, value_layer = [ - k.permute(1, 2, 0, 3) for k in [query_layer, key_layer, value_layer] - ] - if attention_mask is None and query_layer.shape[2] == key_layer.shape[2]: - context_layer = torch.nn.functional.scaled_dot_product_attention( - query_layer, key_layer, value_layer, is_causal=True - ) - else: - if attention_mask is not None: - attention_mask = ~attention_mask - context_layer = torch.nn.functional.scaled_dot_product_attention( - query_layer, key_layer, value_layer, attention_mask - ) - context_layer = context_layer.permute(2, 0, 1, 3) - new_context_layer_shape = context_layer.size()[:-2] + (self.hidden_size_per_partition,) - context_layer = context_layer.reshape(*new_context_layer_shape) - else: - # Raw attention scores - - # [b, np, sq, sk] - output_size = (query_layer.size(1), query_layer.size(2), query_layer.size(0), key_layer.size(0)) - - # [sq, b, np, hn] -> [sq, b * np, hn] - query_layer = query_layer.view(output_size[2], output_size[0] * output_size[1], -1) - # [sk, b, np, hn] -> [sk, b * np, hn] - key_layer = key_layer.view(output_size[3], output_size[0] * output_size[1], -1) - - # preallocting input tensor: [b * np, sq, sk] - matmul_input_buffer = torch.empty( - output_size[0] * output_size[1], - output_size[2], - output_size[3], - dtype=query_layer.dtype, - device=query_layer.device, + query_layer, key_layer, value_layer = [k.permute(1, 2, 0, 3) for k in [query_layer, key_layer, value_layer]] + if attention_mask is None and query_layer.shape[2] == key_layer.shape[2]: + context_layer = torch.nn.functional.scaled_dot_product_attention( + query_layer, key_layer, value_layer, is_causal=True ) - - # Raw attention scores. [b * np, sq, sk] - matmul_result = torch.baddbmm( - matmul_input_buffer, - query_layer.transpose(0, 1), # [b * np, sq, hn] - key_layer.transpose(0, 1).transpose(1, 2), # [b * np, hn, sk] - beta=0.0, - alpha=(1.0 / self.norm_factor), - ) - - # change view to [b, np, sq, sk] - attention_scores = matmul_result.view(*output_size) - - # =========================== - # Attention probs and dropout - # =========================== - - # attention scores and attention mask [b, np, sq, sk] - if self.attention_softmax_in_fp32: - attention_scores = attention_scores.float() - if self.coeff is not None: - attention_scores = attention_scores * self.coeff - if attention_mask is None and attention_scores.shape[2] == attention_scores.shape[3]: - attention_mask = torch.ones( - output_size[0], 1, output_size[2], output_size[3], device=attention_scores.device, dtype=torch.bool - ) - attention_mask.tril_() - attention_mask = ~attention_mask + else: if attention_mask is not None: - attention_scores = attention_scores.masked_fill(attention_mask, float("-inf")) - attention_probs = F.softmax(attention_scores, dim=-1) - attention_probs = attention_probs.type_as(value_layer) - - # This is actually dropping out entire tokens to attend to, which might - # seem a bit unusual, but is taken from the original Transformer paper. - attention_probs = self.attention_dropout(attention_probs) - # ========================= - # Context layer. [sq, b, hp] - # ========================= - - # value_layer -> context layer. - # [sk, b, np, hn] --> [b, np, sq, hn] - - # context layer shape: [b, np, sq, hn] - output_size = (value_layer.size(1), value_layer.size(2), query_layer.size(0), value_layer.size(3)) - # change view [sk, b * np, hn] - value_layer = value_layer.view(value_layer.size(0), output_size[0] * output_size[1], -1) - # change view [b * np, sq, sk] - attention_probs = attention_probs.view(output_size[0] * output_size[1], output_size[2], -1) - # matmul: [b * np, sq, hn] - context_layer = torch.bmm(attention_probs, value_layer.transpose(0, 1)) - # change view [b, np, sq, hn] - context_layer = context_layer.view(*output_size) - # [b, np, sq, hn] --> [sq, b, np, hn] - context_layer = context_layer.permute(2, 0, 1, 3).contiguous() - # [sq, b, np, hn] --> [sq, b, hp] - new_context_layer_shape = context_layer.size()[:-2] + (self.hidden_size_per_partition,) - context_layer = context_layer.view(*new_context_layer_shape) + attention_mask = ~attention_mask + context_layer = torch.nn.functional.scaled_dot_product_attention( + query_layer, key_layer, value_layer, attention_mask + ) + context_layer = context_layer.permute(2, 0, 1, 3) + new_context_layer_shape = context_layer.size()[:-2] + (self.hidden_size_per_partition,) + context_layer = context_layer.reshape(*new_context_layer_shape) return context_layer diff --git a/src/diffusers/pipelines/pipeline_loading_utils.py b/src/diffusers/pipelines/pipeline_loading_utils.py index 681c6f386aca..3ecf2aaef89a 100644 --- a/src/diffusers/pipelines/pipeline_loading_utils.py +++ b/src/diffusers/pipelines/pipeline_loading_utils.py @@ -602,17 +602,8 @@ def _load_empty_model( cache_dir=cached_folder, ) - if is_transformers_available(): - transformers_version = version.parse(version.parse(transformers.__version__).base_version) - else: - transformers_version = "N/A" - # Determine library. - is_transformers_model = ( - is_transformers_available() - and issubclass(class_obj, PreTrainedModel) - and transformers_version >= version.parse("4.20.0") - ) + is_transformers_model = is_transformers_available() and issubclass(class_obj, PreTrainedModel) diffusers_module = importlib.import_module(__name__.split(".")[0]) is_diffusers_model = issubclass(class_obj, diffusers_module.ModelMixin) @@ -862,11 +853,7 @@ def load_sub_model( else: transformers_version = "N/A" - is_transformers_model = ( - is_transformers_available() - and issubclass(class_obj, PreTrainedModel) - and transformers_version >= version.parse("4.20.0") - ) + is_transformers_model = is_transformers_available() and issubclass(class_obj, PreTrainedModel) # For transformers models >= 4.56.0, use 'dtype' instead of 'torch_dtype' to avoid deprecation warnings if issubclass(class_obj, torch.nn.Module): @@ -893,17 +880,7 @@ def load_sub_model( if is_diffusers_model: loading_kwargs["use_flashpack"] = use_flashpack - # the following can be deleted once the minimum required `transformers` version - # is higher than 4.27 - if ( - is_transformers_model - and loading_kwargs["variant"] is not None - and transformers_version < version.parse("4.27.0") - ): - raise ImportError( - f"When passing `variant='{variant}'`, please make sure to upgrade your `transformers` version to at least 4.27.0.dev0" - ) - elif is_transformers_model and loading_kwargs["variant"] is None: + if is_transformers_model and loading_kwargs["variant"] is None: loading_kwargs.pop("variant") loading_kwargs["low_cpu_mem_usage"] = low_cpu_mem_usage diff --git a/src/diffusers/pipelines/pipeline_utils.py b/src/diffusers/pipelines/pipeline_utils.py index 869fbb78128f..edadc434022c 100644 --- a/src/diffusers/pipelines/pipeline_utils.py +++ b/src/diffusers/pipelines/pipeline_utils.py @@ -1186,7 +1186,7 @@ def enable_model_cpu_offload(self, gpu_id: int | None = None, device: torch.devi if is_accelerate_available(): from accelerate import cpu_offload_with_hook else: - raise ImportError("`enable_model_cpu_offload` requires `accelerate v0.17.0` or higher.") + raise ImportError("`enable_model_cpu_offload` requires `accelerate`: `pip install accelerate`") self.remove_all_hooks() @@ -1294,7 +1294,7 @@ def enable_sequential_cpu_offload(self, gpu_id: int | None = None, device: torch if is_accelerate_available(): from accelerate import cpu_offload else: - raise ImportError("`enable_sequential_cpu_offload` requires `accelerate v0.14.0` or higher") + raise ImportError("`enable_sequential_cpu_offload` requires `accelerate`: `pip install accelerate`") self.remove_all_hooks() is_pipeline_device_mapped = self._is_pipeline_device_mapped() diff --git a/src/diffusers/quantizers/bfl/bfl_quantizer.py b/src/diffusers/quantizers/bfl/bfl_quantizer.py index f421171aec17..bc5dc3ea9227 100644 --- a/src/diffusers/quantizers/bfl/bfl_quantizer.py +++ b/src/diffusers/quantizers/bfl/bfl_quantizer.py @@ -49,7 +49,7 @@ def __init__(self, quantization_config, **kwargs): def validate_environment(self, *args, **kwargs): if not is_accelerate_available(): raise ImportError( - "Loading BFL quantized checkpoints requires `accelerate` installed in your environment: `pip install 'accelerate>=0.26.0'`" + "Loading BFL quantized checkpoints requires `accelerate` installed in your environment: `pip install -U accelerate`" ) def adjust_target_dtype(self, target_dtype: "torch.dtype") -> "torch.dtype": diff --git a/src/diffusers/quantizers/bitsandbytes/bnb_quantizer.py b/src/diffusers/quantizers/bitsandbytes/bnb_quantizer.py index 3b96d4245a21..171c8ae257e4 100644 --- a/src/diffusers/quantizers/bitsandbytes/bnb_quantizer.py +++ b/src/diffusers/quantizers/bitsandbytes/bnb_quantizer.py @@ -63,7 +63,7 @@ def validate_environment(self, *args, **kwargs): raise RuntimeError("No GPU found. A GPU is needed for quantization.") if not is_accelerate_available(): raise ImportError( - "Using `bitsandbytes` 4-bit quantization requires Accelerate: `pip install 'accelerate>=0.26.0'`" + "Using `bitsandbytes` 4-bit quantization requires Accelerate: `pip install -U accelerate`" ) if not is_bitsandbytes_available(): raise ImportError( @@ -381,7 +381,7 @@ def validate_environment(self, *args, **kwargs): raise RuntimeError("No GPU found. A GPU is needed for quantization.") if not is_accelerate_available(): raise ImportError( - "Using `bitsandbytes` 8-bit quantization requires Accelerate: `pip install 'accelerate>=0.26.0'`" + "Using `bitsandbytes` 8-bit quantization requires Accelerate: `pip install -U accelerate`" ) if not is_bitsandbytes_available(): raise ImportError( diff --git a/src/diffusers/quantizers/gguf/gguf_quantizer.py b/src/diffusers/quantizers/gguf/gguf_quantizer.py index 2ac49208f8e9..b21079b82097 100644 --- a/src/diffusers/quantizers/gguf/gguf_quantizer.py +++ b/src/diffusers/quantizers/gguf/gguf_quantizer.py @@ -51,7 +51,7 @@ def __init__(self, quantization_config, **kwargs): def validate_environment(self, *args, **kwargs): if not is_accelerate_available(): raise ImportError( - "Loading GGUF Parameters requires `accelerate` installed in your environment: `pip install 'accelerate>=0.26.0'`" + "Loading GGUF Parameters requires `accelerate` installed in your environment: `pip install -U accelerate`" ) if not is_gguf_available(): raise ImportError( diff --git a/src/diffusers/quantizers/quantization_config.py b/src/diffusers/quantizers/quantization_config.py index 9bd4fce3c3ec..80ecb10e9e05 100644 --- a/src/diffusers/quantizers/quantization_config.py +++ b/src/diffusers/quantizers/quantization_config.py @@ -23,7 +23,6 @@ from __future__ import annotations import copy -import importlib.metadata import json import os import warnings @@ -31,8 +30,6 @@ from enum import Enum from typing import Any, Callable -from packaging import version - from ..utils import deprecate, is_torch_available, is_torchao_available, logging @@ -342,13 +339,6 @@ def post_init(self): if not isinstance(self.bnb_4bit_use_double_quant, bool): raise TypeError("bnb_4bit_use_double_quant must be a boolean") - if self.load_in_4bit and not version.parse(importlib.metadata.version("bitsandbytes")) >= version.parse( - "0.39.0" - ): - raise ValueError( - "4 bit quantization requires bitsandbytes>=0.39.0 - please upgrade your bitsandbytes version" - ) - def is_quantizable(self): r""" Returns `True` if the model is quantizable, `False` otherwise. diff --git a/src/diffusers/quantizers/torchao/torchao_quantizer.py b/src/diffusers/quantizers/torchao/torchao_quantizer.py index fc1be63d23d5..b7d54830e7a2 100644 --- a/src/diffusers/quantizers/torchao/torchao_quantizer.py +++ b/src/diffusers/quantizers/torchao/torchao_quantizer.py @@ -181,12 +181,6 @@ def validate_environment(self, *args, **kwargs): raise ImportError( "Loading a TorchAO quantized model requires the torchao library. Please install with `pip install torchao`" ) - torchao_version = version.parse(importlib.metadata.version("torchao")) - if torchao_version < version.parse("0.15.0"): - raise RuntimeError( - f"The minimum required version of `torchao` is 0.15.0, but the current version is {torchao_version}. Please upgrade with `pip install -U torchao`." - ) - self.offload = False device_map = kwargs.get("device_map", None) @@ -200,16 +194,6 @@ def validate_environment(self, *args, **kwargs): else: self.offload = True - if self.pre_quantized: - weights_only = kwargs.get("weights_only", None) - if weights_only: - torch_version = version.parse(importlib.metadata.version("torch")) - if torch_version < version.parse("2.5.0"): - # TODO(aryan): TorchAO is compatible with Pytorch >= 2.2 for certain quantization types. Try to see if we can support it in future - raise RuntimeError( - f"In order to use TorchAO pre-quantized model, you need to have torch>=2.5.0. However, the current version is {torch_version}." - ) - def update_torch_dtype(self, torch_dtype): config_name = self.quantization_config.quant_type.__class__.__name__ is_int_quant = config_name.startswith("Int") or config_name.startswith("Uint") diff --git a/src/diffusers/utils/accelerate_utils.py b/src/diffusers/utils/accelerate_utils.py index f7deeb6e3931..981e9425eb1d 100644 --- a/src/diffusers/utils/accelerate_utils.py +++ b/src/diffusers/utils/accelerate_utils.py @@ -17,15 +17,9 @@ import functools -from packaging import version - from .import_utils import is_accelerate_available -if is_accelerate_available(): - import accelerate - - def apply_forward_hook(method): """ Decorator that applies a registered CpuOffload hook to an arbitrary function rather than `forward`. This is useful @@ -38,9 +32,6 @@ def apply_forward_hook(method): """ if not is_accelerate_available(): return method - accelerate_version = version.parse(accelerate.__version__).base_version - if version.parse(accelerate_version) < version.parse("0.17.0"): - return method @functools.wraps(method) def wrapper(self, *args, **kwargs): diff --git a/src/diffusers/utils/constants.py b/src/diffusers/utils/constants.py index d17587c65bdc..9a716ef258e7 100644 --- a/src/diffusers/utils/constants.py +++ b/src/diffusers/utils/constants.py @@ -11,19 +11,14 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import importlib import os from huggingface_hub.constants import HF_HOME -from packaging import version -from ..dependency_versions_check import dep_version_check from .import_utils import ENV_VARS_TRUE_VALUES, is_peft_available, is_transformers_available MIN_PEFT_VERSION = "0.17.0" -MIN_TRANSFORMERS_VERSION = "4.34.0" -_CHECK_PEFT = os.environ.get("_CHECK_PEFT", "1") in ENV_VARS_TRUE_VALUES CONFIG_NAME = "config.json" @@ -65,21 +60,7 @@ and not DIFFUSERS_DISABLE_REMOTE_CODE ) -# Below should be `True` if the current version of `peft` and `transformers` are compatible with -# PEFT backend. Will automatically fall back to PEFT backend if the correct versions of the libraries are -# available. -# For PEFT it has to be at least `MIN_PEFT_VERSION` and for transformers at least `MIN_TRANSFORMERS_VERSION`. -_required_peft_version = is_peft_available() and version.parse( - version.parse(importlib.metadata.version("peft")).base_version -) >= version.parse(MIN_PEFT_VERSION) -_required_transformers_version = is_transformers_available() and version.parse( - version.parse(importlib.metadata.version("transformers")).base_version -) >= version.parse(MIN_TRANSFORMERS_VERSION) - -USE_PEFT_BACKEND = _required_peft_version and _required_transformers_version - -if USE_PEFT_BACKEND and _CHECK_PEFT: - dep_version_check("peft") +USE_PEFT_BACKEND = is_peft_available() and is_transformers_available() DECODE_ENDPOINT_SD_V1 = "https://q1bj3bpq6kzilnsu.us-east-1.aws.endpoints.huggingface.cloud/" diff --git a/src/diffusers/utils/import_utils.py b/src/diffusers/utils/import_utils.py index 475688294357..4b6140bc3601 100644 --- a/src/diffusers/utils/import_utils.py +++ b/src/diffusers/utils/import_utils.py @@ -28,7 +28,7 @@ from huggingface_hub.utils import is_jinja_available # noqa: F401 from packaging.requirements import Requirement -from packaging.version import Version, parse +from packaging.version import InvalidVersion, Version, parse from ..dependency_versions_table import deps from . import logging @@ -111,7 +111,15 @@ def _is_package_available(pkg_name: str, get_dist_name: bool = False) -> tuple[b if pkg_exists and import_name in _PKG_TO_DEPS_KEY: requirement = Requirement(deps[_PKG_TO_DEPS_KEY[import_name]]) - if not requirement.specifier.contains(parse(pkg_version).base_version): + try: + base_version = parse(pkg_version).base_version + except InvalidVersion: + logger.warning( + f"Could not parse {import_name} version {pkg_version} to check it against `{requirement}`. " + f"Assuming it is supported." + ) + base_version = None + if base_version is not None and not requirement.specifier.contains(base_version): logger.warning( f"Disabling {import_name} because diffusers requires `{requirement}` but found version {pkg_version}. " f"Upgrade it with `pip install -U '{requirement}'`." diff --git a/tests/others/test_dependencies.py b/tests/others/test_dependencies.py index 990c68a92852..3026f040c662 100644 --- a/tests/others/test_dependencies.py +++ b/tests/others/test_dependencies.py @@ -106,3 +106,6 @@ def test_package_below_min_version_is_unavailable(self, monkeypatch): monkeypatch.setattr(import_utils.importlib_metadata, "version", lambda name: "0.10.0a0+abc") assert import_utils._is_package_available("gguf") == (True, "0.10.0a0+abc") + + monkeypatch.setattr(import_utils.importlib_metadata, "version", lambda name: "not-a-version") + assert import_utils._is_package_available("gguf") == (True, "not-a-version") From 208ceae43f8052d70ffc4c55cb57bbac957fd35a Mon Sep 17 00:00:00 2001 From: DN6 Date: Tue, 3 Nov 2026 22:36:49 +0530 Subject: [PATCH 4/6] Test above-floor version in availability check --- tests/others/test_dependencies.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/others/test_dependencies.py b/tests/others/test_dependencies.py index 3026f040c662..705bc4e02f23 100644 --- a/tests/others/test_dependencies.py +++ b/tests/others/test_dependencies.py @@ -104,6 +104,9 @@ def test_package_below_min_version_is_unavailable(self, monkeypatch): monkeypatch.setattr(import_utils.importlib_metadata, "version", lambda name: "0.10.0") assert import_utils._is_package_available("gguf") == (True, "0.10.0") + monkeypatch.setattr(import_utils.importlib_metadata, "version", lambda name: "0.11.0") + assert import_utils._is_package_available("gguf") == (True, "0.11.0") + monkeypatch.setattr(import_utils.importlib_metadata, "version", lambda name: "0.10.0a0+abc") assert import_utils._is_package_available("gguf") == (True, "0.10.0a0+abc") From eca939bd06d8f54cd54c46d83e5c7c6fd28d6ec4 Mon Sep 17 00:00:00 2001 From: DN6 Date: Tue, 3 Nov 2026 22:44:08 +0530 Subject: [PATCH 5/6] Fail closed on unparseable dependency versions --- src/diffusers/utils/import_utils.py | 10 +++------- tests/others/test_dependencies.py | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/diffusers/utils/import_utils.py b/src/diffusers/utils/import_utils.py index 4b6140bc3601..36c91d609ef7 100644 --- a/src/diffusers/utils/import_utils.py +++ b/src/diffusers/utils/import_utils.py @@ -112,14 +112,10 @@ def _is_package_available(pkg_name: str, get_dist_name: bool = False) -> tuple[b if pkg_exists and import_name in _PKG_TO_DEPS_KEY: requirement = Requirement(deps[_PKG_TO_DEPS_KEY[import_name]]) try: - base_version = parse(pkg_version).base_version + is_supported = requirement.specifier.contains(parse(pkg_version).base_version) except InvalidVersion: - logger.warning( - f"Could not parse {import_name} version {pkg_version} to check it against `{requirement}`. " - f"Assuming it is supported." - ) - base_version = None - if base_version is not None and not requirement.specifier.contains(base_version): + is_supported = False + if not is_supported: logger.warning( f"Disabling {import_name} because diffusers requires `{requirement}` but found version {pkg_version}. " f"Upgrade it with `pip install -U '{requirement}'`." diff --git a/tests/others/test_dependencies.py b/tests/others/test_dependencies.py index 705bc4e02f23..7f88405204fb 100644 --- a/tests/others/test_dependencies.py +++ b/tests/others/test_dependencies.py @@ -111,4 +111,4 @@ def test_package_below_min_version_is_unavailable(self, monkeypatch): assert import_utils._is_package_available("gguf") == (True, "0.10.0a0+abc") monkeypatch.setattr(import_utils.importlib_metadata, "version", lambda name: "not-a-version") - assert import_utils._is_package_available("gguf") == (True, "not-a-version") + assert import_utils._is_package_available("gguf") == (False, "not-a-version") From d573b969a6b22e742a6251387f61e906e0befe69 Mon Sep 17 00:00:00 2001 From: DN6 Date: Wed, 4 Nov 2026 09:57:21 +0530 Subject: [PATCH 6/6] Read version floors in quantizer messages from the deps table --- src/diffusers/models/model_loading_utils.py | 5 +++-- src/diffusers/quantizers/autoround/autoround_quantizer.py | 5 +++-- src/diffusers/quantizers/gguf/gguf_quantizer.py | 3 ++- src/diffusers/quantizers/quantization_config.py | 7 +++++-- src/diffusers/quantizers/sdnq/sdnq_quantizer.py | 3 ++- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/diffusers/models/model_loading_utils.py b/src/diffusers/models/model_loading_utils.py index 56ae25e9fd63..a5edc6043243 100644 --- a/src/diffusers/models/model_loading_utils.py +++ b/src/diffusers/models/model_loading_utils.py @@ -28,6 +28,7 @@ import torch from huggingface_hub.utils import EntryNotFoundError +from ..dependency_versions_table import deps from ..quantizers import DiffusersQuantizer from ..utils import ( DEFAULT_HF_PARALLEL_LOADING_WORKERS, @@ -713,10 +714,10 @@ def load_gguf_checkpoint(gguf_checkpoint_path, return_tensors=False): from ..quantizers.gguf.utils import SUPPORTED_GGUF_QUANT_TYPES, GGUFParameter else: logger.error( - "Loading a GGUF checkpoint in PyTorch, requires both PyTorch and GGUF>=0.10.0 to be installed. Please see " + f"Loading a GGUF checkpoint in PyTorch, requires both PyTorch and `{deps['gguf']}` to be installed. Please see " "https://pytorch.org/ and https://github.com/ggerganov/llama.cpp/tree/master/gguf-py for installation instructions." ) - raise ImportError("Please install torch and gguf>=0.10.0 to load a GGUF checkpoint in PyTorch.") + raise ImportError(f"Please install torch and `{deps['gguf']}` to load a GGUF checkpoint in PyTorch.") reader = GGUFReader(gguf_checkpoint_path) diff --git a/src/diffusers/quantizers/autoround/autoround_quantizer.py b/src/diffusers/quantizers/autoround/autoround_quantizer.py index f80563fed406..7e82b4aaad02 100644 --- a/src/diffusers/quantizers/autoround/autoround_quantizer.py +++ b/src/diffusers/quantizers/autoround/autoround_quantizer.py @@ -14,6 +14,7 @@ from typing import TYPE_CHECKING +from ...dependency_versions_table import deps from ...utils import is_auto_round_available, logging from ..base import DiffusersQuantizer @@ -46,14 +47,14 @@ def __init__(self, quantization_config, **kwargs): def validate_environment(self, *args, **kwargs): """ - Validates that the auto-round library (>= 0.5) is installed and captures the device_map for later use during + Validates that a supported auto-round library is installed and captures the device_map for later use during model conversion. """ self.device_map = kwargs.get("device_map", None) if not is_auto_round_available(): raise ImportError( "Loading an AutoRound quantized model requires the auto-round library " - "(`pip install 'auto-round>=0.13.0'`)" + f"(`pip install -U '{deps['auto-round']}'`)" ) if not self.pre_quantized: raise ValueError( diff --git a/src/diffusers/quantizers/gguf/gguf_quantizer.py b/src/diffusers/quantizers/gguf/gguf_quantizer.py index b21079b82097..e8d862f4e37e 100644 --- a/src/diffusers/quantizers/gguf/gguf_quantizer.py +++ b/src/diffusers/quantizers/gguf/gguf_quantizer.py @@ -9,6 +9,7 @@ from ...models.modeling_utils import ModelMixin +from ...dependency_versions_table import deps from ...utils import ( get_module_from_name, is_accelerate_available, @@ -55,7 +56,7 @@ def validate_environment(self, *args, **kwargs): ) if not is_gguf_available(): raise ImportError( - "To load GGUF format files you must have `gguf` installed in your environment: `pip install gguf>=0.10.0`" + f"To load GGUF format files you must have `gguf` installed in your environment: `pip install -U '{deps['gguf']}'`" ) # Copied from diffusers.quantizers.bitsandbytes.bnb_quantizer.BnB4BitDiffusersQuantizer.adjust_max_memory diff --git a/src/diffusers/quantizers/quantization_config.py b/src/diffusers/quantizers/quantization_config.py index 80ecb10e9e05..8d7c0c343b19 100644 --- a/src/diffusers/quantizers/quantization_config.py +++ b/src/diffusers/quantizers/quantization_config.py @@ -30,6 +30,7 @@ from enum import Enum from typing import Any, Callable +from ..dependency_versions_table import deps from ..utils import deprecate, is_torch_available, is_torchao_available, logging @@ -610,7 +611,9 @@ def __init__( def post_init(self): if not is_torchao_available(): - raise ValueError("TorchAoConfig requires torchao >= 0.15.0. Please upgrade with `pip install -U torchao`.") + raise ValueError( + f"TorchAoConfig requires `{deps['torchao']}`. Please upgrade with `pip install -U '{deps['torchao']}'`." + ) from torchao.quantization.quant_api import AOBaseConfig @@ -635,7 +638,7 @@ def to_dict(self): def from_dict(cls, config_dict, return_unused_kwargs=False, **kwargs): """Create configuration from a dictionary.""" if not is_torchao_available(): - raise NotImplementedError("TorchAoConfig requires torchao >= 0.15.0 for construction from dict") + raise NotImplementedError(f"TorchAoConfig requires `{deps['torchao']}` for construction from dict") config_dict = config_dict.copy() quant_type = config_dict.pop("quant_type") diff --git a/src/diffusers/quantizers/sdnq/sdnq_quantizer.py b/src/diffusers/quantizers/sdnq/sdnq_quantizer.py index fa4b4f775a27..db28c02439d6 100644 --- a/src/diffusers/quantizers/sdnq/sdnq_quantizer.py +++ b/src/diffusers/quantizers/sdnq/sdnq_quantizer.py @@ -14,6 +14,7 @@ from functools import lru_cache +from ...dependency_versions_table import deps from ...utils import is_sdnq_available, logging from ..base import DiffusersQuantizer @@ -24,7 +25,7 @@ def _check_sdnq_requirement(): if not is_sdnq_available(): raise ImportError( - "Loading or creating an SDNQ quantized model requires the sdnq library: `pip install 'sdnq>=0.2.2'`" + f"Loading or creating an SDNQ quantized model requires the sdnq library: `pip install '{deps['sdnq']}'`" )