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 MiniMax-H3: keep the whole denoiser forward compilable with the render text cache (follow-up to #17203) (#17226)
Daniel Han83fd83f68dbc
diff --git a/studio/backend/core/inference/video_minimax_h3_forward.py b/studio/backend/core/inference/video_minimax_h3_forward.pyindex ee778071f99..cbd46dcedc1 100644--- a/studio/backend/core/inference/video_minimax_h3_forward.py+++ b/studio/backend/core/inference/video_minimax_h3_forward.py@@ -7,6 +7,8 @@inference tensor has no version counter, so an in-place edit inside a render is not seen(``UNSLOTH_H3_REFINER_CACHE=0`` disables).* the packed sequence filled in place with ``index_copy_`` (``UNSLOTH_H3_INPLACE_PACK=0`` disables).++Under a whole-forward ``torch.compile`` the stock forward runs (regional compile keeps this forward eager)."""from __future__ import annotations@@ -58,6 +60,12 @@ def _forward_sha(cls: type) -> Optional[str]:return sha+def _compiling() -> bool:+ import torch+ is_compiling = getattr(getattr(torch, "compiler", None), "is_compiling", None)+ return bool(is_compiling is not None and is_compiling())++def _stats(module: Any) -> dict:stats = module.__dict__.get(STATS_ATTR)if stats is None:@@ -215,9 +223,14 @@ def _forward() -> Any:import torch- use_cache = self.__dict__.get(_SCOPE_ATTR) is not None and refiner_cache_enabled()extra = {}- if torch.is_grad_enabled() or not (use_cache or inplace_pack_enabled()):+ if _compiling():+ # cache key (is_inference, data_ptr) and stats counters cause graph breaks / recompiles when traced+ fn = type(self).forward+ elif torch.is_grad_enabled() or not (+ (self.__dict__.get(_SCOPE_ATTR) is not None and refiner_cache_enabled())+ or inplace_pack_enabled()+ ):_stats(self)["stock"] += 1fn = type(self).forwardelse:diff --git a/studio/backend/tests/test_h3_forward.py b/studio/backend/tests/test_h3_forward.pyindex 11d1a9ba50f..73648c286f9 100644--- a/studio/backend/tests/test_h3_forward.py+++ b/studio/backend/tests/test_h3_forward.py@@ -311,6 +311,52 @@ def test_regional_compile_adds_no_graphs(monkeypatch):assert patched <= stock+def _two_renders(model, fn):+ outs = []+ layout = _layout()+ for seed in (3, 4):+ enc = _enc(seed)+ with torch.no_grad(), h3f.h3_render_scope(_Pipe(model)):+ for i in range(3):+ outs.append(fn(**_step_inputs(i, enc), **layout))+ return outs+++@needs_mirror+def test_regional_compile_still_uses_the_text_cache(monkeypatch):+ monkeypatch.delenv(h3f.REFINER_CACHE_ENV, raising = False)+ monkeypatch.delenv(h3f.INPLACE_PACK_ENV, raising = False)+ stock = _two_renders(_model(), _model())+ torch._dynamo.reset()+ m = _model()+ h3f.install_h3_forward(m)+ m.compile_repeated_blocks(backend = "eager", fullgraph = True, dynamic = False)+ _assert_same(stock, _two_renders(m, m))+ stats = m.__dict__[h3f.STATS_ATTR]+ assert stats["text_misses"] == 2 and stats["text_hits"] == 4 and stats["inplace_packs"] == 6+++@needs_mirror[email protected]("fullgraph", [True, False])+def test_whole_forward_compile_one_graph_across_renders(monkeypatch, fullgraph):+ from torch._dynamo.testing import CompileCounter+ from torch._dynamo.utils import counters++ monkeypatch.delenv(h3f.REFINER_CACHE_ENV, raising = False)+ monkeypatch.delenv(h3f.INPLACE_PACK_ENV, raising = False)+ stock = _two_renders(_model(), _model())+ torch._dynamo.reset()+ counters.clear()+ m = _model()+ assert h3f.install_h3_forward(m) is True+ cnt = CompileCounter()+ compiled = torch.compile(m, backend = cnt, fullgraph = fullgraph, dynamic = False)+ _assert_same(stock, _two_renders(m, compiled))+ assert cnt.frame_count == 1+ assert sum(counters["graph_break"].values()) == 0+ torch._dynamo.reset()++@needs_mirrordef test_lora_scale_is_part_of_the_key(monkeypatch):monkeypatch.delenv(h3f.REFINER_CACHE_ENV, raising = False)