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.

Studio: pair torch <= 2.8 with torchao 0.15 and gate torchao export on 0.15 (#13329)

Daniel Han3a1b69488282
diff --git a/studio/backend/core/_torchao_stub.py b/studio/backend/core/_torchao_stub.py
index b09c44cce30..92fc31955da 100644
--- a/studio/backend/core/_torchao_stub.py
+++ b/studio/backend/core/_torchao_stub.py
@@ -267,8 +267,8 @@ class _FqnAliasBeforeDiffusers(importlib.abc.MetaPathFinder):
def alias_torchao_fqn_to_config() -> None:
- """diffusers 0.41 imports ``FqnToConfig`` from torchao unguarded; torchao < 0.15 (Studio's torch <= 2.8
- pairing) names it ``ModuleFqnToConfig``, and 0.15 keeps ``ModuleFqnToConfig = FqnToConfig``.
+ """diffusers 0.41 imports ``FqnToConfig`` from torchao unguarded; torchao < 0.15 (what older Studio
+ installs paired with torch <= 2.8) names it ``ModuleFqnToConfig``, and 0.15 keeps ``ModuleFqnToConfig = FqnToConfig``.
Deferred to the first diffusers import: importing torchao here would load torch into the server
process and every spawn child (seconds and ~600 MB each) that never touch diffusers."""
if "diffusers" in sys.modules or "torchao.quantization" in sys.modules:
@@ -294,19 +294,60 @@ def _load_torchao_nodist():
return None
-_TORCHAO_EXPORT_MIN = (0, 15)
+_TORCHAO_EXPORT_MIN = "0.15.0"
+
+
+def _torchao_below(version: str, floor: str) -> bool:
+ """PEP 440 compare, as transformers and diffusers do: 0.15.0rc1 and 0.15.0.dev are below 0.15.0."""
+ try:
+ from packaging.version import Version
+ return Version(version) < Version(floor)
+ except Exception: # noqa: BLE001 -- packaging missing or an unparseable version
+ have = re.match(r"(\d+)\.(\d+)", version or "")
+ need = re.match(r"(\d+)\.(\d+)", floor or "")
+ return bool(have and need) and (int(have[1]), int(have[2])) < (int(need[1]), int(need[2]))
+
+
+def _transformers_torchao_min() -> Optional[str]:
+ """``TORCHAO_MIN_VERSION`` of the installed transformers, read from its source without importing it:
+ 0.15.0 on transformers 5.5, 0.4.0 on the 4.57.6 Python 3.9 pin. None when it cannot be read."""
+ try:
+ spec = importlib.util.find_spec("transformers")
+ locations = list(spec.submodule_search_locations or ()) if spec else []
+ if not locations:
+ return None
+ with open(os.path.join(locations[0], "utils", "import_utils.py"), encoding = "utf-8") as f:
+ found = re.search(r"^TORCHAO_MIN_VERSION\s*=\s*[\"']([^\"']+)[\"']", f.read(), re.M)
+ return found[1] if found else None
+ except Exception: # noqa: BLE001 -- unreadable: do not guess a floor
+ return None
+
+
+def torchao_too_old_for_export() -> Optional[str]:
+ """The installed torchao version when the installed transformers' TorchAoConfig refuses it (below
+ 0.15 on transformers 5.5, which then reports torchao as not installed at all), else None. Reads
+ metadata and source only: never imports torchao or transformers, so it is safe at server startup."""
+ try:
+ version = importlib.metadata.version("torchao")
+ except Exception: # noqa: BLE001 -- absent or unreadable: nothing to name
+ return None
+ floor = _transformers_torchao_min()
+ if not version or not floor:
+ return None
+ return version if _torchao_below(version, floor) else None
def torchao_export_loadable() -> bool:
- """checks Windows ROCm for torchao and unsloth's shim without imports; true elsewhere."""
+ """False when the installed torchao is too old for TorchAoConfig; on Windows ROCm also checks
+ for torchao and unsloth's shim. Never imports either."""
if not _is_windows_rocm():
- return True
+ return torchao_too_old_for_export() is None
try:
if importlib.machinery.PathFinder.find_spec("torchao") is None:
return False
- # TorchAoConfig requires torchao 0.15; torch <= 2.8 is paired with torchao 0.14
- found = re.match(r"(\d+)\.(\d+)", importlib.metadata.version("torchao"))
- if not found or (int(found[1]), int(found[2])) < _TORCHAO_EXPORT_MIN:
+ # TorchAoConfig requires torchao 0.15
+ version = importlib.metadata.version("torchao")
+ if not re.match(r"\d+\.\d+", version or "") or _torchao_below(version, _TORCHAO_EXPORT_MIN):
return False
spec = importlib.util.find_spec("unsloth")
locations = list(spec.submodule_search_locations or ()) if spec else []
diff --git a/studio/backend/core/export/export.py b/studio/backend/core/export/export.py
index 448bc6d9d55..0468fff846b 100644
--- a/studio/backend/core/export/export.py
+++ b/studio/backend/core/export/export.py
@@ -419,6 +419,15 @@ def _torchao_runtime_unavailable():
return False
+def _torchao_too_old():
+ """Installed torchao version when it is below what transformers' TorchAoConfig accepts, else None."""
+ try:
+ from core._torchao_stub import torchao_too_old_for_export
+ return torchao_too_old_for_export()
+ except Exception:
+ return None
+
+
def _is_torchao_alias(alias):
"""Any torchao spelling unsloth's normalizer accepts, else a torchao_ prefix, so the Windows
ROCm guard catches it before it is misread as compressed-tensors."""
@@ -1140,6 +1149,18 @@ class ExportBackend:
None,
)
+ # transformers 5 refuses torchao < 0.15 as "requires torchao to be installed"; name the real cause.
+ if _is_torchao_alias(compressed_alias):
+ _old_torchao = _torchao_too_old()
+ if _old_torchao:
+ return (
+ False,
+ f"Portable torchao FP8/INT8 export needs torchao 0.15 or newer, but torchao "
+ f"{_old_torchao} is installed. Update Unsloth to install a newer torchao, or "
+ "use 16-bit merged or GGUF quantization instead.",
+ None,
+ )
+
compressed_suffix: Optional[str] = None
# Classify the alias: torchao-portable vs compressed-tensors.
torchao_info = None
diff --git a/studio/backend/core/inference/diffusion_precision.py b/studio/backend/core/inference/diffusion_precision.py
index efc6f959037..157616e40bf 100644
--- a/studio/backend/core/inference/diffusion_precision.py
+++ b/studio/backend/core/inference/diffusion_precision.py
@@ -183,7 +183,7 @@ def te_quant_unsupported_reason(mode: str) -> str:
@lru_cache(maxsize = 1)
def nvfp4_weight_only_importable() -> bool:
- """requires torchao 0.15+; Studio pins 0.14 with torch <= 2.8."""
+ """requires torchao 0.15+; older Studio installs kept 0.14 with torch <= 2.8."""
try:
from torchao.prototype.mx_formats import NVFP4WeightOnlyConfig
from .diffusion_transformer_quant import _quiet_config
diff --git a/studio/backend/core/inference/diffusion_prequant.py b/studio/backend/core/inference/diffusion_prequant.py
index 179dab8188a..7158bb2dde3 100644
--- a/studio/backend/core/inference/diffusion_prequant.py
+++ b/studio/backend/core/inference/diffusion_prequant.py
@@ -86,7 +86,7 @@ ALLOW_LOCAL_PREQUANT_PATH_ENV = "UNSLOTH_ALLOW_LOCAL_PREQUANT_PATH"
# local. Registered under the name the PICKLE records, which for a re-exported class is not the class's own
# ``__module__`` (``torchao.quantization.Float8Tensor`` really lives in
# ``...quantize_.workflows.float8.float8_tensor``), so both spellings are listed. Names a given torchao lacks are
-# skipped rather than raised: the set spans every release ``install_python_stack`` pins (0.14, 0.16, 0.17) and an
+# skipped rather than raised: the set spans every release ``install_python_stack`` pins or pinned (0.14 to 0.18) and an
# absent class could not have produced a loadable checkpoint here anyway. Adding a scheme means adding its
# constructors here; forgetting warns and falls back to dense-quantise, never a silent unpickle.
_PREQUANT_SAFE_GLOBALS: tuple[tuple[str, str], ...] = (
diff --git a/studio/backend/tests/test_diffusion_precision.py b/studio/backend/tests/test_diffusion_precision.py
index f7a1bb0fb8f..ed1756533a0 100644
--- a/studio/backend/tests/test_diffusion_precision.py
+++ b/studio/backend/tests/test_diffusion_precision.py
@@ -134,7 +134,7 @@ def test_nvfp4_supported_requires_cuda_bf16_and_fp8_dtype(monkeypatch):
def test_nvfp4_unsupported_when_torchao_lacks_the_weight_only_config(monkeypatch):
- # Studio pins torchao 0.14 for torch <= 2.8, which lacks NVFP4WeightOnlyConfig
+ # older Studio installs keep torchao 0.14 with torch <= 2.8, which lacks NVFP4WeightOnlyConfig
_stub_torch(monkeypatch, cc = (8, 6), nvfp4_config = False)
assert te_quant_supported(_target(cc = (8, 6)), TE_QUANT_NVFP4) is False
assert te_quant_supported(_target(cc = (8, 6)), TE_QUANT_INT8) is True
diff --git a/studio/backend/tests/test_torchao_select.py b/studio/backend/tests/test_torchao_select.py
index 4b4de2431d2..47a3f3a151a 100644
--- a/studio/backend/tests/test_torchao_select.py
+++ b/studio/backend/tests/test_torchao_select.py
@@ -72,15 +72,20 @@ def _load_module(monkeypatch):
("2.9.0+cu128", "torchao==0.15.0"),
("2.9.1", "torchao==0.15.0"),
("2.9.1+rocm6.4", "torchao==0.15.0"),
- # torch <= 2.8 retains the 0.14.0 pin.
- ("2.8.0", "torchao==0.14.0"),
+ # torch <= 2.8 gets 0.15.0 too: transformers 5 and diffusers 0.41 refuse TorchAoConfig on 0.14.
+ ("2.8.0", "torchao==0.15.0"),
+ ("2.8.0+cu128", "torchao==0.15.0"),
+ ("2.7.1+cu126", "torchao==0.15.0"),
+ ("2.6.0+cu124", "torchao==0.15.0"),
+ # torchao 0.15 dropped torch <= 2.5, so those keep 0.14.0.
+ ("2.5.1+cu124", "torchao==0.14.0"),
("2.4.0", "torchao==0.14.0"),
# malformed, missing, and non-2.x versions use the conservative default.
- (None, "torchao==0.14.0"),
- ("", "torchao==0.14.0"),
- ("garbage", "torchao==0.14.0"),
- ("2", "torchao==0.14.0"),
- ("3.0.0", "torchao==0.14.0"),
+ (None, "torchao==0.15.0"),
+ ("", "torchao==0.15.0"),
+ ("garbage", "torchao==0.15.0"),
+ ("2", "torchao==0.15.0"),
+ ("3.0.0", "torchao==0.15.0"),
],
)
def test_select_torchao_spec(monkeypatch, torch_version, expected):
@@ -89,10 +94,30 @@ def test_select_torchao_spec(monkeypatch, torch_version, expected):
def test_default_spec_matches_table(monkeypatch):
- """the historical default keeps older torch versions unchanged."""
+ """torch 2.6-2.8 shares torch 2.9's torchao: below 0.15 transformers and diffusers refuse TorchAoConfig."""
mod = _load_module(monkeypatch)
- assert mod._TORCHAO_DEFAULT_SPEC == "torchao==0.14.0"
+ assert mod._TORCHAO_DEFAULT_SPEC == "torchao==0.15.0"
assert mod._select_torchao_spec("2.8.0") == mod._TORCHAO_DEFAULT_SPEC
+ assert mod._TORCHAO_DEFAULT_SPEC == mod._TORCHAO_TORCH_29_SPEC
+
+
[email protected]("installed", ["0.14.0", "0.14.0+cu128", "0.14.1+cu128", "0.13.0"])
+def test_an_old_torch_install_on_torchao_014_is_repinned(monkeypatch, installed):
+ """An existing torch <= 2.8 install keeps torchao 0.14 until its next dependency pass, which
+ must force 0.15.0 over it even when the pass has evidence to skip satisfied steps."""
+ mod = _load_module(monkeypatch)
+ monkeypatch.setattr(mod, "_installed_distribution_version", lambda _name: installed)
+ monkeypatch.setattr(mod, "_may_skip_on_evidence", lambda: True)
+ calls = []
+ monkeypatch.setattr(mod, "pip_install_try", lambda *a, **k: calls.append(a) or True)
+ monkeypatch.setattr(mod, "pip_install", lambda *a, **k: calls.append(a))
+ monkeypatch.setattr(mod, "_record_step", lambda *a, **k: None)
+ monkeypatch.setattr(mod, "_note", lambda *a, **k: None)
+ mod._install_torchao_for_torch("2.8.0+cu128")
+ assert len(calls) == 1, calls
+ args = calls[0]
+ assert "torchao==0.15.0" in args and "--force-reinstall" in args
+ assert "https://download.pytorch.org/whl/cu128" in args
def test_matching_torchao_pin_does_not_need_force_reinstall(monkeypatch):
@@ -140,6 +165,9 @@ _TORCHAO_INDEX_GAPS = {
range(8, 14),
),
"rocm7.0": ({16: "0.16.0"}, range(9, 11)),
+ # Legacy leaves frozen before torchao 0.10 / 0.11: neither 0.14.0 nor 0.15.0 was ever there.
+ "cu124": ({m: f"0.{m}.0" for m in range(3, 10)}, range(4, 7)),
+ "rocm6.1": ({m: f"0.{m}.0" for m in range(7, 10)}, range(4, 7)),
}
@@ -157,10 +185,15 @@ def test_the_index_pin_starves_only_where_the_retry_covers_it(monkeypatch):
assert starved == {
# cu118 lacks every selected torchao release for torch 2.5 through 2.7.
("cu118", 5, "0.14.0"),
- ("cu118", 6, "0.14.0"),
- ("cu118", 7, "0.14.0"),
- # cu129 lacks torchao 0.14.0 and releases after 0.17.0.
- ("cu129", 8, "0.14.0"),
+ ("cu118", 6, "0.15.0"),
+ ("cu118", 7, "0.15.0"),
+ ("cu124", 4, "0.14.0"),
+ ("cu124", 5, "0.14.0"),
+ ("cu124", 6, "0.15.0"),
+ ("rocm6.1", 4, "0.14.0"),
+ ("rocm6.1", 5, "0.14.0"),
+ ("rocm6.1", 6, "0.15.0"),
+ # cu129 lacks releases after 0.17.0 (it does carry 0.15.0, which torch 2.8 now selects).
("cu129", 12, "0.18.0"),
("cu129", 13, "0.18.0"),
# rocm7.0 provides only torchao 0.16.0.
@@ -560,8 +593,12 @@ def test_torchao_export_not_rejected_with_real_torchao_on_windows_rocm(monkeypat
[
("win32", True, False, False),
("win32", True, True, True),
- ("win32", False, False, True),
- ("linux", True, False, True),
+ # torchao_export_loadable is asked everywhere now: it also says no to torchao < 0.15.
+ ("win32", False, False, False),
+ ("win32", False, True, True),
+ ("linux", True, False, False),
+ ("linux", False, False, False),
+ ("linux", False, True, True),
],
)
def test_export_capability_torchao_flag(monkeypatch, platform, is_rocm, loadable, expected):
@@ -574,6 +611,119 @@ def test_export_capability_torchao_flag(monkeypatch, platform, is_rocm, loadable
assert hw.export_capability()["torchao_export_supported"] is expected
+ ("platform", "is_rocm", "expected"),
+ [("win32", True, False), ("win32", False, True), ("linux", False, True), ("linux", True, True)],
+)
+def test_export_capability_fails_open_off_windows_rocm(monkeypatch, platform, is_rocm, expected):
+ import utils.hardware.hardware as hw
+
+ def broken():
+ raise RuntimeError("probe failed")
+
+ monkeypatch.setattr(hw, "get_device", lambda: hw.DeviceType.CUDA)
+ monkeypatch.setattr(sys, "platform", platform)
+ monkeypatch.setattr(hw, "IS_ROCM", is_rocm)
+ monkeypatch.setattr(_stub, "torchao_export_loadable", broken)
+ assert hw.export_capability()["torchao_export_supported"] is expected
+
+
+ ("installed", "too_old"),
+ [
+ ("0.14.0", "0.14.0"),
+ ("0.14.1+cu128", "0.14.1+cu128"),
+ ("0.13.0", "0.13.0"),
+ # PEP 440, as transformers compares: prereleases of 0.15.0 are still below it.
+ ("0.15.0rc1", "0.15.0rc1"),
+ ("0.15.0.dev20250901", "0.15.0.dev20250901"),
+ ("0.15.0", None),
+ ("0.15.0+cu126", None),
+ ("0.17.0", None),
+ ("0.18.0+rocm7.2", None),
+ ("1.0.0", None),
+ (None, None),
+ ],
+)
+def test_torchao_export_loadable_needs_015_on_every_platform(monkeypatch, installed, too_old):
+ """transformers 5 refuses torchao < 0.15 with "requires torchao to be installed"."""
+ import importlib.metadata as md
+
+ def version(name):
+ if installed is None:
+ raise md.PackageNotFoundError(name)
+ return installed
+
+ monkeypatch.setattr(_stub, "_is_windows_rocm", lambda: False)
+ monkeypatch.setattr(_stub, "_transformers_torchao_min", lambda: "0.15.0")
+ monkeypatch.setattr(_stub.importlib.metadata, "version", version)
+ saved = {n: m for n, m in sys.modules.items() if n == "torchao" or n.startswith("torchao.")}
+ for name in saved:
+ monkeypatch.delitem(sys.modules, name)
+ assert _stub.torchao_export_loadable() is (too_old is None)
+ # metadata only: never imports torchao.
+ assert "torchao" not in sys.modules
+ assert _stub.torchao_too_old_for_export() == too_old
+
+
[email protected]("floor", ["0.4.0", None])
+def test_torchao_014_stays_exportable_where_transformers_accepts_it(monkeypatch, floor):
+ """transformers 4.57.6 (the Python 3.9 pin, torch 2.4 / 2.5 keep torchao 0.14) has a 0.4 floor;
+ an unreadable floor never hides the formats either."""
+ monkeypatch.setattr(_stub, "_is_windows_rocm", lambda: False)
+ monkeypatch.setattr(_stub, "_transformers_torchao_min", lambda: floor)
+ monkeypatch.setattr(_stub.importlib.metadata, "version", lambda name: "0.14.0")
+ assert _stub.torchao_too_old_for_export() is None
+ assert _stub.torchao_export_loadable() is True
+
+
+ ("source", "expected"),
+ [
+ ('TORCHAO_MIN_VERSION = "0.15.0"\n', "0.15.0"),
+ ("x = 1\nTORCHAO_MIN_VERSION = '0.4.0'\n", "0.4.0"),
+ ("x = 1\n", None),
+ ],
+)
+def test_transformers_torchao_min_read_without_import(monkeypatch, tmp_path, source, expected):
+ pkg = tmp_path / "transformers"
+ (pkg / "utils").mkdir(parents = True)
+ (pkg / "__init__.py").write_text("raise RuntimeError('must not be imported')\n")
+ (pkg / "utils" / "import_utils.py").write_text(source)
+ for name in [n for n in sys.modules if n == "transformers" or n.startswith("transformers.")]:
+ monkeypatch.delitem(sys.modules, name)
+ monkeypatch.syspath_prepend(str(tmp_path))
+ assert _stub._transformers_torchao_min() == expected
+ assert "transformers" not in sys.modules
+
+
[email protected]("alias", ["torchao_fp8", "portable_int8"])
+def test_torchao_export_rejected_early_when_torchao_is_too_old(monkeypatch, alias):
+ mod = _load_export_module_no_torch(monkeypatch)
+ monkeypatch.setattr(mod, "_export_runtime_available", lambda: True)
+ monkeypatch.setattr(_stub, "_is_windows_rocm", lambda: False)
+ monkeypatch.setattr(_stub, "_transformers_torchao_min", lambda: "0.15.0")
+ monkeypatch.setattr(_stub.importlib.metadata, "version", lambda name: "0.14.0")
+ _set_torchao(monkeypatch, "real")
+ _install_fake_unsloth_save(monkeypatch, has_method = True)
+
+ ok, message, out = _bare_backend(mod).export_merged_model("/tmp/x", compressed_method = alias)
+ assert ok is False and out is None
+ assert "0.15" in message and "0.14.0" in message
+
+
+def test_too_old_torchao_does_not_block_other_formats(monkeypatch):
+ mod = _load_export_module_no_torch(monkeypatch)
+ monkeypatch.setattr(mod, "_export_runtime_available", lambda: True)
+ monkeypatch.setattr(_stub, "_is_windows_rocm", lambda: False)
+ monkeypatch.setattr(_stub, "_transformers_torchao_min", lambda: "0.15.0")
+ monkeypatch.setattr(_stub.importlib.metadata, "version", lambda name: "0.14.0")
+ _install_fake_unsloth_save(monkeypatch, has_method = True)
+
+ ok, message, _ = _bare_backend(mod).export_merged_model("/tmp/x", compressed_method = None)
+ assert "0.15" not in (message or "")
+
+
def test_torchao_export_loadable_ignores_the_stub(monkeypatch):
# The main process has already stubbed torchao; only an installed torchao counts.
monkeypatch.setattr(_stub, "_is_windows_rocm", lambda: True)
@@ -589,7 +739,13 @@ def test_torchao_export_loadable_ignores_the_stub(monkeypatch):
@pytest.mark.parametrize(
("installed", "expect"),
- [("0.14.0", False), ("0.15.0", True), ("0.17.0", True), ("0.18.0+rocm", True)],
+ [
+ ("0.14.0", False),
+ ("0.15.0rc1", False),
+ ("0.15.0", True),
+ ("0.17.0", True),
+ ("0.18.0+rocm", True),
+ ],
)
def test_torchao_export_loadable_needs_transformers_minimum(
monkeypatch, tmp_path, installed, expect
@@ -678,7 +834,7 @@ def test_real_or_stub_replaces_a_stub_inherited_from_run_py(monkeypatch, consume
def test_real_or_stub_keeps_the_stub_when_torchao_is_not_loadable(monkeypatch):
- """torch <= 2.8 pairs with torchao 0.14, which transformers 5 rejects; never load it."""
+ """an install still on torchao 0.14 (transformers 5 rejects it) never loads it."""
monkeypatch.setattr(_stub, "_is_windows_rocm", lambda: True)
monkeypatch.setattr(_stub, "torchao_export_loadable", lambda: False)
monkeypatch.delitem(sys.modules, "torchao", raising = False)
diff --git a/studio/backend/utils/hardware/hardware.py b/studio/backend/utils/hardware/hardware.py
index 0aac8073f8a..168abe0fb5d 100644
--- a/studio/backend/utils/hardware/hardware.py
+++ b/studio/backend/utils/hardware/hardware.py
@@ -1800,16 +1800,17 @@ def _gpu_present_but_unusable_message(
def export_capability() -> dict:
- """Whether model export can run here, with a torch-aware reason when it cannot. Export runs through Unsloth, which hard-requires an accelerator (it calls ``torch.cuda`` at import and has no CPU path), so it is supported iff ``get_device() in {CUDA, XPU, MLX}``. The reason distinguishes a --no-torch install from a bare-CPU host. Safe to call without torch. Returns {export_supported, export_unsupported_reason, export_unsupported_message, torchao_export_supported}; the last is False only on Windows ROCm without a loadable torchao, where the portable FP8/INT8 formats are hidden."""
+ """Whether model export can run here, with a torch-aware reason when it cannot. Export runs through Unsloth, which hard-requires an accelerator (it calls ``torch.cuda`` at import and has no CPU path), so it is supported iff ``get_device() in {CUDA, XPU, MLX}``. The reason distinguishes a --no-torch install from a bare-CPU host. Safe to call without torch. Returns {export_supported, export_unsupported_reason, export_unsupported_message, torchao_export_supported}; the last is False where the installed torchao is below 0.15 (transformers refuses it) or, on Windows ROCm, not loadable; the portable FP8/INT8 formats are then hidden."""
device = get_device()
- torchao_export_supported = True
# get_device() ran detect_hardware(), so IS_ROCM (hip field OR "rocm" tag) is settled.
- if sys.platform == "win32" and IS_ROCM:
- try:
- from core._torchao_stub import torchao_export_loadable
- torchao_export_supported = torchao_export_loadable()
- except Exception:
- torchao_export_supported = False
+ _windows_rocm = sys.platform == "win32" and IS_ROCM
+ try:
+ # Metadata only: a torchao below 0.15 (older torch <= 2.8 installs) hides the formats
+ # everywhere, since transformers' TorchAoConfig refuses it.
+ from core._torchao_stub import torchao_export_loadable
+ torchao_export_supported = torchao_export_loadable()
+ except Exception:
+ torchao_export_supported = not _windows_rocm
if device in (DeviceType.CUDA, DeviceType.XPU, DeviceType.MLX):
return {
"export_supported": True,
diff --git a/studio/frontend/src/features/export/export-page.tsx b/studio/frontend/src/features/export/export-page.tsx
index 081ed7ab05b..ae75b1c8ac8 100644
--- a/studio/frontend/src/features/export/export-page.tsx
+++ b/studio/frontend/src/features/export/export-page.tsx
@@ -1681,8 +1681,8 @@ export function ExportPage() {
{torchaoUnavailable && (
<div className="text-ui-11 text-muted-foreground">
- Portable FP8/INT8 (torchao) export needs torchao, which
- is not installed here. Update Unsloth, or use
+ Portable FP8/INT8 (torchao) export needs torchao 0.15 or
+ newer, which is not installed here. Update Unsloth, or use
16-bit or GGUF.
</div>
)}
diff --git a/studio/install_python_stack.py b/studio/install_python_stack.py
index 1d38ec5ab03..2318bdf623e 100644
--- a/studio/install_python_stack.py
+++ b/studio/install_python_stack.py
@@ -772,9 +772,12 @@ class _FreezeNewTorchForCoreUpdate:
# torchao cpp extensions match one torch and CUDA release; mismatches disable kernels or crash.
-# torch 2.9 needs 0.15 because 0.14 breaks supported Diffusers and Transformers (#13244).
+# torch 2.6-2.9 gets 0.15: transformers 5 and diffusers 0.41 refuse TorchAoConfig below 0.15 (#13244),
+# and 0.14 never loads its cpp extensions on torch 2.6-2.8 anyway, so the older pin bought nothing.
+# torchao 0.15 dropped torch <= 2.5, so those keep 0.14.
# use the resident accelerator index because PyPI follows the latest PyTorch CUDA major.
-_TORCHAO_DEFAULT_SPEC = "torchao==0.14.0"
+_TORCHAO_DEFAULT_SPEC = "torchao==0.15.0"
+_TORCHAO_TORCH_25_SPEC = "torchao==0.14.0"
_TORCHAO_TORCH_29_SPEC = "torchao==0.15.0"
_TORCHAO_TORCH_210_SPEC = "torchao==0.16.0"
_TORCHAO_TORCH_210_CUDA13_SPEC = "torchao==0.17.0"
@@ -821,6 +824,8 @@ def _select_torchao_spec(torch_version: str | None) -> str:
return _TORCHAO_TORCH_210_SPEC
if minor == 9:
return _TORCHAO_TORCH_29_SPEC
+ if minor <= 5:
+ return _TORCHAO_TORCH_25_SPEC
return _TORCHAO_DEFAULT_SPEC