Repository navigation
Studio Images: run Detailer inpaints eager and uncounted - #15063
Merged
Merged
Conversation
Each Detailer detection inpaints at its own crop size. On a compiled load that recompiled the static SDXL U-Net per face, filled the per-module CUDA graph cap, counted as a generation (engaging the deferred compile mid pass) and fed crop shapes to the background compiler's recorder. Run every crop inpaint inside diffusion_bg_compile.auxiliary_pass(): force eager (with a gate so a whole-module compiled U-Net honours it), no graph capture, no recorded samples, no compile shape registered and no generation_count bump. Sizing and working resolution are unchanged.
Member
Author
|
@codex review |
1 similar comment
Member
Author
|
@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. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 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". |
danielhanchen
added a commit
that referenced
this pull request
Oct 27, 2026
…eager peak, honor force-eager (#15456) Two regressions from #15183 in `studio/backend/core/inference/diffusion_native_quant.py`. **Peak memory above eager.** The compiled W8A8 linear used a chunk budget of `1 << 27` elements, 4x the eager `1 << 25`, on the reasoning that it only holds the int32 accumulator. It also holds the output chunk at the same time, and the chunk outputs were then joined with `torch.cat`, so a large linear peaked above the eager path. For an 8192-row bf16 linear 3072 -> 14336 (Wan 2.2 5B sized) with rotation 256: 558 MiB before #15183, 672 MiB on main, so it runs out of memory with 650 MiB of headroom where the eager path fits. Now the fused budget equals the eager one and the chunks are written into one preallocated output with `copy_` (no list of parts plus a `torch.cat` copy). **Force-eager bypass.** `_forward_fused` checked Dynamo tracing and CUDA graph capture but not the shared `eager_forced()` flag from `diffusion_bg_compile`, so a cold native int8 linear inside the Detailer's `auxiliary_pass()` compiled a graph despite the #15063 contract. It now returns to the eager kernels while the flag is set. The same check also applies while a background compile is running, so those generations run the int8 linears eagerly for that window. Per-linear peak (MiB) and time (ms), shared card, 20-iteration means, so timings are indicative only: | shape (rows, in -> out), rotation | before #15183 | main | this PR | before ms | main ms | this PR ms | |---|---:|---:|---:|---:|---:|---:| | 8192, 3072 -> 14336, 256 | 558.06 | 672.02 | 392.00 | 1.58 | 0.58 | 0.74 | | 8192, 3072 -> 14336, 0 | 510.06 | 672.02 | 392.00 | 1.57 | 0.58 | 0.73 | | 8192, 14336 -> 3072, 256 | 400.01 | 336.02 | 132.00 | 1.80 | 0.55 | 0.67 | | 20000, 3072 -> 14336, 256, no bias | 1210.94 | 1093.75 | 729.23 | 3.76 | 1.56 | 1.70 | | 4096, 3072 -> 3072, 256 | 180.03 | 72.01 | 72.01 | 0.26 | 0.15 | 0.15 | Outputs are bit-identical across all arms on every shape. Inside `auxiliary_pass()`: main makes 1 fused call and 1 compiled graph, this PR makes 0 and 0, and the layer goes back to the fused path after the context exits. Tests in `test_diffusion_native_quant_fused.py`: chunks fill one output in row order, the fused peak never exceeds eager across widths, no fused call under `auxiliary_pass()` / `force_eager()`, and a CUDA test for peak at or below eager plus bit-equality. The CUDA skip guards use `has_real_cuda()`. Against main's module the new CPU tests give 5 failed, with this PR 21 passed, 4 skipped on CPU and all 25 passed on a GPU. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.
Summary
The Detailer (face fix) pass inpaints every detection at its own crop size. Today those inpaints go through the normal render path, so on a compiled load they:
This change runs Detailer inpaints as an auxiliary pass: eager, with no CUDA graph capture, nothing recorded for the background compile, no compile shape registered and no generation counted. The working resolution and sizing are unchanged (same
guide_size/max_size/crop_factormath). ComfyUI-Impact-Pack's FaceDetailer also renders each crop at its own size (core.enhance_detail:new_w = int(w * upscale), thentensor_resize, with no bucketing), and ComfyUI runs it eager, so this keeps output parity while removing the per-face compiles.Changes
diffusion_bg_compile.py:auxiliary_pass()context (sets force-eager and no-record, plus an auxiliary flag) andgate_compiled_eager(modules), which routes a whole-module compiled U-Net to its eager call while force-eager is set. Without the gate, force-eager only reached the guarded regional blocks and the graph wrappers, whose eager path still calls the compiled U-Net.diffusion.pygenerate: under an auxiliary pass, install that gate for the call, skip deferred speed engagement, skip the background compile note/kick and compile-cache shape registration, and do not bumpgeneration_count.diffusion_detailer.py: every crop inpaint runs insideauxiliary_pass().The SAM 3 park path is unchanged: skipping
empty_cacheafter parking is intentional (the comment records that the flush took minutes on a busy card, and the freed blocks stay available to the render in the same process).Tests
test_diffusion_detailer.py::test_every_inpaint_runs_as_an_auxiliary_eager_unrecorded_pass: each inpaint sees force-eager, no-record and the auxiliary flag; all are cleared afterwards.test_diffusion_cold_start.py::test_a_detailer_pass_neither_compiles_a_whole_compiled_unet_nor_feeds_the_recorder: a whole-module compiled net with an armed recorder takes 0 dynamo compiles and records no samples for 3 new shapes, and compiles normally once the gate is removed.test_diffusion_cold_start.py::test_a_whole_compiled_unet_under_the_gate_takes_no_cuda_graph: no capture throughGraphedCompiledCall, and the slot is restored.test_diffusion_cold_start.py::test_force_eager_alone_still_reaches_a_whole_compiled_module: control showing why the gate is needed.test_diffusion_backend.py::test_detailer_passes_neither_count_nor_engage_deferred_speed: 3 Detailer passes after 2 renders leavegeneration_countat 2 and do not engage; the next main render engages.The 4 new behaviour tests fail on main and pass with this change.
GPU check on a tiny SDXL pipeline (
hf-internal-testing/tiny-stable-diffusion-xl-pipe, default compiled tier with CUDA graphs): 2 main renders at 256x256, then 4 inpaints at 192x256, 320x256, 128x192 and 256x384, then 2 more main renders.generation_countafter the inpaints