Repository navigation
[Perf] diffusion/worker: Move cyclic GC out of request execution - #46493
Merged
Merged
Conversation
mickqian
requested review from
AgainstEntropy,
BBuf,
HaiShaw,
kevin-mii,
niehen6174,
ping1jing2 and
yichiche
as code owners
October 26, 2026 02:27
Collaborator
Author
|
/tag-and-rerun-ci |
mickqian
requested review from
JustinTong0323,
sogalin,
wisclmy0611 and
zijiexia
as code owners
October 26, 2026 03:26
Contributor
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
This was referenced Oct 28, 2026
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.
Motivation
FLUX.2 Klein's first-request regression surfaced in #45919 but reproduces without its progress-reporting changes. A GC-instrumented H100 run captured a 449.5 ms generation-2 collection inside denoising. The CI bisection identified #46047 as the conditional trigger, not a Klein kernel regression.
This PR collects at initialization/warmup boundaries and prevents automatic cyclic GC from interrupting protected worker execution. With server warmup the extra cleanup is paid before readiness; with request-based warmup the first caller pays it. It does not modify #45919, performance thresholds, or GT.
Changes
Reference counting and explicit
gc.collect()still work. There is nogc.freeze(), threshold change, new CLI flag, or GPU allocator flush. GC can still run outside protected regions. Cyclic garbage may survive until a request finishes; the 30-second rule bounds continuous overlap, not a single long request. The drain can reduce overlap at that boundary.Validation
main(fd5c52588ff) at3f4a75b2809, retaining [Feat] diffusion/openai: Report per-step progress for async video jobs #45919's progress reporter alongside the GC guard. The only conflict was the import block.git diff --checkpass.quality=exact, server warmup, no torch.compile. Both arms use identical GC callback instrumentation and the same editable environment.The comparison below isolates the new request guard from the already-present startup collection (
a8b84ce6). The fixed measurement uses264d0863; the subsequent commit only fixes sequential warmup handling and its tests.Outputs are byte-identical. The throughput differences are below 0.3% and are not evidence of a meaningful steady-state speedup. The direct result is removal of GC from the protected path, not faster GPU kernels.
With async output saving, a further 600 requests per arm at concurrency 4 give 3.158 vs 3.165 req/s. Forward GC, including warmup, drops from 38 to 0. Peak reported GPU memory is 12,996 MiB in both arms; sampled whole-device usage is 14,789 MiB in both. Between the first and sixth 100-request batches, aggregate worker RSS grows by only 0.24/0.27 MiB. These are several-minute tests, not a production-duration leak proof.
Request-based and disabled warmup also pass real HTTP generation with unchanged output hashes and zero observed forward GC.
Z-Image-Turbo, 1024x1024, nine steps, 20 prompts at each concurrency, explicitly
--component-residency all=resident: current mainfd5c52588ffvs merged head3f4a75b2809gives 1.087/1.087 req/s at concurrency 1 and 1.112/1.112 req/s at concurrency 4. P99 is 923.70/926.37 ms and 3613.48/3607.57 ms, respectively. Per-request hashes match, and both report 23,714 MiB peak GPU memory (25,493 MiB sampled whole-device usage). Forward GC including warmup drops from 34 to 0; the main trace includes a full collection. This is neutral steady-state performance, not a speedup.The initial Z-Image auto-placement comparison is excluded from performance claims: downloading its metadata changed TE offload to resident. Explicit placement removes that confound.
Original Regression Evidence
The historical H100 tracing runs used separate runners with six ancillary package-version differences. They identify the GC stall, but are not a perfectly controlled same-host throughput comparison. The newer H200 comparison above uses one isolated device and unchanged packages.
CI States
Latest PR Test (Base): ✅ Run #40265313152
Latest PR Test (Extra): ❌ Run #40265313171
Latest PR Test (AMD ROCm 10): ❌ Run #40265313155