Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6fac8dc
Studio images: coalesce concurrent requests across accounts
danielhanchen Nov 26, 2026
80a7423
Studio images: coalesce plain text-to-image on /images/generate
danielhanchen Nov 26, 2026
d068da9
Studio images: let seeded requests join a batch behind an opt-in
danielhanchen Nov 26, 2026
a40d678
Studio images: serve the generation slot first come, first served
danielhanchen Nov 26, 2026
7d3e9d2
Studio images: keep per-account LoRAs and embeddings out of shared ba…
danielhanchen Nov 26, 2026
ad1d92c
Studio images: group batch members by what their family encodes per call
danielhanchen Nov 26, 2026
2428129
Studio images: one Stop rule for batched requests, across accounts
danielhanchen Nov 26, 2026
eae66f8
Studio images: no live preview for a batch shared across accounts
danielhanchen Nov 26, 2026
20b7f42
Studio images: batch a static-shape load only at sizes it already com…
danielhanchen Nov 26, 2026
17f3a29
Studio images: one member's failure no longer fails the whole batch
danielhanchen Nov 26, 2026
02a10ae
Studio images: a batch keeps its place in line; follow-up passes go f…
danielhanchen Nov 26, 2026
771a1f0
Studio images: record the shared call in recipes; pin coalesced calls
danielhanchen Nov 26, 2026
077bd66
Studio images: reserved batches get their own worker; tighter batch keys
danielhanchen Nov 26, 2026
e0e4311
Studio images: an idle reservation never stalls the line; recovery ke…
danielhanchen Nov 26, 2026
208b5a6
Studio images: CUDA-graph loads serve serially, and status says so
danielhanchen Nov 26, 2026
f4aaf9c
Studio images: poll review-test conditions by count, not by clock dea…
danielhanchen Nov 26, 2026
aa2e573
Merge origin/main into studio-image-concurrency
danielhanchen Nov 26, 2026
43ed7c3
Studio images: a leader whose Stop was acknowledged returns no images
danielhanchen Nov 26, 2026
97c4054
Studio images: test per-family batch grouping with interleaved arrivals
danielhanchen Nov 26, 2026
6659015
Studio images: read batch keys through private tokenizer copies
danielhanchen Nov 26, 2026
8b82bdf
Studio images: keep Qwen-Image-2.1 out of cross-account batches
danielhanchen Nov 26, 2026
ec19318
Studio images: coalesce across requests only when the denoiser stream…
danielhanchen Nov 26, 2026
e6a3595
Studio images: keep MOSS-Image out of cross-account batches
danielhanchen Nov 26, 2026
34029ec
Studio images: serve serially when the DiT scales activations per call
danielhanchen Nov 26, 2026
d27a985
Trim comments in image request batching
danielhanchen Nov 26, 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: CUDA-graph loads serve serially, and status says so
A CUDA graph replays one batch size: a coalesced call of a new size
captures inside the slot (seconds, plus its own memory pool) while every
other request waits, and an OOM split drops every graph. Serial graph
replay already keeps the card busy; a G4 FLUX.2 Klein trial with 4
clients measured 129.5 images/min serial against 127.1 batched.

- DiffusionBackend.request_batching reports how concurrent requests are
  served on the load: any, compiled_sizes (static compile, only batch
  sizes already compiled) or serial (CUDA graphs), with the reason.
- coalesce_batch_sizes follows it, so a graph load is serial by an
  explicit rule rather than by an empty compiled-size set.
- /images/status carries request_batching.

[skip ci]
  • Loading branch information
danielhanchen committed Nov 26, 2026
commit 208b5a6673f39ec7658896259fb200c2f436b25d
43 changes: 34 additions & 9 deletions studio/backend/core/inference/diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -18076,18 +18076,42 @@ def coalesce_plan(self, prompt: str, has_loras: bool) -> Optional[tuple[tuple, b
private = True
return prompt_key, private

def coalesce_batch_sizes(self, width: int, height: int) -> Optional[frozenset]:
"""Batch sizes a coalesced txt2img call may use at ``width`` x ``height``: None = any. A static compile or
CUDA graphs key their artifacts on the batch, so a new size would compile or capture inside the slot (and an
OOM split resets every graph): only sizes this load already compiled at this size are offered."""
def request_batching(self) -> Optional[dict[str, str]]:
"""How concurrent requests share calls on this load, for status: ``mode`` is ``any`` (any batch size),
``compiled_sizes`` (static compile: only batch sizes this load already compiled) or ``serial`` (CUDA graphs:
every request renders alone), with the reason. None when nothing is loaded."""
state = self._state
if state is None:
return None
if getattr(state, "cuda_graphs", ()):
# A graph replays one batch size: a new size captures (seconds, and its own memory pool) inside the slot
# while everyone waits, and an OOM split drops every graph. Graph replay already keeps the card busy,
# so a batch measured no faster than serial replay.
return {
"mode": "serial",
"reason": "CUDA graphs replay one batch size; concurrent requests render one at a time",
}
if "compiled" in (state.speed_optims or ()) and compiled_shapes_are_static(
state.pipe, state.speed_mode
):
return {
"mode": "compiled_sizes",
"reason": "static compile: concurrent requests share a call only at batch sizes already compiled",
}
return {
"mode": "any",
"reason": "concurrent requests with the same settings share one call",
}

def coalesce_batch_sizes(self, width: int, height: int) -> Optional[frozenset]:
"""Batch sizes a coalesced txt2img call may use at ``width`` x ``height``: None = any, empty = none (CUDA
graphs serve serially; ``request_batching``). A static compile keys its artifacts on the batch, so a new
size would compile inside the slot: only sizes this load already compiled at this size are offered."""
policy = self.request_batching()
state = self._state
if policy is None or policy["mode"] == "serial":
return frozenset()
static = bool(getattr(state, "cuda_graphs", ())) or (
"compiled" in (state.speed_optims or ())
and compiled_shapes_are_static(state.pipe, state.speed_mode)
)
if not static:
if policy["mode"] == "any":
return None
dims = (int(width), int(height))
shapes = getattr(state.compile_cache_ctx, "shapes", None) or ()
Expand Down Expand Up @@ -18503,6 +18527,7 @@ def status(self) -> dict[str, Any]:
tuple(getattr(state.pipe, "_unsloth_cuda_graphs", ()) or ())
or getattr(state, "cuda_graphs", ())
),
"request_batching": self.request_batching(),
"cfg_batch": cfg_batch_status(state.pipe),
"zimage_cfg_split": zimage_cfg_split_status(state.pipe),
"resolved": resolved,
Expand Down
6 changes: 6 additions & 0 deletions studio/backend/models/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -6507,6 +6507,12 @@ class DiffusionStatusResponse(BaseModel):
"denoiser calls (whole-step, per block, per-card segments, and the per-block graphs a whole-step graph falls "
"back to), and the process's dynamo frame and graph-break totals; null when nothing is loaded.",
)
request_batching: Optional[Dict[str, str]] = Field(
None,
description = "How concurrent text-to-image requests share pipeline calls on this load: mode 'any', "
"'compiled_sizes' (static compile, only batch sizes already compiled) or 'serial' (CUDA graphs, every request "
"renders alone), with the reason; null when nothing is loaded.",
)
loaded: bool = Field(False, description = "Whether a diffusion model is loaded")
evicted: List[str] = Field(
default_factory = list,
Expand Down
29 changes: 28 additions & 1 deletion studio/backend/tests/test_image_concurrency_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,9 @@ def test_the_engine_offers_only_compiled_batch_sizes_on_a_static_load(monkeypatc
assert engine.coalesce_batch_sizes(1024, 1024) == frozenset()
monkeypatch.setattr(diffusion_module, "compiled_shapes_are_static", lambda pipe, mode: False)
assert engine.coalesce_batch_sizes(512, 512) is None
# CUDA graphs serve serially, compiled sizes or not.
engine._state.cuda_graphs = (object(),)
assert engine.coalesce_batch_sizes(512, 512) == frozenset({1, 4})
assert engine.coalesce_batch_sizes(512, 512) == frozenset()


def test_a_batch_keeps_the_longest_arrival_prefix_that_fits(monkeypatch):
Expand Down Expand Up @@ -902,3 +903,29 @@ async def run_batch(
# The halves (size 2) are not admitted: every member falls back to rendering alone.
assert attempts == [4]
assert results == [None, None, None, None]


def test_status_tells_how_concurrent_requests_are_served(monkeypatch):
import core.inference.diffusion as diffusion_module
from core.inference.diffusion import DiffusionBackend

engine = DiffusionBackend()
assert engine.request_batching() is None
engine._state = types.SimpleNamespace(
speed_optims = (), speed_mode = "off", pipe = None, cuda_graphs = (), compile_cache_ctx = None
)
assert engine.request_batching()["mode"] == "any"
assert engine.coalesce_batch_sizes(512, 512) is None
engine._state.speed_optims = ("compiled",)
monkeypatch.setattr(diffusion_module, "compiled_shapes_are_static", lambda pipe, mode: True)
assert engine.request_batching()["mode"] == "compiled_sizes"
engine._state.cuda_graphs = (object(),)
policy = engine.request_batching()
assert policy["mode"] == "serial" and "CUDA graphs" in policy["reason"]
assert engine.coalesce_batch_sizes(512, 512) == frozenset()


def test_the_status_model_carries_request_batching():
from models.inference import DiffusionStatusResponse
status = DiffusionStatusResponse(request_batching = {"mode": "serial", "reason": "CUDA graphs"})
assert status.model_dump()["request_batching"] == {"mode": "serial", "reason": "CUDA graphs"}