Repository navigation
Studio images: family batch adapters, measured batching race and per-size CUDA graphs #19837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b24c827
28a9ecb
f437380
58e0db6
6c55fd6
f5b1cec
e8879fb
731542d
a8e5e17
9f0b357
51c1217
bae160e
95de9ec
fe47b92
1a97100
53efa94
8ca902e
3221b2c
92efbc1
705da24
0d7d96d
395de8b
e5b8e38
71e85dc
67a7dcd
0dac8dd
7859edb
9173835
6e6b15b
6332acb
9993ecd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
A graphed race verdict admits its size only while the load holds that batch-size graph; otherwise the eager arm's own verdict applies, with seeded joins off. Batched recording is refused on offloaded loads, and an OOM while recording one runs the call like the other unrecorded shapes. The admission estimate is k times the size-1 graph's own pool growth, with free memory read on the operands' card. A batched key that a size-1 call replays becomes a size-1 graph, and a placement change clears the batched and edit labels. [skip ci]
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -537,7 +537,8 @@ def batch( | |
| break | ||
| report["sizes"][str(size)] = verdict | ||
| if not verdict.get("promoted"): | ||
| # A losing size never runs batched here: its graphs would only pin pool memory. | ||
| # 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). | ||
| dropped = 0 | ||
| for handle in handles: | ||
| drop = getattr(handle, "drop_batched", None) | ||
|
|
@@ -585,6 +586,42 @@ def _neighbour_check(solo, batch, prompts: list, seeds: list, *, eager: bool) -> | |
| } | ||
|
|
||
|
|
||
| def batched_graph_sizes(state: Any) -> Optional[set]: | ||
| """Batch sizes every recording graph handle of this load holds a graph for now; None when the load has no graphs.""" | ||
| handles = list(getattr(state, "cuda_graphs", ()) or ()) | ||
| if not handles: | ||
| return None | ||
| held = None | ||
| for handle in handles: | ||
| batched = getattr(handle, "_batched", None) or {} | ||
| cache = getattr(handle, "cache", None) or {} | ||
| sizes = {int(v) for k, v in batched.items() if k in cache} | ||
| held = sizes if held is None else held & sizes | ||
| return held or set() | ||
|
|
||
|
|
||
| def effective_verdict(verdict: dict, size: int, state: Any) -> dict: | ||
| """The verdict as it applies now: one won on the graphed arm holds only while that batch-size graph exists (user | ||
| calls never record one); otherwise the size is admitted only if the eager arm passed on its own.""" | ||
| if not isinstance(verdict, dict) or verdict.get("arm") != "batched": | ||
| return verdict | ||
|
Comment on lines
+858
to
+859
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If a size wins on the eager arm at canvas A, then a later race wins on the graph arm at canvas B with the same tensor shapes (for example, the same dimensions and guidance but a different step count), this early return still admits A as eager. The second race has installed a graph that Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 6332acb. |
||
| held = batched_graph_sizes(state) | ||
| if held is None or int(size) in held: | ||
| return verdict | ||
| eager = (verdict.get("arms") or {}).get("batched_eager") | ||
| if isinstance(eager, dict): | ||
| # The neighbour check ran on the graphed arm: it vouches for nothing here, so no seeded joins either. | ||
| return dict( | ||
| verdict, | ||
| promoted = bool(eager.get("promoted")), | ||
| arm = "batched_eager", | ||
| graph_missing = True, | ||
| neighbour_exact = False, | ||
| replay_exact = False, | ||
| ) | ||
| return dict(verdict, promoted = False, graph_missing = True) | ||
|
|
||
|
|
||
| def seeded_join_ok(verdict: Optional[dict]) -> bool: | ||
| """A seeded request may join a batch of this size only when the measured path is neighbour-exact (G2a) and its | ||
| row replays bit for bit from the seed alone (G2b): otherwise the returned seed would not reproduce the image.""" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After an adapter-free resident load records an eager batching win with a quality PASS, the same verdict also authorizes batching when LoRAs are subsequently applied or the model is reloaded with adapters:
load_key()excludes adapters, and this lookup never checks_race_adapters_active(). The refusal inbatch_race()only prevents measuring adapted loads; it does not prevent consuming the base model's verdicts. Consequently, an otherwise serial adapted load can enter measured batching, including automatic explicitly seeded joins based on the base model's bit-exact checks. Reject adapter-bearing loads and requests when consuming these verdicts, or include the adapter selection in the measurement identity.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 6e6b15b.
_measured_sizesnow returns no verdicts when the load carries adapters with a non-zero weight (applied, baked in, or requested at load, the same check the race uses to refuse). An adapted load therefore keeps today's rules: a resident or graphed load serves one request at a time, a streamed load keeps its unmeasured default, andcoalesce_seeded_okis False, so an explicitly seeded request never joins on the base model's exactness. A zero-weight adapter still reads the base verdicts. New testtest_an_adapted_load_never_consumes_the_adapter_free_verdictsfails before the change.