Repository navigation
Studio diffusion: price the compiled tier's requests from its own learned peak (offloaded bf16 keeps its residency after compile) - #15198
Conversation
…rned peak The deferred profile marked the load's reserve static, so every compiled render sized itself from the flat estimate and streamed resident groups again (3840 MiB on FLUX.1-schnell bf16 at an L4's 24 GiB). The compiled tier now records its own learned peak, keyed by the CUDA graph mode it runs (stable across the first capture), and the request guard prices compiled renders from it, never below the eager pricing. Until that tier has a measurement the flat estimate stands in. A graph captured over a release keeps that release while it is live, so no graph is re-captured. UNSLOTH_DIFFUSION_TIER_PEAKS=0 restores the flat estimate.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 73a8c15c2d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| totals = cuda_graph.stats(handles) | ||
| if totals.get("graphs"): | ||
| return armed | ||
| if totals.get("captures") or totals.get("poisoned") or _graphs_settled_eager(state): | ||
| return "off" |
There was a problem hiding this comment.
Account for per-block fallbacks in the tier graph identity
When a whole-step graph is dropped and its fallback_handle starts running per-block graphs, cuda_graph.stats(handles) only inspects the top-level handles. Consequently, this returns off despite live per-block graphs; if the original graph remains cached, it instead returns step. This fallback is installed by _attach_block_fallback and activated by GraphedForward._engage_fallback. Because _follow_live_graph_mode now writes this result into the peak identity and _tier_request_peak uses it for request pricing, per-block execution can consume or record a peak belonging to a different graph mode, potentially under-reserving memory. Inspect the fallback handles and distinguish their execution mode before selecting the learned-peak key.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed. On the deferred profile's tier _attach_block_fallback arms a per-block fallback whenever the denoiser stays on the device (not hooked, or pinned resident), and on a streamed one with UNSLOTH_DIFFUSION_BLOCK_GRAPHS=1. Once the whole-step graph drops, _engage_fallback routes its calls through fallback_handle, which cuda_graph.stats() does not inspect, so the tier read off (or step while the old graph was still cached). _tier_graph_mode now reports its own step_blocks mode while a fallback is engaged, so those renders neither read nor record the step / off peaks; until that mode has its own learned peak they price from the flat estimate, as before. _live_graph_mode and non-deferred loads are unchanged. Added test_an_engaged_per_block_fallback_keys_its_own_graph_mode; the tier-peak, graph and memory suites pass (1957 passed, 159 skipped).
…tier graph mode A whole-step graph that dropped hands its calls to per-block graphs held as fallback_handle, which cuda_graph.stats() does not inspect, so the tier read off or step for them. Report step_blocks while a fallback is engaged so it neither reads nor records the step / off peaks. [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
[skip ci]
Summary
On an offloaded dense bf16 load, the deferred speed profile (compile on the 3rd image) made every compiled render keep less of the DiT resident than the eager renders did.
streaming 3840 MiB of resident groups for an oversized requestand kept 4321 MiB fewer. The image-3 denoise moved 53.3 GiB host to device, against ComfyUI's 17.8 GiB._unsloth_peak_static. That sends every later request inmeasured_request_extra_mibto the flat estimate, 8192 MiB for FLUX.1 at 1024x1024, against the 4352 MiB the load reserved. The compiled tier also never recorded a learned peak of its own:graphs:offwhile the renders rangraphs:step;Changes
_tier_graph_mode). That mode stays the same through the first capture: the armed mode until the graphs are captured and then dropped, or settle eager, thenoff. So the render that captures the graph records, and the renders after a dropped graph record undergraphs:off.measured_request_extra_mibtakestier_peak_mib, which is read only under the live compiled key, graph mode included (_tier_request_peak)._hold_captured_release), because graphs key on weight addresses. Once no graph is live, the measured peak places the renders._learned_peak_keys/_learned_peak_for_keys, shared by the whole-module per-request path (unchanged: eager keys still stand in there) and the guard (eager_stand_in = False).UNSLOTH_DIFFUSION_TIER_PEAKS=0restores the static reserve and the flat estimate.Results
Local B200 with an L4-sized cap: the planner sees 23034 MiB, of which 450 MiB is held by others, and the caching allocator is capped there. FLUX.1-schnell bf16 (
transformer_quant=none), 1024x1024, 4 steps, a new prompt per render, 9 timed renders plus 1 profiled render per process, fresh learned-peak store per process. Timing arms had an exclusive lease. Base is the merge base 3bf5e85.Session 1 is a first session (empty store). Session 2 reuses the store a session-1 process wrote.
replay measured slower than the eager step), so renders from image 8 keep it all;Compiled peak above eager (still handled). Every compiled denoiser forward holds 6000 MiB more (a pre-hook allocation), graphs off:
The flat estimate under-prices this request, and head streams more to cover it. With graphs on, the graph captured over the 3840 MiB release stays live on that run, so head keeps that release. No arm hit an OOM.
Other family: Qwen-Image-2.1 bf16 at the same cap, 8 steps. The transformer stays resident in both arms. The renders, the H2D (14.1 GiB), the graph capture and the dynamo counts (3 frames, 488 calls) are identical to base. Head also records the compiled tier's 3061 MiB peak.
Tests
tests/test_diffusion_tier_peaks.py(21 tests):_tier_graph_modeacross capture / drop / poison / decline;Limits