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: report compile and CUDA graph engagement in the image and video status (#14656)

Daniel Han3612651021c6
diff --git a/studio/backend/core/inference/diffusion.py b/studio/backend/core/inference/diffusion.py
index 1ca3bfa2ffa..84741454a86 100644
--- a/studio/backend/core/inference/diffusion.py
+++ b/studio/backend/core/inference/diffusion.py
@@ -13699,6 +13699,10 @@ class DiffusionBackend:
"transformer_cache_stats": static_skip_stats(state.pipe),
"baked_loras": _baked_lora_names(state.pipe),
"multi_gpu": multigpu_placement_status(state.pipe),
+ "graph_engagement": cuda_graph.engagement(
+ tuple(getattr(state.pipe, "_unsloth_cuda_graphs", ()) or ())
+ or getattr(state, "cuda_graphs", ())
+ ),
"cfg_batch": cfg_batch_status(state.pipe),
"zimage_cfg_split": zimage_cfg_split_status(state.pipe),
"resolved": resolved,
diff --git a/studio/backend/core/inference/diffusion_cuda_graph.py b/studio/backend/core/inference/diffusion_cuda_graph.py
index b74828a898b..877b44dbc14 100644
--- a/studio/backend/core/inference/diffusion_cuda_graph.py
+++ b/studio/backend/core/inference/diffusion_cuda_graph.py
@@ -14,6 +14,7 @@ import contextlib
import gc
import inspect
import os
+import sys
import threading
import traceback
import weakref
@@ -2447,6 +2448,43 @@ def stats(handles: Any) -> dict:
return out
+def engagement(handles: Any) -> dict:
+ """Compile / CUDA-graph engagement counters for the status payload, so a client can tell an engaged path from one
+ that merely never recompiles: this load's graph captures, replays and ungraphed denoiser calls (whole-step and per
+ block, with a layer split's per-card segment graphs), and the process's dynamo frame and graph-break totals
+ (process-wide: a new frame or break after the first render is a recompile or a new break)."""
+ # A whole-step graph that dropped a key or failed hands its calls to per-block graphs it holds as
+ # ``fallback_handle`` (``GraphedForward._engage_fallback``): those count too.
+ units: list = []
+ for handle in handles or ():
+ units.append(handle)
+ nested = getattr(handle, "fallback_handle", None)
+ if nested is not None and nested is not handle:
+ units.append(nested)
+ s = stats(units)
+ out = {
+ field: s[field]
+ for field in ("graphs", "captures", "replays", "eager_calls", "invalidations", "fallbacks")
+ }
+ out["segment_captures"] = out["segment_replays"] = 0
+ for handle in units:
+ for segment in getattr(handle, "segments", None) or ():
+ try:
+ out["segment_captures"] += int(segment.stats.get("segment_captures", 0))
+ out["segment_replays"] += int(segment.stats.get("segment_replays", 0))
+ except Exception: # noqa: BLE001
+ pass
+ out["dynamo_frames"] = out["graph_breaks"] = None
+ if "torch._dynamo" in sys.modules:
+ try:
+ from torch._dynamo.utils import counters
+ out["dynamo_frames"] = int(counters["stats"].get("unique_graphs", 0))
+ out["graph_breaks"] = int(sum(counters["graph_break"].values()))
+ except Exception: # noqa: BLE001
+ pass
+ return out
+
+
def never_engaged(handles: Any) -> Optional[str]:
"""Why the armed graphs never replayed a step; None before the first call or once any engaged."""
if not handles:
diff --git a/studio/backend/core/inference/video.py b/studio/backend/core/inference/video.py
index e59166a39c7..f9374fdb9c2 100644
--- a/studio/backend/core/inference/video.py
+++ b/studio/backend/core/inference/video.py
@@ -13540,6 +13540,7 @@ class VideoBackend:
},
"multi_gpu": multigpu_placement_status(getattr(state, "pipe", None)),
"cfg_batch": cfg_batch_status(getattr(state, "pipe", None)),
+ "graph_engagement": _graph_engagement(getattr(state, "pipe", None)),
"resolved": resolved,
}
@@ -13577,6 +13578,17 @@ _backend: Optional[VideoBackend] = None
_backend_lock = threading.Lock()
+def _graph_engagement(pipe: Any) -> Optional[dict]:
+ """``diffusion_cuda_graph.engagement`` for the loaded pipe; None when unreadable (never fails a status poll)."""
+ try:
+ from . import diffusion_cuda_graph
+ return diffusion_cuda_graph.engagement(
+ tuple(getattr(pipe, "_unsloth_cuda_graphs", ()) or ())
+ )
+ except Exception: # noqa: BLE001
+ return None
+
+
def get_video_backend() -> VideoBackend:
global _backend
with _backend_lock:
diff --git a/studio/backend/models/inference.py b/studio/backend/models/inference.py
index b86c9207c6e..64b930e951b 100644
--- a/studio/backend/models/inference.py
+++ b/studio/backend/models/inference.py
@@ -5753,6 +5753,12 @@ class DiffusionStatusResponse(BaseModel):
"call counts, or why it declined); null when the load had one card to use. A multi-card load that kept "
"everything on its primary card reports why it declined.",
)
+ graph_engagement: Optional[Dict[str, Any]] = Field(
+ None,
+ description = "Compile / CUDA-graph engagement counters: this load's graph captures, replays and ungraphed "
+ "denoiser calls (whole-step, per block, per-card segments, and the per-block graphs a whole-step graph falls "
+ "back to), and the process's dynamo frame and graph-break totals; null when nothing is loaded.",
+ )
loaded: bool = Field(False, description = "Whether a diffusion model is loaded")
evicted: List[str] = Field(
default_factory = list,
@@ -7415,6 +7421,12 @@ class VideoStatusResponse(BaseModel):
"call counts, or why it declined); null when the load had one card to use. A multi-card load that kept "
"everything on its primary card reports why it declined.",
)
+ graph_engagement: Optional[Dict[str, Any]] = Field(
+ None,
+ description = "Compile / CUDA-graph engagement counters: this load's graph captures, replays and ungraphed "
+ "denoiser calls (whole-step, per block, per-card segments, and the per-block graphs a whole-step graph falls "
+ "back to), and the process's dynamo frame and graph-break totals; null when nothing is loaded.",
+ )
loaded: bool = Field(False, description = "Whether a video model is loaded")
evicted: List[str] = Field(
default_factory = list,
diff --git a/studio/backend/tests/test_diffusion_cuda_graph.py b/studio/backend/tests/test_diffusion_cuda_graph.py
index f24b70de8a4..d94460d4789 100644
--- a/studio/backend/tests/test_diffusion_cuda_graph.py
+++ b/studio/backend/tests/test_diffusion_cuda_graph.py
@@ -1655,3 +1655,64 @@ def test_capture_warmups_wait_for_held_replica_work(stub_torch):
assert handle.stats["captures"] == 1
assert seen == [0] * (cg.WARMUP_ITERS + 1)
assert cg._OUTSIDE_JOBS == 0 and cg._CAPTURE_DEPTH == 0
+
+
+def test_engagement_reports_captures_replays_and_per_card_segments():
+ """Status shows whether the graph layers are ENGAGED, not only that nothing recompiled."""
+ import types as _types
+
+ seg = _types.SimpleNamespace(stats = {"segment_captures": 2, "segment_replays": 30})
+ whole = _types.SimpleNamespace(
+ cache = {1: None},
+ stats = {"captures": 1, "replays": 7, "eager_calls": 2, "invalidations": 0},
+ placement = None,
+ poisoned = False,
+ capture_error = None,
+ )
+ blocks = _types.SimpleNamespace(
+ cache = {},
+ stats = {"captures": 3, "replays": 9},
+ placement = None,
+ poisoned = False,
+ capture_error = None,
+ segments = [seg],
+ )
+ out = cg.engagement((whole, blocks))
+ assert out["graphs"] == 1 and out["captures"] == 4 and out["replays"] == 16
+ assert out["eager_calls"] == 2 and out["segment_captures"] == 2 and out["segment_replays"] == 30
+ assert set(out) >= {"dynamo_frames", "graph_breaks"}
+ assert cg.engagement(())["captures"] == 0
+
+
+def test_engagement_counts_the_per_block_graphs_a_whole_step_graph_fell_back_to():
+ import types as _types
+
+ seg = _types.SimpleNamespace(stats = {"segment_captures": 1, "segment_replays": 12})
+ blocks = _types.SimpleNamespace(
+ cache = {1: None, 2: None},
+ stats = {"captures": 5, "replays": 40},
+ placement = None,
+ poisoned = False,
+ capture_error = None,
+ segments = [seg],
+ )
+ step = _types.SimpleNamespace(
+ cache = {},
+ stats = {"captures": 1, "replays": 2, "eager_calls": 3, "fallbacks": 1},
+ placement = None,
+ poisoned = True,
+ capture_error = None,
+ fallback_handle = blocks,
+ )
+ out = cg.engagement((step,))
+ assert out["graphs"] == 2 and out["captures"] == 6 and out["replays"] == 42
+ assert out["fallbacks"] == 1 and out["segment_captures"] == 1 and out["segment_replays"] == 12
+
+
+def test_status_response_models_keep_graph_engagement():
+ from models.inference import DiffusionStatusResponse, VideoStatusResponse
+ counters = {"graphs": 1, "captures": 1, "replays": 7, "eager_calls": 0}
+ for model in (DiffusionStatusResponse, VideoStatusResponse):
+ dumped = model.model_validate({"graph_engagement": counters}).model_dump()
+ assert dumped["graph_engagement"] == counters
+ assert model.model_validate({}).model_dump()["graph_engagement"] is None