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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio tests: skip pre-quant tests without torchao and pin the Mac memory reading (#17117)
Daniel Han39f0ea3a4302
diff --git a/studio/backend/tests/_torchao_installed.py b/studio/backend/tests/_torchao_installed.pynew file mode 100644index 00000000000..beabf907c7e--- /dev/null+++ b/studio/backend/tests/_torchao_installed.py@@ -0,0 +1,28 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Skip for tests whose claim needs a real torchao install.++Read from the installed distribution, not ``import torchao``: other tests put fake torchao modules in+``sys.modules``, so an import can succeed where torchao is absent (macOS, which installs MLX instead).+"""++from __future__ import annotations++import importlib.metadata++import pytest+++def torchao_installed() -> bool:+ try:+ importlib.metadata.version("torchao")+ except importlib.metadata.PackageNotFoundError:+ return False+ return True+++needs_torchao = pytest.mark.skipif(+ not torchao_installed(),+ reason = "needs torchao installed: without it no pre-quant checkpoint can load, so none is planned",+)diff --git a/studio/backend/tests/test_diffusion_backend.py b/studio/backend/tests/test_diffusion_backend.pyindex 48512d91c37..5c00d6dcfb5 100644--- a/studio/backend/tests/test_diffusion_backend.py+++ b/studio/backend/tests/test_diffusion_backend.py@@ -17,6 +17,8 @@ from pathlib import Pathimport pytest+from ._torchao_installed import needs_torchao+from core.inference.diffusion import (DiffusionBackend,DiffusionModelReplacedError,@@ -8797,6 +8799,7 @@ def test_download_plan_stages_no_second_denoiser_for_an_uncached_prequant(monkeyassert plan["total_bytes"] == 4 * GB + base["bytes"] < 17 * GB+@needs_torchaodef test_download_plan_counts_the_hosted_prequant_in_the_required_footprint(monkeypatch):_fake_zimage_hub(monkeypatch)_stub_hosted_prequant(monkeypatch, cached = False)@@ -8883,6 +8886,7 @@ def test_download_plan_counts_a_cached_lower_auto_prequant(monkeypatch):assert not any(source.filename in entry["files"] for entry in plan["entries"])+@needs_torchaodef test_download_plan_omits_the_prequant_under_a_definite_offload_policy(monkeypatch):# Balanced / low_vram offload by MODE, so the load keeps the GGUF and never fetches the prequant._fake_zimage_hub(monkeypatch)@@ -8910,6 +8914,7 @@ def test_download_plan_omits_the_prequant_under_a_definite_offload_policy(monkeyassert any(f.endswith("-FP8.pt") for e in resident["entries"] for f in e["files"])+@needs_torchaodef test_download_plan_omits_the_prequant_for_an_auto_pick_at_speed_off(monkeypatch):# load_pipeline forces an AUTO quant to "off" under Speed="off", which normalizes to None and# skips the fast path, so nothing is fetched and the footprint must not claim it.@@ -11823,6 +11828,7 @@ def test_generation_in_flight_never_builds_a_backend(fake_runtime, monkeypatch):assert diffusion_mod.generation_in_flight() is False+@needs_torchaodef test_the_download_plan_resolves_the_same_nvfp4_rung_the_load_does(monkeypatch):from types import SimpleNamespace@@ -14202,6 +14208,8 @@ def test_gguf_offload_swap_on_mps_keeps_the_gguf(fake_runtime, tmp_path, monkeypfrom core.inference.diffusion_transformer_quant import dense_transformer_supportedmonkeypatch.setattr(dmod, "dense_transformer_supported", dense_transformer_supported)+ # The unified-memory check reads the host's free memory; a fixed 64 GB Mac keeps the runner's out of it.+ monkeypatch.setattr(dmod, "settled_snapshot_device_memory", _unified_snapshot(64))# z-image defaults to its hosted int8 ConvRot encoder, which this offline fixture does not carry; MPS budgets# for that file alone, so the encoder is not what is under test here.status = _load_gguf(backend, tmp_path, text_encoder_quant = "none")diff --git a/studio/backend/tests/test_diffusion_pipeline_prequant.py b/studio/backend/tests/test_diffusion_pipeline_prequant.pyindex 4dd40fdac2f..ea06f4537cb 100644--- a/studio/backend/tests/test_diffusion_pipeline_prequant.py+++ b/studio/backend/tests/test_diffusion_pipeline_prequant.py@@ -13,6 +13,8 @@ import typesimport pytest+from ._torchao_installed import needs_torchao+from core.inference import diffusion as dmodfrom core.inference import diffusion_prequant as pqmodfrom core.inference import diffusion_transformer_quant as tqmod@@ -201,6 +203,7 @@ def _plan_backend(return backend+@needs_torchaodef test_the_plan_counts_and_stages_the_hosted_checkpoint(monkeypatch, hub):backend = _plan_backend(monkeypatch, planned = "fp8")plan = backend.download_plan(Z_IMAGE_REPO, model_kind = "pipeline")@@ -235,6 +238,7 @@ def test_a_declined_plan_keeps_the_released_shards(monkeypatch, hub):assert all(shard in entries[Z_IMAGE_REPO]["files"] for shard in DENOISER_SHARDS)+@needs_torchaodef test_the_artifact_carries_the_denoiser_share_of_the_unified_memory_verdict(monkeypatch, hub):"""The unified-memory refusal prices the denoiser from the artifact, not the dropped shards."""backend = _plan_backend(monkeypatch, planned = "fp8")@@ -1963,6 +1967,7 @@ def test_a_large_variant_of_a_small_dit_family_quantises_under_auto(fake_runtimeassert spy.quantised == ["auto"]+@needs_torchao@pytest.mark.parametrize("shared_repo", [False, True])def test_denoiser_is_a_checkpoint_and_encoder_only_is_an_asset(monkeypatch, hub, shared_repo):backend = _plan_backend(monkeypatch, planned = "fp8")diff --git a/studio/backend/tests/test_prequant_safetensors.py b/studio/backend/tests/test_prequant_safetensors.pyindex 14b067f4ade..f01362eaef1 100644--- a/studio/backend/tests/test_prequant_safetensors.py+++ b/studio/backend/tests/test_prequant_safetensors.py@@ -11,6 +11,8 @@ import sysimport pytest+from ._torchao_installed import needs_torchao+import core.inference.diffusion_prequant as pqimport core.inference.prequant_safetensors as psfrom core.inference.diffusion_families import DiffusionFamily@@ -392,6 +394,7 @@ def test_the_windows_rocm_torchao_stub_is_not_safetensors_support(monkeypatch):assert restricted_prequant_load_supported("fp8", "Model-FP8.pt") is False+@needs_torchaodef test_a_scheme_this_torchao_cannot_flatten_is_reported_before_the_build(monkeypatch):"""Importing helpers proves nothing; torchao 0.17 int8 cannot flatten, so report it before building."""import torchao.quantization as tq@@ -428,6 +431,7 @@ def test_a_scheme_this_torchao_cannot_flatten_is_reported_before_the_build(monkeassert ps.scheme_is_flattenable("cfg") is False+@needs_torchaodef test_the_real_installed_torchao_answers_the_int8_question(monkeypatch):"""Not a mock: the probe against the torchao actually installed, whichever way it answers."""from core.inference.diffusion_transformer_quant import _make_quant_config@@ -443,6 +447,7 @@ def test_the_real_installed_torchao_answers_the_int8_question(monkeypatch):assert answer is not False, f"torchao {torchao.__version__} should flatten int8"+@needs_torchaodef test_a_root_level_plain_tensor_round_trips_instead_of_failing_the_build(tmp_path):"""Root-level plain tensors are split before flatten and restored after, so z-image builds survive."""torch = pytest.importorskip("torch")diff --git a/studio/backend/tests/test_video_te_quant_default.py b/studio/backend/tests/test_video_te_quant_default.pyindex 431d2914215..208dda62866 100644--- a/studio/backend/tests/test_video_te_quant_default.py+++ b/studio/backend/tests/test_video_te_quant_default.py@@ -12,6 +12,8 @@ import typesimport pytestimport torch+from ._torchao_installed import needs_torchao+import core.inference.diffusion_te_prequant as tpqfrom core.inference.video import video_te_quant_requestfrom core.inference.video_families import _FAMILIES, detect_video_family@@ -341,6 +343,7 @@ def _converter():return module+@needs_torchaodef test_the_converter_can_store_a_tied_embedding_once(tmp_path, monkeypatch):"""--drop-tied-copies writes UMT5's shared/embed_tokens pair once, the round trip still verifies, and the fp8loader fills the alias back from the model's own tie."""@@ -592,6 +595,7 @@ def test_ltx25_budgets_the_dense_peak_unless_the_hosted_encoder_applies(monkeypa)+@needs_torchaodef test_drop_tied_copies_keeps_a_tied_lm_head(tmp_path):import core.inference.prequant_safetensors as ps