Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Install torchao in Backend CI, and stop one test's allowlist answer leaking into the rest (#8486)

Daniel Han4f520e01a7ed
diff --git a/.github/workflows/studio-backend-ci.yml b/.github/workflows/studio-backend-ci.yml
index 22bd7f2cdb8..4a12632a0b1 100644
--- a/.github/workflows/studio-backend-ci.yml
+++ b/.github/workflows/studio-backend-ci.yml
@@ -97,6 +97,13 @@ jobs:
# keeps the install ~250 MB / ~1 min on a clean runner.
pip install --index-url https://download.pytorch.org/whl/cpu --extra-index-url https://pypi.org/simple 'torch>=2.4,<2.11'
pip install 'transformers>=4.51,<5.5'
+ # torchao: the pre-quant allowlist is built by importing the torchao tensor
+ # constructors a checkpoint names, and registration refuses unless at least one of
+ # them resolves. Without it every pre-quant load returns None and 21 tests across
+ # test_diffusion_prequant.py and test_diffusion_convrot.py fail on an install that is
+ # simply missing a dependency they need. CPU-only is fine: it declines to load its cpp
+ # extensions under torch < 2.11 and the pure-Python constructors still import.
+ pip install torchao
- name: Backend tests
working-directory: studio/backend
diff --git a/studio/backend/tests/conftest.py b/studio/backend/tests/conftest.py
index ff7e637ed6f..2d466acf62e 100644
--- a/studio/backend/tests/conftest.py
+++ b/studio/backend/tests/conftest.py
@@ -157,6 +157,34 @@ def _isolate_xet_health_state():
hf_xet_health.clear_xet_health()
[email protected](autouse = True)
+def _confine_prequant_registration_memo():
+ """Keep one test's answer about the pre-quant allowlist from becoming every later test's.
+
+ ``diffusion_prequant`` asks once whether this torch can register the constructor allowlist and
+ memoises the answer, INCLUDING the failure, in a module global. That is right in a process
+ where torch never changes. It is wrong in this suite, where several files put a fake torch in
+ ``sys.modules``: the question gets asked while the fake is installed, the answer is False, and
+ ``monkeypatch`` restores ``sys.modules`` but not the memo. Every later real load then refuses.
+
+ Measured on main: after ``test_diffusion_backend.py`` the memo reads False, where it reads None
+ when that file runs alone. In a full-suite run that turned 20 tests across
+ ``test_diffusion_prequant.py`` and ``test_diffusion_convrot.py`` red, all with the same
+ ``assert None is not None``, while every one of them passed when its file ran by itself.
+
+ Restored rather than cleared, so nothing re-registers 22k times and a test that sets the memo
+ deliberately still sees its own value.
+ """
+ from core.inference import diffusion_prequant
+
+ registered = diffusion_prequant._SAFE_GLOBALS_REGISTERED
+ resolved = set(diffusion_prequant._RESOLVED_SAFE_GLOBALS)
+ yield
+ diffusion_prequant._SAFE_GLOBALS_REGISTERED = registered
+ diffusion_prequant._RESOLVED_SAFE_GLOBALS.clear()
+ diffusion_prequant._RESOLVED_SAFE_GLOBALS.update(resolved)
+
+
@pytest.fixture(autouse = True)
def _isolate_audio_gallery(monkeypatch, tmp_path):
"""Keep generated-clip persistence out of the developer's real gallery.