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: do not demote a resident transformer to whole-module offload for the 2048 worst case (#15065)
Daniel Han38011fd95483
diff --git a/studio/backend/core/inference/diffusion_memory.py b/studio/backend/core/inference/diffusion_memory.pyindex bfa58e00967..e5ee65dca0c 100644--- a/studio/backend/core/inference/diffusion_memory.py+++ b/studio/backend/core/inference/diffusion_memory.py@@ -2965,9 +2965,10 @@ def _calibrated_faster_tier(stream_transformer: bool,) -> Optional[tuple[str, bool, bool, bool, str]]:"""Strictly faster tier than the flat pick, else None; resident tiers must fit the 2048 denoise (it cannot tile).- A flat resident-transformer pick whose measured 2048 denoise does not fit beside the weights (the flat runtime- headroom undercounts it) is demoted to the fastest tier that does fit, as ComfyUI offloads weights against its- activation estimate. Every check grows with the budget, so more VRAM never picks a slower tier."""+ A flat all-resident pick whose measured 2048 denoise does not fit is demoted to the fastest tier that does:+ nothing it holds has offload hooks a request could release. A resident-transformer pick (encoders streamed) is+ never demoted: like ComfyUI, which sizes residency per call, the generation guard handles an oversized request.+ Every check grows with the budget, so more VRAM never picks a slower tier."""if budget is None or free_mib is None or model_dense_mib is None or companion_dense_mib is None:return Nonete = max(0, int(text_encoder_dense_mib or 0))@@ -3047,12 +3048,7 @@ def _calibrated_faster_tier(),)# Only the 2048 denoise is checked here: it cannot tile, while an oversized decode is tiled by the generation guard.- denoise_fits = (- transformer + te + others <= room- if flat_rank == 0- else te > 0 and transformer + others <= room- )- if flat_rank <= 1 and not denoise_fits:+ if flat_rank == 0 and transformer + te + others > room:for fits, (tier_policy, stream_te, stream_tr, tile, reason) in candidates[flat_rank + 1 :]:if fits:return (diff --git a/studio/backend/tests/test_diffusion_calibrated_activation.py b/studio/backend/tests/test_diffusion_calibrated_activation.pyindex 302048089e0..7839cf3d8d6 100644--- a/studio/backend/tests/test_diffusion_calibrated_activation.py+++ b/studio/backend/tests/test_diffusion_calibrated_activation.py@@ -249,7 +249,43 @@ def test_16gb_qwen_image_21_at_the_max_speed_tier_keeps_streaming_the_transformeact = calibrated_image_activation("qwen-image-2.1", max_speed = True)assert _plan(16, QWEN21_GGUF, act) == _plan(16, QWEN21_GGUF, None)plan = _plan(22, QWEN21_GGUF, act)- assert plan.offload_policy == OFFLOAD_MODEL and plan.vae_tiling is False+ assert plan.offload_policy == OFFLOAD_GROUP and plan.stream_transformer is False+++# Real max-tier load of qwen-image-2.1-Q8_0.gguf, transformer_quant=none (plain GGUF, no offload groups).+QWEN21_Q8_GGUF = dict(+ model_dense_mib = 17_210, companion_dense_mib = 9_560, text_encoder_dense_mib = 8_916+)+# Real max-tier load of unsloth/Qwen-Image-2.1-GGUF (auto: INT8 DiT + INT8 TE).+QWEN21_AUTO_INT8 = dict(+ model_dense_mib = 18_128, companion_dense_mib = 10_680, text_encoder_dense_mib = 9_345+)+++ "total_gib, used_mib, sizes",+ [+ (22, 1_229, QWEN21_GGUF),+ (24, 2_400, QWEN21_GGUF),+ (24, 2_700, QWEN21_GGUF),+ (24, 1_229, QWEN21_AUTO_INT8),+ (24, 3_000, QWEN21_AUTO_INT8),+ # tightest cells: a capped B200 rendered 2048x2048 here without OOM+ (22, 1_850, QWEN21_Q8_GGUF),+ (24, 3_850, QWEN21_Q8_GGUF),+ ],+)+def test_a_resident_transformer_is_not_demoted_for_the_2048_worst_case(total_gib, used_mib, sizes):+ # Demoting would upload the whole transformer per 1024 render (~1.7x slower on a capped B200).+ act = calibrated_image_activation("qwen-image-2.1", max_speed = True)+ total = int(total_gib * GIB)+ card = DeviceMemory("cuda", "cuda", "discrete_vram", total - used_mib, total)+ kwargs = dict(target = _target(), device_memory = card, runtime_headroom_mib = 8192, **sizes)+ flat = plan_diffusion_memory(**kwargs)+ assert flat.offload_policy == OFFLOAD_GROUP and flat.stream_transformer is False+ plan = plan_diffusion_memory(calibrated_activation = act, **kwargs)+ assert plan.offload_policy == OFFLOAD_GROUP and plan.stream_transformer is False+ assert not any("2048 denoise" in reason for reason in plan.reasons)def test_the_shipped_qwen_image_21_figures_never_stream_the_transformer_on_16gb():@@ -401,7 +437,8 @@ def test_generation_guard_never_refuses_the_calibrated_2048_canvas_on_a_promotedfor step in range(10 * 4, 48 * 4 + 1):gib = step / 4plan = _plan(gib, sizes, act)- if "calibrated_headroom_mib" not in plan.estimates:+ resident = plan.offload_policy == OFFLOAD_GROUP and not plan.stream_transformer+ if "calibrated_headroom_mib" not in plan.estimates and not resident:continuepromoted += 1total = int(gib * GIB)