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: seed dense fp16 denoisers on the default and max tiers from measured peaks (#14720)

Daniel Han7a4d59974300
diff --git a/studio/backend/core/inference/diffusion.py b/studio/backend/core/inference/diffusion.py
index 1df95724c9f..ce11e993c2d 100644
--- a/studio/backend/core/inference/diffusion.py
+++ b/studio/backend/core/inference/diffusion.py
@@ -2568,6 +2568,17 @@ def _controlnet_streams(state: Any) -> bool:
)
+def _measured_target(target: Any) -> bool:
+ """Whether ``target`` is where the activation tables were measured: NVIDIA CUDA with a sub-quadratic SDPA kernel seen
+ to run. Math-only attention, ROCm and an unanswered probe are not."""
+ if getattr(target, "backend", None) != "cuda" or getattr(target, "vendor", None) != "nvidia":
+ return False
+ try:
+ return bool(sdpa_subquadratic_confirmed(target))
+ except Exception: # noqa: BLE001 - unprobed attention keeps the flat estimate
+ return False
+
+
def _calibrated_activation(fam: Any, target: Any) -> Any:
"""Measured activations apply only where measured: NVIDIA with a sub-quadratic attention kernel."""
if getattr(target, "backend", None) != "cuda" or getattr(target, "vendor", None) != "nvidia":
@@ -9806,6 +9817,8 @@ class DiffusionBackend:
try:
# the phase-table seed holds only where it was measured
pipe._unsloth_phase_seeds = _calibrated_activation(fam, target) is not None
+ # the dense default / max tier seeds hold on the measured target only
+ pipe._unsloth_dense_tier_seeds = _measured_target(target)
# a CFG-capable family may place from a peak recorded without CFG (``cfg:off``)
pipe._unsloth_peak_expects_cfg = bool(
getattr(fam, "uses_negative_prompt", False)
@@ -13053,6 +13066,14 @@ class DiffusionBackend:
guard_cfg = _negative_prompt_engaged(fam, guidance)
except Exception: # noqa: BLE001 - unknown: sized as a CFG request
guard_cfg = None
+ # a reference family's source image joins the denoiser's sequence, and only FLUX.3 and the
+ # ``reference_resolutions`` families price it in guard_condition_pixels
+ guard_unpriced_refs = bool(
+ getattr(fam, "reference", False)
+ and init_pil is not None
+ and ref_resolution is None
+ and not is_flux3_family(fam)
+ )
extra_mib = measured_request_extra_mib(
state.pipe,
width = guard_width,
@@ -13060,10 +13081,13 @@ class DiffusionBackend:
batch_size = guard_batch,
condition_pixels = guard_condition_pixels,
cfg = guard_cfg,
+ unpriced_references = guard_unpriced_refs,
)
if extra_mib > 0:
releasable_mib = resident_group_mib(state.pipe)
- if guard_condition_pixels > 0 and extra_mib > releasable_mib:
+ if (
+ guard_condition_pixels > 0 or guard_unpriced_refs
+ ) and extra_mib > releasable_mib:
# The guard credits a conditioned request nothing the load reserved: hook the resident
# transformer so this request can stream part of it.
hook_resident_denoiser(state.pipe, guard_target.torch_device, logger)
diff --git a/studio/backend/core/inference/diffusion_memory.py b/studio/backend/core/inference/diffusion_memory.py
index 901c9f7dd0e..bebb55f8873 100644
--- a/studio/backend/core/inference/diffusion_memory.py
+++ b/studio/backend/core/inference/diffusion_memory.py
@@ -2654,12 +2654,41 @@ _MEASURED_DENSE_EAGER_PEAK_MIB: dict[str, tuple[int, int]] = {
"qwen-image": (4248, 40900),
}
_MEASURED_DENSE_SPEED_MODES = ("off",)
+# Dense fp16 / fp32 denoisers (pre-Ampere cards: T4, V100, Turing) on the default and max tiers, seeded from the
+# family's measured peaks instead of the flat 8 GiB per megapixel estimate. "0" restores the flat estimate.
+MEASURED_ACTIVATION_DENSE_TIERS_ENV = "UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_DENSE_TIERS"
def _env_off(name: str) -> bool:
return (os.environ.get(name) or "").strip().lower() in ("0", "off", "false", "no")
+def _dense_seed_mib(
+ family: str, speed_mode: str, dense_mib: int, widen: int, tier_seeds: bool
+) -> Optional[int]:
+ """Seed MiB for a dense fp16 / fp32 denoiser (``widen`` = its element size), or None. Eager: the dense table. Default
+ / max: the larger of the dense table and the tier's worst phase (encoder, denoise, untiled decode), only for a
+ family the dense table measured at this DiT size. Families it lacks keep the flat estimate: on a T4, Z-Image's 11.5
+ GiB DiT would then be kept partly resident, which ran slower per step than streaming it whole (3.8-4.4 vs 3.2-3.6
+ s/step). ``tier_seeds``: the target is where the phase table was measured (NVIDIA with a sub-quadratic attention
+ kernel, ``diffusion._measured_target``); elsewhere (math-only attention, ROCm) the tiers keep the flat estimate."""
+ entry = _MEASURED_DENSE_EAGER_PEAK_MIB.get(family)
+ if entry is None or not 0 < dense_mib <= entry[1] * widen // 2:
+ return None
+ peak = entry[0] * widen // 2
+ if speed_mode in _MEASURED_DENSE_SPEED_MODES:
+ return peak
+ phases = _MEASURED_IMAGE_ACTIVATION_MIB.get(family)
+ if (
+ speed_mode not in _MEASURED_PEAK_SPEED_MODES
+ or not tier_seeds
+ or phases is None
+ or _env_off(MEASURED_ACTIVATION_DENSE_TIERS_ENV)
+ ):
+ return None
+ return max(peak, max(phases[1 if speed_mode == "max" else 0][:3]) * widen // 2)
+
+
def measured_image_runtime_mib(
family: Optional[str],
speed_mode: Optional[str],
@@ -2672,6 +2701,7 @@ def measured_image_runtime_mib(
quant: Optional[str] = None,
phase_seeds: bool = False,
static_seed: bool = True,
+ dense_tier_seeds: bool = False,
) -> Optional[int]:
"""Measured runtime headroom for ``family`` at this size, or None (unmeasured: use the flat estimate).
``dense_transformer_mib`` selects the dense eager table; ``compute_bytes`` scales it (fp32 Qwen-Image: 8480 vs 4248).
@@ -2682,20 +2712,21 @@ def measured_image_runtime_mib(
peak this machine recorded for (family, quant, speed tier, resolution bucket) at an earlier render
(diffusion_measured_peaks): it raises a seed and stands in for a missing one, never lowers a seed.
``static_seed=False`` (a denoiser no static table was measured on: bf16 or GGUF / int8 packed dense weights)
- answers from the learned peak alone."""
+ answers from the learned peak alone. ``dense_tier_seeds`` enables the dense default / max tier seeds (``_dense_seed_mib``)
+ on the target the phase table was measured on."""
if _env_off(MEASURED_ACTIVATION_ENV):
return None
seed: Optional[int] = None
if dense_transformer_mib is not None and _env_off(MEASURED_ACTIVATION_DENSE_ENV):
return None
if static_seed and dense_transformer_mib is not None:
- entry = _MEASURED_DENSE_EAGER_PEAK_MIB.get(str(family or "").lower())
- if entry is not None and str(speed_mode or "") in _MEASURED_DENSE_SPEED_MODES:
- peak, max_dit = entry
- widen = max(2, int(compute_bytes or 2))
- peak, max_dit = peak * widen // 2, max_dit * widen // 2
- if 0 < int(dense_transformer_mib) <= max_dit:
- seed = peak
+ seed = _dense_seed_mib(
+ str(family or "").lower(),
+ str(speed_mode or ""),
+ int(dense_transformer_mib),
+ max(2, int(compute_bytes or 2)),
+ dense_tier_seeds,
+ )
elif static_seed and str(speed_mode or "") in _MEASURED_PEAK_SPEED_MODES:
seed = _MEASURED_IMAGE_PEAK_MIB.get(str(family or "").lower())
if seed is None and phase_seeds:
@@ -3213,6 +3244,7 @@ def refine_plan_from_loaded_weights(
compute_bytes = compute_bytes or 2,
quant = read_quant,
phase_seeds = bool(getattr(pipe, "_unsloth_phase_seeds", False)),
+ dense_tier_seeds = bool(getattr(pipe, "_unsloth_dense_tier_seeds", False)),
static_seed = static_seed,
)
if headroom is None:
@@ -3941,9 +3973,13 @@ def measured_request_extra_mib(
batch_size: int = 1,
condition_pixels: int = 0,
cfg: Optional[bool] = None,
+ unpriced_references: bool = False,
) -> int:
"""MiB a request needs beyond what the measured placement reserved (0 when it fits or none was made). ``cfg``:
- whether the request runs classifier-free guidance (None: unknown, treated as running it)."""
+ whether the request runs classifier-free guidance (None: unknown, treated as running it). ``unpriced_references``:
+ the request carries reference images whose latents join the denoiser's sequence but are not in
+ ``condition_pixels`` (FLUX.2 Klein's primary reference): a placement made from a dense default / max tier seed,
+ measured on text-to-image, then sizes the request from the flat estimate."""
reserve = getattr(pipe, "_unsloth_measured_reserve", None)
if not reserve:
return 0
@@ -3962,15 +3998,25 @@ def measured_request_extra_mib(
# after the load only places the NEXT load, it must not stream resident groups for a request the same size as one
# that just completed. An unseeded family was placed from its learned peak, which is all there is to check against.
sized["phase_seeds"] = bool(getattr(pipe, "_unsloth_phase_seeds", False))
+ sized["dense_tier_seeds"] = bool(getattr(pipe, "_unsloth_dense_tier_seeds", False))
sized["static_seed"] = bool(reserve[8]) if len(reserve) > 8 and reserve[8] is not None else True
need = measured_image_runtime_mib(family, speed_mode, **sized)
learned = reserve[5] if len(reserve) > 5 else None
# placed from a peak recorded without CFG: a request that runs it doubles the denoiser batch no measurement covers
cfg_unmeasured = bool(len(reserve) > 9 and reserve[9]) and cfg is not False
- if (learned or need is None) and (
- getattr(pipe, "_unsloth_peak_static", False)
- or getattr(pipe, "_unsloth_loras", None)
- or cfg_unmeasured
+ # the dense tier seeds were measured on text-to-image: a reference the guard cannot size is not covered
+ tier_seeded = (
+ dense_mib is not None
+ and sized["dense_tier_seeds"]
+ and str(speed_mode or "") in _MEASURED_PEAK_SPEED_MODES
+ )
+ if (unpriced_references and tier_seeded) or (
+ (learned or need is None)
+ and (
+ getattr(pipe, "_unsloth_peak_static", False)
+ or getattr(pipe, "_unsloth_loras", None)
+ or cfg_unmeasured
+ )
):
# the learned peak no longer describes this pipeline (runtime LoRA adapters, a planned VAE saver that did not
# engage): requests size from the flat estimate
diff --git a/studio/backend/tests/test_diffusion_dense_tier_activation.py b/studio/backend/tests/test_diffusion_dense_tier_activation.py
new file mode 100644
index 00000000000..6893f44bc43
--- /dev/null
+++ b/studio/backend/tests/test_diffusion_dense_tier_activation.py
@@ -0,0 +1,253 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""Measured activations for DENSE fp16 denoisers on the default / max speed tiers (``diffusion_memory.py``).
+
+Pre-Ampere cards (T4, V100, Turing) load the denoiser dense in fp16, so ``measured_image_runtime_mib`` takes its dense
+branch. That branch only knew the eager tier: on the default tier (Studio's default) it returned None and the load
+placed from the flat 8 GiB per megapixel estimate (6.8 GiB for a turbo / distilled model), against measured peaks of
+about 2.5 GiB. For a family the dense table measured at that DiT size, the default / max tiers now take the larger of the
+dense table and the per-phase table's worst phase for the tier. CPU-only; the loaded sizes and the torchao check are stubbed.
+"""
+
+from __future__ import annotations
+
+import types
+
+import pytest
+
+import core.inference.diffusion_memory as dm
+
+T4_TOTAL = 15095
+T4_BUDGET = 12758
+KLEIN_LOADED = {
+ "transformer": (7393, "dit"),
+ "text_encoder": (7673, "text_encoder"),
+ "vae": (160, "other"),
+}
+KLEIN_FLAT = dict(model_dense_mib = 15258, companion_dense_mib = 7820, text_encoder_dense_mib = 7629)
+ZIMAGE_LOADED = {
+ "transformer": (11739, "dit"),
+ "text_encoder": (7672, "text_encoder"),
+ "vae": (160, "other"),
+}
+ZIMAGE_FLAT = dict(model_dense_mib = 19571, companion_dense_mib = 7832, text_encoder_dense_mib = 7672)
+ENVS = (
+ "UNSLOTH_DIFFUSION_MEASURED_ACTIVATION",
+ "UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_DENSE",
+ "UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_DENSE_TIERS",
+ "UNSLOTH_DIFFUSION_PARTIAL_RESIDENT",
+)
+
+
+def _memory(budget_mib: int, total_mib: int) -> "dm.DeviceMemory":
+ reserve = dm._reserve_mib("discrete_vram", total_mib)
+ return dm.DeviceMemory("cuda", "cuda", "discrete_vram", budget_mib + reserve, total_mib)
+
+
+def _flat_plan(
+ sizes: dict,
+ family: str,
+ budget_mib: int = T4_BUDGET,
+ total_mib: int = T4_TOTAL,
+):
+ return 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 = family),
+ **sizes,
+ )
+
+
+def _pipe(
+ monkeypatch,
+ loaded: dict,
+ dtype_name: str = "float16",
+ phase_seeds: bool = False,
+ tier_seeds: bool = True,
+):
+ import torch
+
+ for name in ENVS:
+ monkeypatch.delenv(name, raising = False)
+ monkeypatch.setattr(dm, "_loaded_component_mib", lambda pipe: dict(loaded))
+ monkeypatch.setattr(dm, "_pipe_denoisers_hold_torchao", lambda pipe: False)
+ return types.SimpleNamespace(
+ transformer = types.SimpleNamespace(dtype = getattr(torch, dtype_name)),
+ _unsloth_phase_seeds = phase_seeds,
+ # NVIDIA with a sub-quadratic SDPA kernel (diffusion._measured_target), as on the T4
+ _unsloth_dense_tier_seeds = tier_seeds,
+ )
+
+
[email protected](autouse = True)
+def _no_learned_store(tmp_path, monkeypatch):
+ import core.inference.diffusion_measured_peaks as mp
+ monkeypatch.setenv(mp.LEARNED_PEAKS_FILE_ENV, str(tmp_path / "peaks.json"))
+ mp._cache.update(path = None, mtime = None, data = None)
+
+
+def _refine(pipe, plan, family: str, speed: str):
+ return dm.refine_plan_from_loaded_weights(pipe, plan, family = family, speed_mode = speed)
+
+
[email protected]("speed", ["default", "max"])
+def test_t4_klein_compiled_tiers_keep_the_dit_resident(monkeypatch, speed):
+ pipe = _pipe(monkeypatch, KLEIN_LOADED)
+ plan = _flat_plan(KLEIN_FLAT, "flux.2-klein")
+ # flat: 8192 MiB of activations, every DiT block streamed
+ assert plan.estimates["runtime_headroom_mib"] == 8192
+ assert plan.offload_policy == dm.OFFLOAD_GROUP and plan.stream_transformer
+ new = _refine(pipe, plan, "flux.2-klein", speed)
+ assert new is not plan
+ headroom = new.estimates["measured_runtime_headroom_mib"]
+ assert headroom == (3072 if speed == "default" else 3328)
+ # default: the whole DiT; max (the larger compiled-tier peak): all but the last few blocks
+ assert new.resident_transformer_mib == (7393 if speed == "default" else 7222)
+ assert 160 + new.resident_transformer_mib + headroom + dm.DEFAULT_BASE_OVERHEAD_MIB <= T4_BUDGET
+
+
+def test_t4_zimage_keeps_the_flat_plan(monkeypatch):
+ """No dense table entry for Z-Image: a partly resident 11.5 GiB DiT ran slower than streaming it whole on a T4."""
+ plan = _flat_plan(ZIMAGE_FLAT, "z-image-turbo")
+ assert plan.estimates["runtime_headroom_mib"] == 6963
+ for phase_seeds in (False, True):
+ pipe = _pipe(monkeypatch, ZIMAGE_LOADED, phase_seeds = phase_seeds)
+ for speed in ("off", "default", "max"):
+ assert _refine(pipe, plan, "z-image", speed) is plan
+
+
+def test_seed_never_below_a_measured_phase_or_the_eager_seed():
+ m = dm.measured_image_runtime_mib
+ for family, (eager_peak, max_dit) in dm._MEASURED_DENSE_EAGER_PEAK_MIB.items():
+ phases = dm._MEASURED_IMAGE_ACTIVATION_MIB.get(family)
+ for speed, column in (("default", 0), ("max", 1)):
+ seed = m(family, speed, dense_transformer_mib = max_dit, dense_tier_seeds = True)
+ if phases is None:
+ assert seed is None, family
+ continue
+ assert seed >= max(phases[column][:3]) * dm._MEASURED_PEAK_MARGIN, (family, speed)
+ assert seed >= m(family, "off", dense_transformer_mib = max_dit), (family, speed)
+ # off the measured target (math-only attention, ROCm) the tiers keep the flat estimate
+ assert m(family, speed, dense_transformer_mib = max_dit) is None, (family, speed)
+ # fp32 compute doubles it, never shrinks it
+ assert (
+ m(
+ family,
+ speed,
+ dense_transformer_mib = max_dit,
+ compute_bytes = 4,
+ dense_tier_seeds = True,
+ )
+ >= 2 * seed - 256
+ )
+
+
+def test_larger_dit_bf16_and_kill_switch_keep_the_flat_plan(monkeypatch):
+ m = dm.measured_image_runtime_mib
+ # klein-9B is above the size the dense table measured
+ assert m("flux.2-klein", "default", dense_transformer_mib = 17300) is None
+ # an unmeasured family, with or without phase evidence
+ assert m("sdxl", "default", dense_transformer_mib = 4900, phase_seeds = True) is None
+ plan = _flat_plan(KLEIN_FLAT, "flux.2-klein")
+ # bf16 (every Ampere+ card): no static seed, learned peaks only
+ assert (
+ _refine(_pipe(monkeypatch, KLEIN_LOADED, "bfloat16"), plan, "flux.2-klein", "default")
+ is plan
+ )
+ pipe = _pipe(monkeypatch, KLEIN_LOADED)
+ monkeypatch.setenv("UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_DENSE_TIERS", "0")
+ assert _refine(pipe, plan, "flux.2-klein", "default") is plan
+ # the eager tier is not behind the new switch
+ assert _refine(pipe, plan, "flux.2-klein", "off") is not plan
+
+
+def test_large_card_plan_unchanged(monkeypatch):
+ pipe = _pipe(monkeypatch, KLEIN_LOADED)
+ resident = _flat_plan(KLEIN_FLAT, "flux.2-klein", 160000, 183359)
+ assert resident.offload_policy == dm.OFFLOAD_NONE
+ assert _refine(pipe, resident, "flux.2-klein", "default") is resident
+
+
+def test_guard_charges_bigger_requests_past_the_default_tier_reserve(monkeypatch):
+ for name in ENVS:
+ monkeypatch.delenv(name, raising = False)
+ pipe = types.SimpleNamespace(
+ _unsloth_measured_reserve = (3072, "flux.2-klein", "default", 7393, 2),
+ _unsloth_dense_tier_seeds = True,
+ )
+ assert dm.measured_request_extra_mib(pipe, width = 1024, height = 1024) == 0
+ # 2048 x 2048 is four megapixels: the seed scales with the pixels, so resident groups stream again
+ assert dm.measured_request_extra_mib(pipe, width = 2048, height = 2048) == 12288 - 3072
+ assert dm.measured_request_extra_mib(pipe, width = 1024, height = 1024, batch_size = 2) > 0
+
+
[email protected]("speed", ["default", "max"])
+def test_unmeasured_target_keeps_the_flat_plan(monkeypatch, speed):
+ """Math-only attention or ROCm: the phase table was not measured there, so a dense fp16 load keeps the flat
+ reserve on the compiled tiers (the eager dense table is unchanged)."""
+ pipe = _pipe(monkeypatch, KLEIN_LOADED, tier_seeds = False)
+ plan = _flat_plan(KLEIN_FLAT, "flux.2-klein")
+ assert _refine(pipe, plan, "flux.2-klein", speed) is plan
+ assert _refine(pipe, plan, "flux.2-klein", "off") is not plan
+
+
+def test_measured_target_needs_nvidia_and_a_subquadratic_kernel(monkeypatch):
+ import core.inference.diffusion as diffusion
+
+ nvidia = types.SimpleNamespace(backend = "cuda", vendor = "nvidia")
+ rocm = types.SimpleNamespace(backend = "cuda", vendor = "amd")
+ monkeypatch.setattr(diffusion, "sdpa_subquadratic_confirmed", lambda target: True)
+ assert diffusion._measured_target(nvidia) is True
+ assert diffusion._measured_target(rocm) is False
+ assert diffusion._measured_target(types.SimpleNamespace(backend = "mps", vendor = "apple")) is False
+ # math-only attention (no fused kernel ran) and a probe that raised are not the measured target
+ monkeypatch.setattr(diffusion, "sdpa_subquadratic_confirmed", lambda target: False)
+ assert diffusion._measured_target(nvidia) is False
+
+ def boom(target):
+ raise RuntimeError("probe failed")
+
+ monkeypatch.setattr(diffusion, "sdpa_subquadratic_confirmed", boom)
+ assert diffusion._measured_target(nvidia) is False
+
+
+def test_unpriced_reference_request_sizes_from_the_flat_estimate(monkeypatch):
+ """A FLUX.2 Klein reference render adds the source image's latents to the denoiser's sequence, which the guard does
+ not count in condition_pixels and the text-to-image tier seed never measured: it falls back to the flat estimate,
+ so the resident DiT groups stream again exactly as the flat plan would have placed them."""
+ for name in ENVS:
+ monkeypatch.delenv(name, raising = False)
+ pipe = types.SimpleNamespace(
+ _unsloth_measured_reserve = (3072, "flux.2-klein", "default", 7393, 2),
+ _unsloth_dense_tier_seeds = True,
+ )
+ flat = dm.estimate_image_runtime_mib(width = 1024, height = 1024, family = "flux.2-klein")
+ assert flat == 8192
+ extra = dm.measured_request_extra_mib
+ assert extra(pipe, width = 1024, height = 1024, unpriced_references = True) == flat - 3072
+ # text-to-image keeps the seed
+ assert extra(pipe, width = 1024, height = 1024) == 0
+ # the eager dense table is unaffected
+ eager = types.SimpleNamespace(
+ _unsloth_measured_reserve = (3072, "flux.2-klein", "off", 7393, 2),
+ _unsloth_dense_tier_seeds = True,
+ )
+ assert extra(eager, width = 1024, height = 1024, unpriced_references = True) == 0
+
+
+def test_generate_passes_unpriced_references_to_the_guard():
+ src = (__import__("pathlib").Path(dm.__file__).parent / "diffusion.py").read_text(
+ encoding = "utf-8"
+ )
+ at = src.index("guard_unpriced_refs = bool(")
+ window = src[at : at + 400]
+ for part in (
+ 'getattr(fam, "reference", False)',
+ "init_pil is not None",
+ "ref_resolution is None",
+ "not is_flux3_family(fam)",
+ ):
+ assert part in window, part
+ call = src.index("extra_mib = measured_request_extra_mib(", at)
+ assert "unpriced_references = guard_unpriced_refs," in src[call : call + 500]
diff --git a/studio/backend/tests/test_diffusion_measured_placement.py b/studio/backend/tests/test_diffusion_measured_placement.py
index cc3c1995cba..4559f6c9f2b 100644
--- a/studio/backend/tests/test_diffusion_measured_placement.py
+++ b/studio/backend/tests/test_diffusion_measured_placement.py
@@ -608,7 +608,9 @@ def test_generate_hooks_the_resident_transformer_only_when_the_release_falls_sho
encoding = "utf-8"
)
at = src.index("releasable_mib = resident_group_mib(state.pipe)")
- assert "if guard_condition_pixels > 0 and extra_mib > releasable_mib:" in src[at : at + 200]
+ # conditioned requests: priced condition pixels, or a reference the guard cannot price (FLUX.2 Klein's source image)
+ assert "guard_condition_pixels > 0 or guard_unpriced_refs" in src[at : at + 200]
+ assert ") and extra_mib > releasable_mib:" in src[at : at + 250]
assert "hook_resident_denoiser(state.pipe," in src[at : at + 600]
assert (
src.index("restore_resident = release_resident_groups(state.pipe, extra_mib, logger)") > at
diff --git a/studio/backend/tests/test_diffusion_measured_placement_dense.py b/studio/backend/tests/test_diffusion_measured_placement_dense.py
index 637465e1ad4..06d9da73dda 100644
--- a/studio/backend/tests/test_diffusion_measured_placement_dense.py
+++ b/studio/backend/tests/test_diffusion_measured_placement_dense.py
@@ -74,7 +74,13 @@ def test_dense_headroom_values(klein_pipe, monkeypatch):
assert m("flux.1", "off", dense_transformer_mib = 22680) == 2816
assert m("qwen-image", "off", dense_transformer_mib = 38968) == 5120
assert m("flux.2-klein", "off", dense_transformer_mib = 7393, width = 2048, height = 2048) == 11520
+ # the compiled tiers take the family's worst measured phase on that tier (2645 / 2677 MiB, the untiled decode);
+ # unmeasured families and a larger DiT of the same family (klein-9B) keep the flat estimate
+ assert m("flux.2-klein", "default", dense_transformer_mib = 7393, dense_tier_seeds = True) == 3072
+ assert m("flux.2-klein", "max", dense_transformer_mib = 7393, dense_tier_seeds = True) == 3328
+ # not on the target the phase table was measured on (math-only attention, ROCm): flat
assert m("flux.2-klein", "default", dense_transformer_mib = 7393) is None
+ assert m("flux.2-klein", "default", dense_transformer_mib = 17300) is None
assert m("sdxl", "off", dense_transformer_mib = 4900) is None
assert m("flux.2-klein", "off", dense_transformer_mib = 17300) is None
assert m("flux.2-klein", "off") is None
@@ -115,7 +121,7 @@ def test_large_card_and_other_tiers_untouched(klein_pipe):
assert resident.offload_policy == dm.OFFLOAD_NONE
assert _refine(klein_pipe, resident) is resident
plan = _flat_plan(12758)
- assert _refine(klein_pipe, plan, speed = "default") is plan
+ assert _refine(klein_pipe, plan, speed = "unknown") is plan
assert _refine(klein_pipe, plan, family = "sdxl") is plan
balanced = _flat_plan(12758, mode = "balanced")
assert _refine(klein_pipe, balanced) is balanced