From 0ed0e78cc510d0d0f463e133700e8ea32af9d8eb Mon Sep 17 00:00:00 2001 From: usmanmateen <74776275+usmanmateen@users.noreply.github.com> Date: Wed, 21 Oct 2026 09:23:58 +0100 Subject: [PATCH 1/3] Add a test for importing models with torchao older than 0.15 --- tests/others/test_dependencies.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/others/test_dependencies.py b/tests/others/test_dependencies.py index 924f5418cc40..d7382303357e 100644 --- a/tests/others/test_dependencies.py +++ b/tests/others/test_dependencies.py @@ -13,6 +13,9 @@ # limitations under the License. import inspect +import os +import subprocess +import sys from importlib import import_module import pytest @@ -22,6 +25,25 @@ class TestDependencies: def test_diffusers_import(self): import diffusers # noqa: F401 + def test_model_import_with_torchao_older_than_0_15(self, tmp_path): + # FqnToConfig only exists from torchao 0.15. An older torchao, such as the one on Google Colab, must not + # stop models from importing. + (tmp_path / "torchao" / "quantization").mkdir(parents=True) + (tmp_path / "torchao" / "__init__.py").write_text("") + (tmp_path / "torchao" / "quantization" / "__init__.py").write_text( + "def quantize_(*args, **kwargs):\n pass\n" + ) + (tmp_path / "torchao-0.14.1.dist-info").mkdir() + (tmp_path / "torchao-0.14.1.dist-info" / "METADATA").write_text( + "Metadata-Version: 2.1\nName: torchao\nVersion: 0.14.1\n" + ) + env = {**os.environ, "PYTHONPATH": os.pathsep.join([str(tmp_path), os.environ.get("PYTHONPATH", "")])} + + result = subprocess.run( + [sys.executable, "-c", "from diffusers import UNet2DModel"], env=env, capture_output=True, text=True + ) + assert result.returncode == 0, result.stderr + def test_backend_registration(self): import diffusers from diffusers.dependency_versions_table import deps From 1f66033eb3c4577a5fd64c6ff6f946b543383de0 Mon Sep 17 00:00:00 2001 From: usmanmateen <74776275+usmanmateen@users.noreply.github.com> Date: Wed, 21 Oct 2026 09:23:58 +0100 Subject: [PATCH 2/3] Only import FqnToConfig from torchao 0.15 on torchao_quantizer.py imported FqnToConfig whenever torchao was installed, but it only exists from torchao 0.15. With an older torchao, importing any model failed, including on Google Colab. --- src/diffusers/quantizers/torchao/torchao_quantizer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/diffusers/quantizers/torchao/torchao_quantizer.py b/src/diffusers/quantizers/torchao/torchao_quantizer.py index 8e781ebb143a..e31db9faa068 100644 --- a/src/diffusers/quantizers/torchao/torchao_quantizer.py +++ b/src/diffusers/quantizers/torchao/torchao_quantizer.py @@ -51,7 +51,8 @@ import torch import torch.nn as nn -if is_torchao_available(): +# `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"): from torchao.quantization import FqnToConfig, quantize_ if is_torchao_version(">=", "0.16.0"): From 6ed7a1ec28bb80fd28f9d4c59813465a1716b15d Mon Sep 17 00:00:00 2001 From: usmanmateen <74776275+usmanmateen@users.noreply.github.com> Date: Wed, 21 Oct 2026 09:33:06 +0100 Subject: [PATCH 3/3] Remove the torchao import test --- tests/others/test_dependencies.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/tests/others/test_dependencies.py b/tests/others/test_dependencies.py index d7382303357e..924f5418cc40 100644 --- a/tests/others/test_dependencies.py +++ b/tests/others/test_dependencies.py @@ -13,9 +13,6 @@ # limitations under the License. import inspect -import os -import subprocess -import sys from importlib import import_module import pytest @@ -25,25 +22,6 @@ class TestDependencies: def test_diffusers_import(self): import diffusers # noqa: F401 - def test_model_import_with_torchao_older_than_0_15(self, tmp_path): - # FqnToConfig only exists from torchao 0.15. An older torchao, such as the one on Google Colab, must not - # stop models from importing. - (tmp_path / "torchao" / "quantization").mkdir(parents=True) - (tmp_path / "torchao" / "__init__.py").write_text("") - (tmp_path / "torchao" / "quantization" / "__init__.py").write_text( - "def quantize_(*args, **kwargs):\n pass\n" - ) - (tmp_path / "torchao-0.14.1.dist-info").mkdir() - (tmp_path / "torchao-0.14.1.dist-info" / "METADATA").write_text( - "Metadata-Version: 2.1\nName: torchao\nVersion: 0.14.1\n" - ) - env = {**os.environ, "PYTHONPATH": os.pathsep.join([str(tmp_path), os.environ.get("PYTHONPATH", "")])} - - result = subprocess.run( - [sys.executable, "-c", "from diffusers import UNet2DModel"], env=env, capture_output=True, text=True - ) - assert result.returncode == 0, result.stderr - def test_backend_registration(self): import diffusers from diffusers.dependency_versions_table import deps