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 diffusion: VAE OOM under a component split, expanded timesteps in the CFG routers, and test fixes (#14420)
Daniel Hanbfaed19a3474
diff --git a/studio/backend/core/inference/diffusion_memory.py b/studio/backend/core/inference/diffusion_memory.pyindex f38e17dc6a1..54d092e751a 100644--- a/studio/backend/core/inference/diffusion_memory.py+++ b/studio/backend/core/inference/diffusion_memory.py@@ -1164,6 +1164,7 @@ def _rocm_linux_apu_os_room_outside_pool(memory: DeviceMemory) -> bool:free, #7072); unknown readings answer False."""if (memory.memory_kind != "unified_memory"+ or str(getattr(memory, "device", None) or "").split(":")[0] != "cuda"or not sys.platform.startswith("linux")or memory.free_mib is None):@@ -3404,11 +3405,13 @@ def release_resident_groups(logger: Any = None,denoisers_only: bool = False,reason: str = "an oversized request",+ device: Any = None,) -> Optional[Callable[[], None]]:"""Stream resident offload groups again until ``need_mib`` is freed (text encoders first, then the denoiser'sblocks from the last); returns a callable pinning exactly those groups again, or None when nothing was resident.A request larger than the measured placement reserved (reference images, a bigger canvas, a batch) then runs as- the flat plan. ``denoisers_only`` leaves the text encoders' groups alone (the prompt encode needs them)."""+ the flat plan. ``denoisers_only`` leaves the text encoders' groups alone (the prompt encode needs them).+ ``device``: only modules resident on that card."""released: list = []streamed: set = set()@@ -3443,6 +3446,13 @@ def release_resident_groups(if getattr(m, "_unsloth_resident_room", None)and not (denoisers_only and _is_text_encoder_module(pipe, m))]+ if device is not None:+ from .diffusion_vae_oom import _same_card+ modules = [+ m+ for m in modules+ if _same_card(getattr(m, "_unsloth_resident_device", None) or device, device)+ ]if not modules or int(need_mib) <= 0:return Nonemodules.sort(key = lambda m: 0 if _is_text_encoder_module(pipe, m) else 1)diff --git a/studio/backend/core/inference/diffusion_multigpu.py b/studio/backend/core/inference/diffusion_multigpu.pyindex 81af0ca2b12..1f5d12dcfa9 100644--- a/studio/backend/core/inference/diffusion_multigpu.py+++ b/studio/backend/core/inference/diffusion_multigpu.py@@ -1420,6 +1420,15 @@ def _rebuild(_SMALL_TENSOR_NUMEL = 4096+def _as_bytes(t: Any) -> Any:+ """Flat uint8 view; a one-element ``t.expand(n)`` keeps stride 0 through ``contiguous()``, so copy it."""+ torch = _torch()+ flat = t.reshape(-1).contiguous()+ if flat.numel() and flat.stride(0) != 1:+ flat = flat.clone(memory_format = torch.contiguous_format)+ return flat.view(torch.uint8)++def _bitwise_equal(a: Any, b: Any) -> bool:torch = _torch()if not (isinstance(a, torch.Tensor) and isinstance(b, torch.Tensor)):@@ -1429,12 +1438,7 @@ def _bitwise_equal(a: Any, b: Any) -> bool:if a is b:return Truetry:- return bool(- torch.equal(- a.reshape(-1).contiguous().view(torch.uint8),- b.reshape(-1).contiguous().view(torch.uint8),- )- )+ return bool(torch.equal(_as_bytes(a), _as_bytes(b)))except Exception: # noqa: BLE001 - a layout that cannot be viewed as bytes is never assumed equalreturn False@@ -1451,11 +1455,11 @@ def _unchanged_since_launch(snapshots: list) -> bool:if src.numel() == 0:continuetry:- now = src.to(snap.device).reshape(-1).contiguous().view(torch.uint8)+ now = _as_bytes(src.to(snap.device))checks.append(- torch.equal(now, snap.reshape(-1).contiguous().view(torch.uint8))+ torch.equal(now, _as_bytes(snap))if snap.device.type == "cpu"- else (now == snap.reshape(-1).contiguous().view(torch.uint8)).all()+ else (now == _as_bytes(snap)).all())except Exception: # noqa: BLE001 - an unverifiable tensor never accepts a predictionreturn Falsediff --git a/studio/backend/core/inference/diffusion_vae_oom.py b/studio/backend/core/inference/diffusion_vae_oom.pyindex 3326b539e29..e8b5ec9702c 100644--- a/studio/backend/core/inference/diffusion_vae_oom.py+++ b/studio/backend/core/inference/diffusion_vae_oom.py@@ -177,6 +177,53 @@ def _whole_on(module: Any, device: Any) -> bool:return bool(tensors) and all(t.device == device for t in tensors)+def _same_card(a: Any, b: Any) -> bool:+ """Unreadable devices count as the same card; index-less ``cuda`` is the current card."""+ try:+ import torch+ da, db = torch.device(a), torch.device(b)+ except Exception: # noqa: BLE001+ return True+ if da.type != db.type:+ return False+ if da.index == db.index:+ return True+ if da.index is not None and db.index is not None:+ return False+ try:+ current = int(torch.cuda.current_device()) if da.type == "cuda" else 0+ except Exception: # noqa: BLE001+ return True+ return (current if da.index is None else da.index) == (+ current if db.index is None else db.index+ )+++def _graph_on(handle: Any, device: Any) -> bool:+ """Graph handle lives on ``device`` (capture card, else module card; unknown: True)."""+ cards = {+ c+ for h in (+ handle,+ getattr(handle, "fallback_handle", None),+ *(getattr(handle, "graphs", None) or ()),+ )+ if h is not None+ for c in (getattr(h, "_unsloth_capture_device", None),)+ if isinstance(c, int)+ }+ if cards:+ return any(_same_card(f"cuda:{c}", device) for c in cards)+ module = getattr(handle, "module", None)+ try:+ cuda = {t.device for t in _module_tensors(module) if t.device.type == "cuda"}+ except Exception: # noqa: BLE001+ cuda = set()+ if cuda:+ return any(_same_card(d, device) for d in cuda)+ return True++def _nbytes(module: Any) -> int:seen: set = set()total = 0@@ -453,7 +500,11 @@ class DecodeSession:# Captured graphs pin their pool and the weights' addresses: drop them before any weight moves (the image and# video backends drop them on any OOM too). Nothing to undo: the next step re-captures. If dropping them# fails, no weight may move under a graph that could still replay: step (a) stops here.- graphs = getattr(pipe, "_unsloth_cuda_graphs", ()) or ()+ graphs = tuple(+ h+ for h in (getattr(pipe, "_unsloth_cuda_graphs", ()) or ())+ if _graph_on(h, self.device)+ )if graphs:def reset() -> None:@@ -520,16 +571,21 @@ class DecodeSession:from . import diffusion_memorygot: list = []- anchor = next(- (m for m in (getattr(pipe, "components", {}) or {}).values() if getattr(m, "_unsloth_resident_room", None)),- None,- ) # fmt: skip+ resident = [+ m for m in (getattr(pipe, "components", {}) or {}).values() if getattr(m, "_unsloth_resident_room", None)+ ] # fmt: skip+ # Only groups on the VAE's card free memory for its decode (component split).+ local = [+ m for m in resident if _same_card(getattr(m, "_unsloth_resident_device", None) or self.device, self.device)+ ] # fmt: skip+ anchor = local[0] if local else Noneif anchor is None:return 0+ on_card = {} if len(local) == len(resident) else {"device": self.device}def do() -> None:restore = diffusion_memory.release_resident_groups(- pipe, 1 << 30, self.logger, reason = "a VAE decode that ran out of memory"+ pipe, 1 << 30, self.logger, reason = "a VAE decode that ran out of memory", **on_card)if restore is not None:got.append(restore)@@ -543,7 +599,7 @@ class DecodeSession:def settle() -> None:restore = diffusion_memory.release_resident_groups(- pipe, 1 << 30, self.logger, reason = "a failed re-pin"+ pipe, 1 << 30, self.logger, reason = "a failed re-pin", **on_card)if restore is not None:got.append(restore)diff --git a/studio/backend/tests/test_diffusion_cfg_batch.py b/studio/backend/tests/test_diffusion_cfg_batch.pyindex 3761f2cfd8f..c13374ecaa5 100644--- a/studio/backend/tests/test_diffusion_cfg_batch.py+++ b/studio/backend/tests/test_diffusion_cfg_batch.py@@ -159,6 +159,29 @@ def test_batched_steps_match_two_calls_and_engage(monkeypatch):assert cb.cfg_batch_status(pipe)["shape_off"] is None+def test_wan_expanded_timesteps_serve_the_second_branch(monkeypatch):+ """WanPipeline's stride-0 ``t.expand(batch)`` timestep must compare equal, not disable batching."""++ def loop(model):+ torch.manual_seed(0)+ latents = torch.randn(1, 4, 8)+ pos, neg = torch.randn(1, 5, 8), torch.randn(1, 5, 8)+ txt_ids, img_ids = torch.zeros(1, 5, 4), torch.ones(1, 4, 4)+ for t in torch.tensor([999, 941, 883, 825, 767, 709]):+ branch = {"txt_ids": txt_ids, "img_ids": img_ids, "return_dict": False}+ c = model(hidden_states = latents, timestep = t.expand(latents.shape[0]), encoder_hidden_states = pos, **branch)[0] # fmt: skip+ u = model(hidden_states = latents, timestep = t.expand(latents.shape[0]), encoder_hidden_states = neg, **branch)[0] # fmt: skip+ latents = latents - 0.1 * (u + 4.0 * (c - u))+ return latents++ ref = loop(_offloaded(Flux2Transformer2DModel()))+ model = Flux2Transformer2DModel()+ _pipe, router = _armed(model, monkeypatch)+ torch.testing.assert_close(loop(model), ref)+ assert router.stats["hits"] == 4 and router.stats["misses"] == 0, router.describe()+ assert router.shape.off is None++def test_qwen_unequal_prompt_lengths_and_img_shapes_batch(monkeypatch):def loop(model):torch.manual_seed(1)diff --git a/studio/backend/tests/test_diffusion_fbcache_mixed_stream.py b/studio/backend/tests/test_diffusion_fbcache_mixed_stream.pyindex 23c1bad451d..c34d1227236 100644--- a/studio/backend/tests/test_diffusion_fbcache_mixed_stream.py+++ b/studio/backend/tests/test_diffusion_fbcache_mixed_stream.py@@ -132,6 +132,8 @@ def _render(torch, FirstBlockCacheConfig, *_ = _diffusers()if threshold is not None:model.enable_cache(FirstBlockCacheConfig(threshold = threshold))+ # diffusers 0.39/0.40 cache the child-registry list across renders, as apply_step_cache does+ dc._invalidate_child_registry_cache(model)tail_attn = model.single_transformer_blocks[-1].attncalls = []handle = tail_attn.register_forward_hook(lambda *_: calls.append(1))diff --git a/studio/backend/tests/test_diffusion_fp8_unit_scale.py b/studio/backend/tests/test_diffusion_fp8_unit_scale.pyindex 0b88aca1f4c..e5a9d52355a 100644--- a/studio/backend/tests/test_diffusion_fp8_unit_scale.py+++ b/studio/backend/tests/test_diffusion_fp8_unit_scale.py@@ -319,6 +319,9 @@ print(json.dumps({"installed": installed, "calls": len(calls), "unit": all(a ==def _fp8_gpu() -> bool:try:+ # ROCm capability is a gfx version, and Studio never runs torchao fp8 on ROCm.+ if getattr(torch.version, "hip", None):+ return Falsereturn torch.cuda.is_available() and torch.cuda.get_device_capability() >= (8, 9)except Exception: # noqa: BLE001return Falsediff --git a/studio/backend/tests/test_diffusion_memory_rocm_apu_reserve.py b/studio/backend/tests/test_diffusion_memory_rocm_apu_reserve.pyindex fc96c17b5ac..6f8dba834e4 100644--- a/studio/backend/tests/test_diffusion_memory_rocm_apu_reserve.py+++ b/studio/backend/tests/test_diffusion_memory_rocm_apu_reserve.py@@ -92,6 +92,14 @@ def test_unknown_host_reading_keeps_the_unified_reserve(host):assert _plan().estimates["safe_device_budget_mib"] == POOL_FREE - int(POOL_TOTAL * 0.20)[email protected]("device", ["mps", "cpu"])+def test_a_unified_snapshot_of_another_device_keeps_the_unified_reserve(host, device):+ memory = DeviceMemory(device, device, "unified_memory", POOL_FREE, POOL_TOTAL)+ assert dm._safe_device_budget_mib(memory) == POOL_FREE - int(POOL_TOTAL * 0.20)+ cuda = DeviceMemory("cuda", "cuda", "unified_memory", POOL_FREE, POOL_TOTAL)+ assert dm._safe_device_budget_mib(cuda) == POOL_FREE - int(POOL_TOTAL * 0.10)++@pytest.mark.parametrize("platform", ["win32", "darwin"])def test_other_platforms_unchanged(host, platform):host["platform"] = platformdiff --git a/studio/backend/tests/test_diffusion_multigpu.py b/studio/backend/tests/test_diffusion_multigpu.pyindex 82653c12870..1350ce93447 100644--- a/studio/backend/tests/test_diffusion_multigpu.py+++ b/studio/backend/tests/test_diffusion_multigpu.py@@ -36,6 +36,9 @@ def _from_diffusers(module: str, name: str):def _env(monkeypatch):monkeypatch.delenv(mg.MULTIGPU_ENV, raising = False)monkeypatch.delenv(mg.CFG_PARALLEL_ENV, raising = False)+ # Keep make_selection's real-host filters from collapsing fake [0, 1] selections on a one-GPU host.+ monkeypatch.setattr(torch.cuda, "device_count", lambda: 8)+ monkeypatch.setattr(mg, "_capability", lambda o: None)yield@@ -1012,6 +1015,18 @@ def test_inline_recomputed_scalars_are_predicted_by_value():assert router.stats["predicted_hits"] == 5 and router.stats["predicted_misses"] == 0+def test_bitwise_equal_on_an_expanded_scalar():+ t = torch.tensor(941).expand(1)+ assert t.stride() == (0,)+ assert mg._bitwise_equal(t, t.clone())+ assert mg._bitwise_equal(t, torch.tensor(941).expand(1))+ assert not mg._bitwise_equal(t, torch.tensor([942]))+ assert mg._bitwise_equal(torch.tensor(float("nan")).expand(1), torch.tensor([float("nan")]))+ assert not mg._bitwise_equal(torch.tensor(-0.0).expand(1), torch.tensor([0.0]))+ assert mg._unchanged_since_launch([(t, t.clone())])+ assert not mg._unchanged_since_launch([(torch.tensor(942).expand(1), t.clone())])++def test_bitwise_equal_distinguishes_signed_zero():assert mg._bitwise_equal(torch.tensor([0.0]), torch.tensor([0.0]))assert mg._bitwise_equal(torch.tensor(0.5), torch.tensor(1.0) / 2)@@ -1825,6 +1840,20 @@ def test_a_card_torch_cannot_address_is_not_a_secondary(monkeypatch):assert mg.make_selection(0, [0, 1]) == mg.MultiGpuSelection(primary = 0, secondaries = (1,))+def test_two_discrete_rocm_cards_split_like_cuda(monkeypatch):+ """2x 7900 XTX / MI300: a HIP torch with two addressable discrete cards plans the same split CUDA does."""+ monkeypatch.setattr(torch.version, "hip", "7.13.0", raising = False)+ monkeypatch.setattr(torch.cuda, "is_available", lambda: True)+ monkeypatch.setattr(torch.cuda, "device_count", lambda: 2)+ monkeypatch.setattr(mg, "_capability", lambda o: (11, 0)) # gfx1100, as ROCm reports it+ monkeypatch.setattr(mg, "secondary_resident_limit_mib", lambda o, mode: 13600)+ selection = mg.make_selection(0, [0, 1])+ assert selection == mg.MultiGpuSelection(primary = 0, secondaries = (1,))+ with mg.selection_scope(selection):+ plan = _plan()+ assert plan.offload_policy == dm.OFFLOAD_NONE and plan.secondary_ordinal == 1++def test_refinement_keeps_an_explicit_cpu_offload(monkeypatch):sizes = {"transformer": (9000, "dit"),diff --git a/studio/backend/tests/test_diffusion_vae_oom.py b/studio/backend/tests/test_diffusion_vae_oom.pyindex 476563fd140..add7366ec2f 100644--- a/studio/backend/tests/test_diffusion_vae_oom.py+++ b/studio/backend/tests/test_diffusion_vae_oom.py@@ -2641,3 +2641,99 @@ def test_split_vae_never_decodes_before_its_required_repair(monkeypatch):deferred.pending[:] = [("vae_offload", lambda: vae.conv.to(_CARD))]vae._decode(_z())assert O._DEFERRED_ATTR not in vae.__dict__ and len(vae.seen) == seen_before + 1+++class _GraphHandle:+ def __init__(self, card):+ self._unsloth_capture_device = card+ self.cache = {"k": "graph"}+++def _split_vae(monkeypatch, events):+ """A component split: the VAE decodes on cuda:1, the denoiser (and its graphs) sit on cuda:0."""+ from core.inference import diffusion_cuda_graph as G++ monkeypatch.setattr(O, "_device_of", lambda z: torch.device("cuda", 1))+ monkeypatch.setattr(+ G, "reset_all", lambda handles, strict = False: events.append(("graphs", tuple(handles)))+ )+ return _setup(cap = 4096 + 600, untiled_need = 10**9, tiled_need = 500, can_free = False)+++def test_split_vae_oom_leaves_the_other_cards_graphs_alone(monkeypatch):+ """Dropping cuda:0 graphs must not count as freed for a cuda:1 VAE OOM."""+ events = []+ vae, pipe = _split_vae(monkeypatch, events)+ pipe._unsloth_cuda_graphs = (_GraphHandle(0),)+ vae._decode(_z())+ assert events == []+ assert [s[0] for s in vae.seen] == [False, True]+ assert vae._unsloth_vae_oom_stats["recovered_by"] == "tiled"+++def test_split_vae_oom_still_drops_graphs_on_its_own_card(monkeypatch):+ events = []+ vae, pipe = _split_vae(monkeypatch, events)+ local, other = _GraphHandle(1), _GraphHandle(0)+ pipe._unsloth_cuda_graphs = (other, local)+ vae._decode(_z())+ assert events == [("graphs", (local,))]+++def test_split_vae_oom_releases_only_groups_on_its_own_card(monkeypatch):+ """Only resident groups on the VAE's card are released or deferred."""+ from core.inference import diffusion_memory as M++ calls = []++ def release(+ pipe,+ need,+ logger = None,+ reason = "",+ **kw,+ ):+ calls.append(kw)+ return lambda strict = False: None++ monkeypatch.setattr(M, "release_resident_groups", release)+ vae, pipe = _split_vae(monkeypatch, [])+ te = pipe.components["text_encoder"]+ te._unsloth_resident_room, te._unsloth_resident_device = 1, torch.device("cuda", 0)+ vae._decode(_z())+ assert calls == [] and [s[0] for s in vae.seen] == [False, True]+ assert O._DEFERRED_ATTR not in te.__dict__++ vae, pipe = _split_vae(monkeypatch, [])+ te, tr = pipe.components["text_encoder"], pipe.components["transformer"]+ te._unsloth_resident_room, te._unsloth_resident_device = 1, torch.device("cuda", 0)+ tr._unsloth_resident_room, tr._unsloth_resident_device = 1, torch.device("cuda", 1)+ vae._decode(_z())+ assert calls == [{"device": torch.device("cuda", 1)}]+++def test_release_resident_groups_device_filter(monkeypatch):+ from core.inference import diffusion_memory as M++ class G:+ _unsloth_resident = True+ _unsloth_resident_bytes = 1 << 20++ groups = {}+ released = []+ monkeypatch.setattr(M, "_offload_groups", lambda m: groups.get(id(m), []))+ monkeypatch.setattr(M, "_release_group", lambda g: released.append(g))+ monkeypatch.setattr(M, "_is_text_encoder_module", lambda pipe, m: False)+ monkeypatch.setattr(torch.cuda, "synchronize", lambda device = None: None)+ a, b = torch.nn.Linear(1, 1), torch.nn.Linear(1, 1)+ for m, card in ((a, 0), (b, 1)):+ m._unsloth_resident_room, m._unsloth_resident_device = 1, torch.device("cuda", card)+ groups[id(m)] = [G()]+ pipe = _Pipe(a = a, b = b)+ assert M.release_resident_groups(pipe, 1 << 30, device = torch.device("cuda", 1)) is not None+ assert released == groups[id(b)]+ released.clear()+ for g in (*groups[id(a)], *groups[id(b)]):+ g._unsloth_resident = True+ M.release_resident_groups(pipe, 1 << 30)+ assert len(released) == 2diff --git a/studio/backend/tests/test_flux3_prompt_upsampler.py b/studio/backend/tests/test_flux3_prompt_upsampler.pyindex 270c90e96c7..7ebb1d6eb11 100644--- a/studio/backend/tests/test_flux3_prompt_upsampler.py+++ b/studio/backend/tests/test_flux3_prompt_upsampler.py@@ -931,6 +931,7 @@ def test_the_child_is_pinned_to_the_image_models_card(monkeypatch):monkeypatch.setattr(torch.cuda, "device_count", lambda: 4)monkeypatch.setattr(torch.version, "hip", None, raising = False)+ monkeypatch.setattr(torch, "__version__", "2.11.0+cu130")monkeypatch.setenv("CUDA_VISIBLE_DEVICES", "3,5,GPU-abc")assert pup._child_device_mask(2) == {"CUDA_VISIBLE_DEVICES": "GPU-abc"}assert pup._child_device_mask(1) == {"CUDA_VISIBLE_DEVICES": "5"}@@ -1153,6 +1154,8 @@ def test_users_llama_arg_device_keeps_every_card_visible(monkeypatch, hip):monkeypatch.setattr(torch.cuda, "device_count", lambda: 2)monkeypatch.setattr(torch.version, "hip", hip, raising = False)+ # ROCm is also read from a "+rocm" __version__: pin it to the build this case names.+ monkeypatch.setattr(torch, "__version__", "2.11.0+rocm6.2" if hip else "2.11.0+cu130")monkeypatch.setenv("HIP_VISIBLE_DEVICES", "2,3")monkeypatch.setenv("CUDA_VISIBLE_DEVICES", "2,3")monkeypatch.setenv("LLAMA_ARG_DEVICE", "ROCm1" if hip else "CUDA1")@@ -1488,6 +1491,8 @@ def warmable(monkeypatch, tmp_path):monkeypatch.setattr(pup, "_take_render_slot", _take_slot)monkeypatch.setattr(pup, "_active_engine_loading", lambda: False)+ # One card: on a multi-GPU host an unpinned warm declines with "placement" (tests that need several patch it).+ monkeypatch.setattr(pup, "_cuda_device_count", lambda: 1)memory = {"free": 160 * 1024, "total": 180 * 1024, "device": "cuda"}monkeypatch.setattr(pup,@@ -2180,6 +2185,8 @@ def test_a_hip_mask_on_a_cuda_torch_never_steers_the_vulkan_pin(monkeypatch.setattr(pup, "_vulkan_rows", lambda b, retry_empty = False: calls.append(b) or [])monkeypatch.setattr(torch.cuda, "device_count", lambda: 2)monkeypatch.setattr(torch.version, "hip", hip, raising = False)+ # ROCm is also read from a "+rocm" __version__: pin it to the build this case names.+ monkeypatch.setattr(torch, "__version__", "2.11.0+rocm6.2" if hip else "2.11.0+cu130")monkeypatch.setenv("HIP_VISIBLE_DEVICES", "2,3")assert pup._vulkan_device_args("b", 0) is Noneassert bool(calls) is probeddiff --git a/studio/backend/tests/test_video_prequant.py b/studio/backend/tests/test_video_prequant.pyindex aeb64658b1b..6b1b6d3d898 100644--- a/studio/backend/tests/test_video_prequant.py+++ b/studio/backend/tests/test_video_prequant.py@@ -1741,6 +1741,8 @@ def test_the_seeded_denoiser_artifact_is_fetched_under_the_load_cancel_event(mon_load_token = 1,_cancel_event = cancel,transformer_quant = "nvfp4",+ # pinned: on a CUDA host an unset request also plans the hosted FP8 text encoder, a second fetch+ text_encoder_quant = "off",)assert [(r, f) for r, f, _ in fetched] == [diff --git a/studio/backend/tests/test_video_stream_encode.py b/studio/backend/tests/test_video_stream_encode.pyindex 982eb196410..84b00b734cf 100644--- a/studio/backend/tests/test_video_stream_encode.py+++ b/studio/backend/tests/test_video_stream_encode.py@@ -14,8 +14,12 @@ torch = pytest.importorskip("torch")av = pytest.importorskip("av")diffusers = pytest.importorskip("diffusers")-from diffusers import AutoencoderKLWan # noqa: E402-from diffusers.video_processor import VideoProcessor # noqa: E402+# Lazy diffusers imports can raise RuntimeError (broken bitsandbytes): skip, not abort collection.+try:+ from diffusers import AutoencoderKLWan # noqa: E402+ from diffusers.video_processor import VideoProcessor # noqa: E402+except (ImportError, RuntimeError) as exc:+ pytest.skip(f"diffusers is not importable here: {type(exc).__name__}", allow_module_level = True)from core.inference import video_stream_encode as vse # noqa: E402from core.inference.video_frames import uint8_video_frames # noqa: E402