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: shipped activation seed for Qwen-Image-Edit placement (#15542)

Daniel Hancbe4498ad597
diff --git a/studio/backend/core/inference/diffusion_memory.py b/studio/backend/core/inference/diffusion_memory.py
index fba8ca1452f..39a80545fda 100644
--- a/studio/backend/core/inference/diffusion_memory.py
+++ b/studio/backend/core/inference/diffusion_memory.py
@@ -3291,12 +3291,16 @@ PARTIAL_RESIDENT_ENV = "UNSLOTH_DIFFUSION_PARTIAL_RESIDENT"
# int8 / fp8 denoisers on the compiled tiers (Qwen-Image-2.1: encoder 1849 streamed, denoise 1442, decode 1730).
# FLUX.1 / Z-Image: their worst phase is the untiled 16-channel VAE decode (_MEASURED_IMAGE_ACTIVATION_MIB).
# MOSS-Image: 2905 MiB worst-phase peak fully streamed (B200 capped at 16 GiB).
+# Qwen-Image-Edit-2511: 6046 MiB whole render (1024^2, one 1024^2 source, 40 steps, true CFG 3), int8 DiT + encoder.
_MEASURED_IMAGE_PEAK_MIB: dict[str, int] = {
"qwen-image-2.1": 1849,
"flux.1": 2666,
"z-image": 2666,
"moss-image": 2976,
+ "qwen-image-edit": 6046,
}
+# "0": Qwen-Image-Edit places from its learned peak only.
+MEASURED_ACTIVATION_QWEN_EDIT_ENV = "UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_QWEN_EDIT"
_MEASURED_PEAK_SPEED_MODES = ("default", "max")
_MEASURED_PEAK_MARGIN = 1.15
_MEASURED_PEAK_ROUND_MIB = 256
@@ -3463,6 +3467,10 @@ def measured_image_runtime_mib(
)
elif static_seed and str(speed_mode or "") in _MEASURED_PEAK_SPEED_MODES:
seed = _MEASURED_IMAGE_PEAK_MIB.get(str(family or "").lower())
+ if str(family or "").lower() == "qwen-image-edit" and _env_off(
+ MEASURED_ACTIVATION_QWEN_EDIT_ENV
+ ):
+ seed = None
if seed is None and phase_seeds:
phases = _MEASURED_IMAGE_ACTIVATION_MIB.get(str(family or "").lower())
if phases is not None:
diff --git a/studio/backend/tests/test_diffusion_measured_placement.py b/studio/backend/tests/test_diffusion_measured_placement.py
index d99f0a764b1..1240e0ba0df 100644
--- a/studio/backend/tests/test_diffusion_measured_placement.py
+++ b/studio/backend/tests/test_diffusion_measured_placement.py
@@ -1207,3 +1207,69 @@ def test_compiled_blocks_under_group_offload_skip_hook_tracing():
torch.testing.assert_close(out, expected, rtol = 0, atol = 1e-6)
# Traced hooks add a graph per hook variant; eager hooks leave only the block graph.
assert counters["stats"]["unique_graphs"] <= 1
+
+
+# Qwen-Image-Edit-2511 auto on a 16 / 12 GiB card: int8 DiT (20.4 GB), int8 ConvRot encoder, bf16 VAE; MiB as loaded.
+QEDIT_LOADED = {
+ "transformer": (19932, "dit"),
+ "text_encoder": (8560, "text_encoder"),
+ "vae": (242, "other"),
+}
+QEDIT_FLAT = dict(model_dense_mib = 38956, companion_dense_mib = 16062, text_encoder_dense_mib = 15820)
+
+
+def qedit_pipe(monkeypatch):
+ for env in (
+ "MEASURED_ACTIVATION_ENV",
+ "PARTIAL_RESIDENT_ENV",
+ "MEASURED_ACTIVATION_QWEN_EDIT_ENV",
+ ):
+ monkeypatch.delenv(getattr(dm, env, "UNSET_" + env), raising = False)
+ monkeypatch.setattr(dm, "_loaded_component_mib", lambda pipe: dict(QEDIT_LOADED), raising = False)
+ monkeypatch.setattr(dm, "_pipe_denoisers_hold_torchao", lambda pipe: True)
+ return object()
+
+
+def _qedit_flat_plan(budget_mib: int, total_mib: int):
+ plan = dm.plan_diffusion_memory(
+ target = types.SimpleNamespace(supports_model_cpu_offload = True),
+ device_memory = _memory(budget_mib, total_mib),
+ runtime_headroom_mib = dm.estimate_image_runtime_mib(
+ width = None, height = None, family = "qwen-image-edit"
+ ),
+ requested_mode = None,
+ **QEDIT_FLAT,
+ )
+ if plan.offload_policy == dm.OFFLOAD_MODEL:
+ plan = dm.torchao_streaming_plan(plan)
+ return plan
+
+
+def test_qwen_edit_seed_value():
+ # 6046 MiB whole edit render x 1.15, rounded up to 256 MiB
+ assert dm.measured_image_runtime_mib("qwen-image-edit", "default") == 7168
+ assert dm.measured_image_runtime_mib("qwen-image-edit", "off") is None
+
+
[email protected]("budget,total", [(13638, 16376), (9550, 12288)])
+def test_qwen_edit_fresh_home_keeps_part_of_the_int8_dit_resident(qedit_pipe, budget, total):
+ """A fresh home streamed every one of the 60 int8 DiT groups at 16 / 12 GiB (no seed, no learned peak)."""
+ plan = _qedit_flat_plan(budget, total)
+ assert (
+ plan.offload_policy in (dm.OFFLOAD_GROUP, dm.OFFLOAD_STREAMING) and plan.stream_transformer
+ )
+ new = _refine(qedit_pipe, plan, family = "qwen-image-edit")
+ assert new is not plan
+ resident = new.resident_transformer_mib
+ assert resident and 0 < resident < 19932
+ assert new.estimates["measured_runtime_headroom_mib"] == 7168
+ assert resident + 7168 + dm.DEFAULT_BASE_OVERHEAD_MIB + 242 <= budget
+
+
+def test_qwen_edit_seed_kill_switch(qedit_pipe, monkeypatch):
+ monkeypatch.setenv(dm.MEASURED_ACTIVATION_QWEN_EDIT_ENV, "0")
+ assert dm.measured_image_runtime_mib("qwen-image-edit", "default") is None
+ plan = _qedit_flat_plan(13638, 16376)
+ assert _refine(qedit_pipe, plan, family = "qwen-image-edit") is plan
+ assert dm.measured_image_runtime_mib("qwen-image-2.1", "default") == 2304