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: compose the FP8 and NVFP4 compile cache tags in a fixed order (#15692)
Daniel Hand513620286a5
diff --git a/studio/backend/core/inference/diffusion_compile_config.py b/studio/backend/core/inference/diffusion_compile_config.pyindex f801955ecd6..701ba603d6c 100644--- a/studio/backend/core/inference/diffusion_compile_config.py+++ b/studio/backend/core/inference/diffusion_compile_config.py@@ -138,3 +138,16 @@ def _reset_for_tests() -> None:with _LOCK:_KNOBS.clear()_generation += 1+++_STUDIO_CACHE_TAG_PREFIXES = ("unsloth_fp8_unit_scale=", "unsloth_nvfp4_act_quant=")+++def canonical_compile_cache_tag(current: str, prefix: str, tag: str | None) -> str:+ """``prefix``'s token set to ``tag`` (None drops it); Studio's sorted so setter order never changes torch's cache key."""+ parts = [p for p in current.split(";") if p and not p.startswith(prefix)]+ if tag:+ parts.append(prefix + tag)+ foreign = [p for p in parts if not p.startswith(_STUDIO_CACHE_TAG_PREFIXES)]+ owned = sorted(p for p in parts if p.startswith(_STUDIO_CACHE_TAG_PREFIXES))+ return ";".join(foreign + owned)diff --git a/studio/backend/core/inference/diffusion_fp8_unit_scale.py b/studio/backend/core/inference/diffusion_fp8_unit_scale.pyindex 0b2c552198a..4c1381f9c9e 100644--- a/studio/backend/core/inference/diffusion_fp8_unit_scale.py+++ b/studio/backend/core/inference/diffusion_fp8_unit_scale.py@@ -61,11 +61,10 @@ def _set_compile_cache_tag(tag: Optional[str]) -> None:current = getattr(_cc, "cache_key_tag", None)if not isinstance(current, str):return- parts = [p for p in current.split(";") if p and not p.startswith(_CACHE_TAG_PREFIX)]- if tag:- parts.append(_CACHE_TAG_PREFIX + tag)+ from .diffusion_compile_config import canonical_compile_cache_tag+try:- _cc.cache_key_tag = ";".join(parts)+ _cc.cache_key_tag = canonical_compile_cache_tag(current, _CACHE_TAG_PREFIX, tag)except Exception: # noqa: BLE001passdiff --git a/studio/backend/core/inference/diffusion_nvfp4_act_quant.py b/studio/backend/core/inference/diffusion_nvfp4_act_quant.pyindex 102c068a686..fe9e462ff67 100644--- a/studio/backend/core/inference/diffusion_nvfp4_act_quant.py+++ b/studio/backend/core/inference/diffusion_nvfp4_act_quant.py@@ -128,11 +128,10 @@ def _set_compile_cache_tag(tag: str | None) -> None:current = getattr(_cc, "cache_key_tag", None)if not isinstance(current, str):return- parts = [p for p in current.split(";") if p and not p.startswith(_CACHE_TAG_PREFIX)]- if tag:- parts.append(_CACHE_TAG_PREFIX + tag)+ from .diffusion_compile_config import canonical_compile_cache_tag+try:- _cc.cache_key_tag = ";".join(parts)+ _cc.cache_key_tag = canonical_compile_cache_tag(current, _CACHE_TAG_PREFIX, tag)except Exception: # noqa: BLE001passdiff --git a/studio/backend/tests/test_diffusion_cache_tag_order.py b/studio/backend/tests/test_diffusion_cache_tag_order.pynew file mode 100644index 00000000000..55581db554d--- /dev/null+++ b/studio/backend/tests/test_diffusion_cache_tag_order.py@@ -0,0 +1,57 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""FP8 + NVFP4 cache tags compose to one string whatever order they were set in (torch keys its caches on it)."""++from __future__ import annotations++import pytest++pytest.importorskip("torch")+import torch.compiler.config as cc # noqa: E402++from core.inference import diffusion_fp8_unit_scale as fp8 # noqa: E402+from core.inference import diffusion_nvfp4_act_quant as nvfp4 # noqa: E402++[email protected](autouse = True)+def _restore_tag():+ saved = cc.cache_key_tag+ yield+ cc.cache_key_tag = saved+++def _apply(steps, start = ""):+ cc.cache_key_tag = start+ for step in steps:+ step()+ return cc.cache_key_tag+++FP8 = lambda: fp8._set_compile_cache_tag("256") # noqa: E731+NVFP4_ON = lambda: nvfp4._set_compile_cache_tag(nvfp4._TAG_ON) # noqa: E731+++def test_setter_order_does_not_change_the_tag():+ assert _apply([FP8, NVFP4_ON]) == _apply([NVFP4_ON, FP8])+++def test_setting_again_does_not_change_the_tag():+ once = _apply([FP8, NVFP4_ON])+ assert _apply([FP8, NVFP4_ON, FP8]) == once+ assert _apply([FP8, NVFP4_ON, NVFP4_ON, FP8, NVFP4_ON]) == once+++def test_values_and_removal_still_count():+ on = _apply([FP8, NVFP4_ON])+ off = _apply([FP8, lambda: nvfp4._set_compile_cache_tag(nvfp4._TAG_OFF)])+ other_rows = _apply([lambda: fp8._set_compile_cache_tag("512"), NVFP4_ON])+ assert len({on, off, other_rows}) == 3+ removed = _apply([FP8, NVFP4_ON, lambda: fp8._set_compile_cache_tag(None)])+ assert "unsloth_fp8_unit_scale=" not in removed and "unsloth_nvfp4_act_quant=1" in removed+++def test_foreign_tokens_are_kept_in_place():+ tag = _apply([NVFP4_ON, FP8], start = "user_tag;other=2")+ assert tag.split(";")[:2] == ["user_tag", "other=2"]+ assert tag == _apply([FP8, NVFP4_ON], start = "user_tag;other=2")