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: keep SDXL ControlNet running after the T4 resident promotion (#15446)

Daniel Han9c397197e085
diff --git a/studio/backend/core/inference/diffusion_memory.py b/studio/backend/core/inference/diffusion_memory.py
index 4e29acc9bf4..fba8ca1452f 100644
--- a/studio/backend/core/inference/diffusion_memory.py
+++ b/studio/backend/core/inference/diffusion_memory.py
@@ -1640,6 +1640,11 @@ _MEASURED_IMAGE_ACTIVATION_MIB: dict[
_RESIDENT_ONLY_CALIBRATED = frozenset({"sdxl"})
+def _resident_only_hint(family: Optional[str]) -> bool:
+ parts = str(family or "").split()
+ return bool(parts) and parts[0] in _RESIDENT_ONLY_CALIBRATED
+
+
def calibrated_image_activation(
family: Optional[str], *, max_speed: bool = True
) -> Optional[CalibratedImageActivation]:
@@ -7645,6 +7650,9 @@ def image_activation_verdict(
if budget is None:
return ImageActivationVerdict(ACTIVATION_RUN)
# Calibrated tiers measured only the unconditioned denoise; a ControlNet counts as one output-sized image.
+ # Not on a U-Net: its ControlNet adds no tokens and stays under the measured decode peak.
+ if controlnet and _resident_only_hint(family):
+ controlnet = False
input_pixels = max(0, int(condition_pixels or 0))
conditioned = bool(calibrated_placement) and (input_pixels > 0 or bool(controlnet))
if calibrated_placement and controlnet:
diff --git a/studio/backend/tests/test_diffusion_calibrated_activation.py b/studio/backend/tests/test_diffusion_calibrated_activation.py
index b8fb88d2362..b74ad1cd2d2 100644
--- a/studio/backend/tests/test_diffusion_calibrated_activation.py
+++ b/studio/backend/tests/test_diffusion_calibrated_activation.py
@@ -625,3 +625,38 @@ def test_sdxl_measured_activation_only_ever_adds_the_resident_tier():
assert plan.offload_policy == OFFLOAD_NONE, gib
assert resident_from == 15
assert _plan(12, SDXL_FP16, act).offload_policy == OFFLOAD_MODEL
+
+
[email protected]("width, height", [(1024, 1024), (1152, 896), (768, 768)])
+def test_sdxl_controlnet_still_runs_after_the_t4_resident_promotion(monkeypatch, width, height):
+ """Resident SDXL on a T4 must not refuse ControlNet requests that whole-module offload ran."""
+ monkeypatch.setattr(dm, "_vram_budget_fraction", lambda: 0.97)
+ hint = "sdxl stabilityai/stable-diffusion-xl-base-1.0"
+ flat, plan = _t4_plan(None), _t4_plan(calibrated_image_activation("sdxl"))
+ assert flat.offload_policy == OFFLOAD_MODEL and plan.offload_policy == OFFLOAD_NONE
+ resident_free = 14_807 - SDXL_FP16["model_dense_mib"]
+ kw = dict(width = width, height = height, family = hint, tile_side = dm.DEFAULT_VAE_TILE_SIDE)
+ before = _guard(14_807, 14_912, calibrated = False, controlnet = True, **kw)
+ after = _guard(
+ resident_free,
+ 14_912,
+ calibrated = "calibrated_headroom_mib" in plan.estimates,
+ controlnet = True,
+ **kw,
+ )
+ assert before.action != dm.ACTIVATION_REFUSE
+ assert after.action != dm.ACTIVATION_REFUSE, after
+ plain = _guard(resident_free, 14_912, calibrated = True, **kw)
+ assert after == plain
+
+
+def test_controlnet_surcharge_still_applies_to_transformer_families_named_like_sdxl():
+ assert dm._resident_only_hint("sdxl stabilityai/stable-diffusion-xl-base-1.0")
+ assert not dm._resident_only_hint("flux.1 someone/flux-sdxl-style")
+ assert not dm._resident_only_hint("")
+ assert not dm._resident_only_hint(None)
+ kw = dict(width = 1024, height = 1024, family = "flux.1 someone/flux-sdxl-style")
+ assert (
+ _guard(6 * GIB, 24 * GIB, calibrated = True, controlnet = True, **kw).action
+ == dm.ACTIVATION_REFUSE
+ )