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 video: fall back to the tiled VAE decode when the Linux / macOS CPU allocator refuses (#17075)
Daniel Haned670cce273d
diff --git a/studio/backend/core/inference/video_vae_untiled.py b/studio/backend/core/inference/video_vae_untiled.pyindex a94eef1aefa..fda7120ee6d 100644--- a/studio/backend/core/inference/video_vae_untiled.py+++ b/studio/backend/core/inference/video_vae_untiled.py@@ -175,10 +175,24 @@ def _free_bytes(device: Any) -> Optional[int]:return None+# torch's CPU allocator refusals: ``not enough memory`` (Windows commit limit), ``can't allocate memory`` (POSIX ENOMEM).+_CPU_ALLOC_REFUSALS = ("not enough memory", "can't allocate memory")++def _is_oom(exc: BaseException) -> bool:- """A device OOM, or the CPU allocator's ``not enough memory`` (raised e.g. on Windows commit limits)."""from .diffusion_batched import is_oom_error- return is_oom_error(exc) or "not enough memory" in str(exc).lower()++ if is_oom_error(exc):+ return True+ seen = set()+ cur: Optional[BaseException] = exc+ while cur is not None and id(cur) not in seen:+ seen.add(id(cur))+ msg = str(cur).lower()+ if any(s in msg for s in _CPU_ALLOC_REFUSALS):+ return True+ cur = cur.__cause__ or cur.__context__+ return Falsedef _in_chain(fn: Any, target: Any) -> bool:diff --git a/studio/backend/tests/test_video_ltx2_vae_tiles.py b/studio/backend/tests/test_video_ltx2_vae_tiles.pyindex 99ea4b05a89..7baddf843a7 100644--- a/studio/backend/tests/test_video_ltx2_vae_tiles.py+++ b/studio/backend/tests/test_video_ltx2_vae_tiles.py@@ -140,8 +140,13 @@ def test_temb_and_causal_reach_every_tile(free):"[enforce fail at alloc_cpu.cpp:117] data. DefaultCPUAllocator: not enough memory: ""you tried to allocate 123 bytes."),+ # Linux / macOS: posix_memalign's ENOMEM+ lambda: RuntimeError(+ "[enforce fail at alloc_cpu.cpp:127] err == 0. DefaultCPUAllocator: can't allocate memory: "+ "you tried to allocate 123 bytes. Error code 12 (Cannot allocate memory)"+ ),],- ids = ["cuda", "cpu_allocator"],+ ids = ["cuda", "cpu_allocator", "posix_allocator"],)def test_oom_retries_in_stock_size_tiles(free, monkeypatch, error):vae = _ltx_vae()diff --git a/studio/backend/tests/test_video_vae_untiled.py b/studio/backend/tests/test_video_vae_untiled.pyindex a96ce406539..34c0b4306ec 100644--- a/studio/backend/tests/test_video_vae_untiled.py+++ b/studio/backend/tests/test_video_vae_untiled.py@@ -242,6 +242,60 @@ def test_cpu_allocator_refusal_falls_back_to_tiled(monkeypatch):assert vae.use_tiling is True+ "err",+ [+ RuntimeError(+ "[enforce fail at alloc_cpu.cpp:127] err == 0. DefaultCPUAllocator: can't allocate memory: you tried to "+ "allocate 9663676416 bytes. Error code 12 (Cannot allocate memory)"+ ),+ RuntimeError("decode failed"),+ ],+ ids = ["posix_enomem", "wrapped"],+)+def test_posix_cpu_allocator_refusal_falls_back_to_tiled(monkeypatch, err):+ if str(err) == "decode failed":+ err.__cause__ = RuntimeError(+ "DefaultCPUAllocator: can't allocate memory: you tried to allocate 1 bytes."+ )+ monkeypatch.setattr(U, "_free_bytes", lambda device: 100 * 2**30)+ vae = FakeVAE(error = err)+ U.install_untiled_decode(_pipe(vae), WAN)+ assert vae.decode(Z) == ("tiled",)+ assert vae.calls == [False, True]+ assert vae.use_tiling is True+++class _RefusingVAE(FakeVAE):+ def decode(+ self,+ z,+ return_dict = False,+ ):+ self.calls.append(self.use_tiling)+ if not self.use_tiling:+ torch.empty(+ 2**60, dtype = torch.uint8+ ) # past any address space: the real allocator refuses+ return ("tiled",)+++def test_real_cpu_allocator_refusal_falls_back_to_tiled(monkeypatch):+ monkeypatch.setattr(U, "_free_bytes", lambda device: 100 * 2**30)+ vae = _RefusingVAE()+ U.install_untiled_decode(_pipe(vae), WAN)+ assert vae.decode(Z) == ("tiled",)+ assert vae.calls == [False, True]+++def test_unrelated_runtime_error_still_raises(monkeypatch):+ monkeypatch.setattr(U, "_free_bytes", lambda device: 100 * 2**30)+ vae = FakeVAE(error = RuntimeError("shape mismatch"))+ U.install_untiled_decode(_pipe(vae), WAN)+ with pytest.raises(RuntimeError, match = "shape mismatch"):+ vae.decode(Z)++class CpuOffload:def __init__(self,