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 diffusion: Automatic CFG-parallel no longer refuses an idle card over its own CUDA context (#17057)

Daniel Han49453f39a3b4
diff --git a/studio/backend/core/inference/diffusion_multigpu.py b/studio/backend/core/inference/diffusion_multigpu.py
index 21e25535d82..62b2c44acdd 100644
--- a/studio/backend/core/inference/diffusion_multigpu.py
+++ b/studio/backend/core/inference/diffusion_multigpu.py
@@ -3255,10 +3255,11 @@ class CfgParallelRouter:
need_mib = sum(
t.numel() * t.element_size() for t in (*module.parameters(), *module.buffers())
) // (1 << 20)
+ automatic = getattr(self, "automatic_idle_only", False)
+ # Outside the load scope: read the card directly, before the memory read opens our context (3-7% busy).
+ util = _smi_util_pct(self.secondary.index) if automatic else None
free, total = self._secondary_free_total_mib()
- if getattr(self, "automatic_idle_only", False):
- # Built lazily during generation, after the load's selection scope ended: read the card directly.
- util = _smi_util_pct(self.secondary.index)
+ if automatic:
if not _idle_card(
DeviceProbe(
ordinal = self.secondary.index,
diff --git a/studio/backend/tests/test_diffusion_unet_cfg_parallel.py b/studio/backend/tests/test_diffusion_unet_cfg_parallel.py
index a3e6427509e..2ced3212c8a 100644
--- a/studio/backend/tests/test_diffusion_unet_cfg_parallel.py
+++ b/studio/backend/tests/test_diffusion_unet_cfg_parallel.py
@@ -327,6 +327,24 @@ def test_automatic_replica_is_not_built_on_a_card_another_job_keeps_busy(monkeyp
assert "80.0% busy" in router.disabled_reason
+def test_automatic_replica_build_reads_utilisation_before_opening_its_own_context(monkeypatch):
+ unet = UNet2DConditionModel()
+ router, replicas = _router(unet)
+ router.automatic_idle_only = True
+ opened = []
+
+ def free_total():
+ opened.append(True)
+ return 14798, 14911
+
+ monkeypatch.setattr(router, "_secondary_free_total_mib", free_total)
+ monkeypatch.setattr(mg, "_smi_util_pct", lambda _o: 7.0 if opened else 0.0)
+ lat = torch.randn(1, 4, 8, 8)
+ _sdxl_loop(unet, lat, steps = 2)
+ assert router.disabled_reason is None
+ assert len(replicas) == 1 and router.stats["steps_parallel"] == 2
+
+
def test_group_offloaded_denoiser_runs_cfg_parallel_from_its_onload_card(monkeypatch):
from core.inference import diffusion_memory as dm