Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b24c827
Studio images: family batch adapters, measured batching race and per-…
danielhanchen Nov 26, 2026
28a9ecb
Studio images: no coalescing wait at a shape with no admitted size; r…
danielhanchen Nov 26, 2026
f437380
Studio images: a batch size that loses the race drops its CUDA graphs
danielhanchen Nov 26, 2026
58e0db6
Studio images: test that a measured win coalesces at the winning size…
danielhanchen Nov 26, 2026
6c55fd6
Studio images: members a fired batch could not take coalesce again be…
danielhanchen Nov 26, 2026
f5b1cec
Studio images: no shared call while FBCache can run; decode coalesced…
danielhanchen Nov 26, 2026
e8879fb
Studio images: FBCache coupling test holds with the length guard and …
danielhanchen Nov 26, 2026
731542d
Studio images: free the failed call before the halved retry; key race…
danielhanchen Nov 26, 2026
a8e5e17
Studio images: an edit at a new reference size never evicts a text-to…
danielhanchen Nov 26, 2026
9f0b357
Studio images: batch-size graphs get their own pool and graph budget;…
danielhanchen Nov 26, 2026
51c1217
Studio images: the race's batched-eager arm really runs with the grap…
danielhanchen Nov 26, 2026
bae160e
Studio images: key batching race verdicts by card topology
danielhanchen Nov 26, 2026
95de9ec
Studio images: price and scope batched CUDA graphs by what they hold
danielhanchen Nov 27, 2026
fe47b92
Studio images: seeded joins, eager wins and static compiles follow wh…
danielhanchen Nov 27, 2026
1a97100
Studio images: pin the Fast CFG interval in the batch key
danielhanchen Nov 27, 2026
53efa94
Studio images: the eager arm stays eager, graphed verdicts keep their…
danielhanchen Nov 27, 2026
8ca902e
Studio images: an aborted race size drops the batched graphs its warm…
danielhanchen Nov 27, 2026
3221b2c
Merge remote-tracking branch 'origin/main' into studio-batch-infra-main
danielhanchen Nov 27, 2026
92efbc1
Studio images: block graph handles never count a graphed race winner …
danielhanchen Nov 27, 2026
705da24
Studio images: a graphed race verdict holds only beside a live graph …
danielhanchen Nov 27, 2026
0d7d96d
Studio images: a measured batching win serves only with a passing G2c…
danielhanchen Nov 27, 2026
395de8b
Studio images: the race's replay check compares row 0 with its solo r…
danielhanchen Nov 27, 2026
e5b8e38
Studio images: the quality gate reads the path a race really ran, and…
danielhanchen Nov 27, 2026
71e85dc
Studio images: the race picks a qualifying arm first and refuses size…
danielhanchen Nov 27, 2026
67a7dcd
Studio images: a batched warm-up that runs out of memory keeps the si…
danielhanchen Nov 27, 2026
0dac8dd
Merge remote-tracking branch 'origin/main' into studio-batch-g2c-gate
danielhanchen Nov 27, 2026
7859edb
Studio images: the race never measures across a change in how the loa…
danielhanchen Nov 27, 2026
9173835
Studio images: the route leaves MOSS to the engine, and an eager win …
danielhanchen Nov 27, 2026
6e6b15b
Studio images: an adapted load never consumes the adapter-free batchi…
danielhanchen Nov 27, 2026
6332acb
Studio images: withhold an eager batching win once a same-size graph …
danielhanchen Nov 27, 2026
9993ecd
Merge remote-tracking branch 'origin/main' into studio-batch-g2c-gate
danielhanchen Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Studio images: seeded joins, eager wins and static compiles follow wh…
…at was measured

A seeded request joins only when every batch size it could render at has
a neighbour- and replay-exact verdict, so a streamed load that still
admits unmeasured sizes keeps seeded requests alone. When the eager arm
wins a size, the race drops that size's recorded graphs, so dispatch runs
the arm that was measured. The race derives the static-compile size limit
from the load's compile state, since resident and graphed loads answer
serial before the compiled-sizes rule.
  • Loading branch information
danielhanchen committed Nov 27, 2026
commit fe47b9268281f814c46af0ff1792f7a4f6105e79
17 changes: 13 additions & 4 deletions studio/backend/core/inference/diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -18454,15 +18454,21 @@ def coalesce_seeded_ok(
steps: Optional[int] = None,
) -> bool:
"""Whether an explicitly seeded request may share a call: the measured path at this shape is neighbour-exact
and replays a member bit for bit (diffusion_batch_race.seeded_join_ok) at every size it could join."""
and replays a member bit for bit (diffusion_batch_race.seeded_join_ok) at every size it could join. A load that
still admits unmeasured sizes (policy ``any``) can fire at one of them, so every admitted size needs a verdict."""
state = self._state
if state is None:
return False
from . import diffusion_batch_race
from .image_request_batching import batch_max

admitted = self.coalesce_batch_sizes(width, height, guidance, steps)
sizes = set(range(2, batch_max() + 1)) if admitted is None else set(admitted)
sizes = {k for k in sizes if k > int(images or 1)}
if not sizes:
return False
measured = _measured_sizes(state, width, height, guidance, steps)
winners = [v for v in measured.values() if v.get("promoted")]
return bool(winners) and all(diffusion_batch_race.seeded_join_ok(v) for v in winners)
return all(diffusion_batch_race.seeded_join_ok(measured.get(k)) for k in sizes)

def batch_race(
self,
Expand Down Expand Up @@ -18513,7 +18519,10 @@ def idle() -> bool:
if policy["mode"] == "serial" and not policy.get("measurable"):
raise diffusion_batch_race.RaceRefused(policy["reason"])
allowed = None
if policy["mode"] == "compiled_sizes":
# From the load's compile state, not the policy mode: resident and graphed loads answer serial before it.
if "compiled" in (state.speed_optims or ()) and compiled_shapes_are_static(
state.pipe, state.speed_mode
):
dims = (int(width), int(height))
shapes = getattr(state.compile_cache_ctx, "shapes", None) or ()
compiled = {int(shape[2]) for shape in list(shapes) if tuple(shape[:2]) == dims}
Expand Down
7 changes: 4 additions & 3 deletions studio/backend/core/inference/diffusion_batch_race.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,10 @@ def batch(
report["aborted"] = True
break
report["sizes"][str(size)] = verdict
if not verdict.get("promoted"):
# A losing size never runs batched here: drop its graphs (their own pool returns to the card; under
# BATCH_POOL_ENV=shared they stay in the one pool for the next capture).
if not verdict.get("promoted") or verdict.get("arm") == "batched_eager":
# A losing size never runs batched here, and an eager-won size must not replay the graphs the race
# recorded (dispatch never bypasses them; user calls never record new ones): drop that size's graphs (their
# own pool returns to the card; under BATCH_POOL_ENV=shared they stay in the one pool).
dropped = 0
for handle in handles:
drop = getattr(handle, "drop_batched", None)
Expand Down
64 changes: 64 additions & 0 deletions studio/backend/tests/test_image_batch_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,3 +955,67 @@ def test_a_graphed_verdict_admits_a_size_only_while_its_graph_exists(monkeypatch
assert race.effective_verdict(graphed_win, 2, restarted)["promoted"] is False
no_graphs = types.SimpleNamespace(cuda_graphs = ())
assert race.effective_verdict(graphed_win, 2, no_graphs)["promoted"] is True


def test_a_seeded_request_joins_only_when_every_size_it_could_render_at_is_exact(monkeypatch):
"""A streamed load (policy any) still admits the unmeasured sizes: one exact size 2 says nothing about 3-8."""
from core.inference.image_request_batching import batch_max

exact = {"promoted": True, "neighbour_exact": True, "replay_exact": True}
streamed = _engine(offload_policy = "sequential")
_verdicts(monkeypatch, {2: exact})
assert streamed.coalesce_seeded_ok(1024, 1024, 4.0, 1) is False
_verdicts(monkeypatch, {k: exact for k in range(2, batch_max() + 1)})
assert streamed.coalesce_seeded_ok(1024, 1024, 4.0, 1) is True
# A measured (resident) load admits only the winners: one exact size is enough there.
_verdicts(monkeypatch, {2: exact, 4: {"promoted": False}})
assert _engine().coalesce_seeded_ok(1024, 1024, 4.0, 1) is True


def test_an_eager_win_drops_the_graphs_dispatch_would_otherwise_replay(monkeypatch):
"""Dispatch never bypasses graphs: when the eager arm wins, the size's race-recorded graphs go, so requests run the
arm that was measured."""
monkeypatch.setattr(race, "record", lambda *a, **k: True)
dropped = []
flag = {"bypassed": False}
handle = types.SimpleNamespace(
set_bypass = lambda on: flag.update(bypassed = bool(on)),
drop_batched = lambda size: dropped.append(size) or 1,
)
generate, clock, _ = _fake_generate(
lambda rows: 1.0 if rows == 1 else (0.3 if flag["bypassed"] else 0.9) * rows
)
report = race.run_race(
generate,
types.SimpleNamespace(cuda_graphs = (handle,)),
idle = lambda: True,
width = 512,
height = 512,
sizes = (2,),
repeats = 3,
accuracy = False,
clock = lambda: clock["t"],
)
verdict = report["sizes"]["2"]
assert verdict["promoted"] is True and verdict["arm"] == "batched_eager"
assert dropped == [2]


def test_a_static_compile_limits_the_race_on_a_resident_or_graphed_load(monkeypatch):
"""Resident weights return serial (measurable) before the static-compile rule: the race must still skip sizes the
compile cache lacks."""
import core.inference.diffusion as diffusion_module

monkeypatch.setattr(diffusion_module, "compiled_shapes_are_static", lambda pipe, mode: True)
seen = {}
monkeypatch.setattr(race, "run_race", lambda *a, **k: seen.update(k) or {})
for extra in ({}, {"offload_policy": "sequential", "cuda_graphs": (object(),)}):
engine = _engine(
speed_optims = ("compiled",),
compile_cache_ctx = types.SimpleNamespace(shapes = [(512, 512, 2)]),
**extra,
)
seen.clear()
engine.batch_race(width = 512, height = 512)
allowed = seen["allowed_sizes"]
assert allowed is not None and allowed(2) and not allowed(4)