Repository navigation
[staging CI] unslothai/unsloth#19667 - #4714
Closed
danielhanchen wants to merge 17 commits into
Closed
danielhanchen wants to merge 17 commits into
danielhanchen wants to merge 17 commits into
Conversation
The image batch key no longer holds the account, so requests from different users with the same model, adapters, size, steps, guidance, negative prompt and other render settings share one pipeline call. Each member still gets only its own images through its own future. - A shared Stop reaches only the leader's own account; members from other accounts render alone instead. - A member's own Stop leaves the batch (generation_rider), even while another account's call holds the slot. - Prompt-derived result fields are not shared across accounts. - A full batch stops collecting and the next request opens another. - UNSLOTH_STUDIO_IMAGE_BATCH_MAX defaults to 8; the engine's OOM halving still splits a chunk that does not fit.
The Studio Images page and bench clients call /images/generate, which never batched. A plain Create run (no init image, mask, reference images, ControlNet, Detailer, hires, upscale, variation seed, X/Y grid, prompt or seed lists, or prompt upsampling) now goes through the same coalescer as /v1/images/generations. - Every generate() argument other than prompt, seed and count is part of the batch key, so only renders that would match share a call. - An idle engine with no batch collecting renders at once with no extra status read, so a single user's latency is unchanged. - FLUX.3, Anima and layered models stay batch-1. - Queued jobs, X/Y cells and the chat image tool keep their own path.
Bench clients and recipe replays send a seed, so nothing coalesced for them. With UNSLOTH_STUDIO_IMAGE_BATCH_SEEDED=1 a seeded request joins a waiting batch and keeps the per-image seeds a lone request would use (seed, seed + 1, ...), passed per member through seeds=. Off by default: a batched render can differ slightly in pixels from the same seed rendered alone.
Waiting generations each polled the slot lock every 0.1 s, so the thread that happened to wake first won and a request could be overtaken by later arrivals. Each generation now takes a ticket on arrival and only the oldest waiter competes for the lock; the next ticket becomes the head as soon as one is admitted. Cancel and timeout behaviour is unchanged: a queued waiter still sees its cancel within 0.1 s and leaves the queue, a teardown fence still holds the head (which keeps its place), and the image queue drain still waits on direct runs as before.
…tches A batched call resolves LoRA ids, hosted adapters (with their HF token) and textual-inversion embeddings under the leader's account, and an embedding trigger matches in every member's prompt. A request that sets any LoRA, or whose account owns embeddings on a family that applies them, now carries its account in the batch key, so it batches only with its own account's requests.
Some families render a prompt differently, or gain nothing, inside a batch, so the batch key now carries a per-prompt group: - MiniMax-H3-Image loops per image when resident: never batched. - Qwen-Image-2.1 builds its RoPE layout from row 0: equal prompt token lengths only. - FLUX.1 / Kontext pad T5 to one bucket per call: 256 and 512 apart. - SD / SDXL weight and chunk prompts per call: prompt weighting and the 77-token chunk count must match. A prompt that cannot be measured renders alone.
- The Stop route stops this account's waiting and riding batched work before its foreign-generation early return. Under managed accounts a member riding another account's call saw that call as foreign, so its Stop answered cancelled: false while its images still saved. - cancel_generate applies one rule in every branch: Stop ends this account's denoising generation and all of its waiting and riding batched requests. - A Stop during a model change sets only the caller's queued requests; each queued cancel now records its account.
The preview decodes row 0 of each forward. An OOM split or a Qwen-Image-2.1 equal-length run can start a forward with another account's image, which the leader would then see. A batched call whose members come from more than one account now runs with the preview off; a batch of one account's requests keeps it.
…piled A static compile and CUDA graphs key their artifacts on the batch, so a coalesced call of a new size compiled or captured inside the slot while every other request waited, and an OOM split resets every graph. DiffusionBackend.coalesce_batch_sizes reports the batch sizes this load already compiled at the requested size (None when shapes are dynamic). A batch keeps the longest arrival-order run of members whose image total is one of them; the rest render alone.
- A failed batched call keeps the images that finished: the engine attaches them (in job order) to the exception, and the members whose images all finished get them instead of rendering again. Never after a Stop. - A ValueError, a memory refusal or an OOM that survived halving splits the remaining members in two and retries each half, so the member that caused it ends up rendering alone and only it sees the error. - A blank prompt, which fails validation for the whole call, renders alone.
…irst - A coalesced batch takes its slot ticket when it opens (reserve_slot_turn), so requests arriving while it collects members queue behind it, and a leader left alone renders in that place instead of at the back. - The waiting batch wakes from the slot itself (add_slot_listener on a release or a line change) instead of a 50 ms poll; a 250 ms timeout covers lock holders outside the line. - Follow-up passes of a request already admitted go to the front: X/Y cells after the first, Detailer crop inpaints (slot_follow_up), and the Detailer's segmenter pass (jump_slot_queue). The head of the line rechecks its place after taking the lock. The hires refine already runs inside its base pass's slot.
- Each coalesced image's recipe and gallery record carry coalesced_batch_size and coalesced_index: its pixels come from a forward of that size, so a solo replay of the seed lands close to it, not on it. Images rendered alone carry neither. - A coalesced call is always pinned to the load its settings were read for (expected_load), so a model swapped in while the batch collected is refused and each member retries, instead of every member rendering on the new model. [skip ci]
danielhanchen
force-pushed
the
pr-19667-xplat-ci
branch
from
November 26, 2026 03:13
a1b2da2 to
25ece0c
Compare
- A coalesced batch's own call (and a leader left alone) runs on a small dedicated pool. Its slot turn is first in line, while requests queued behind that turn could hold every worker of the shared image pool, so the batch could never start and nothing ran. - A variation request with a random subseed (variation_strength set, no variation_seed) renders alone: per-member seeds would replace the base seed it repeats across its images. - The SD / SDXL batch key counts the conditioning chunks the weighted encode actually builds (tokenize_chunks, BREAK and comma backtracking included) in every CLIP encoder, weighted and unweighted, so a member is never padded with an extra empty chunk.
…eps admitted sizes - A reserved slot turn that sits first in line, unclaimed, with the slot free steps back one place after 0.5 s. If every worker of an executor waits behind it, its owner may have no worker to run on; the waiters now step past it and the queue drains on any pool, not only on the dedicated batch pool. - Failure recovery consults the static batch-size filter on every split: a half whose size this load has not compiled keeps only its admitted prefix, and the rest render alone. [skip ci]
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]
danielhanchen
force-pushed
the
pr-19667-xplat-ci
branch
from
November 26, 2026 05:05
25ece0c to
63a5733
Compare
danielhanchen
force-pushed
the
pr-19667-xplat-ci
branch
from
November 26, 2026 05:22
63a5733 to
07acb18
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Disposable CI run for unslothai#19667. Do not merge; closed after CI.