Repository navigation
[Diffusion] Enable lossless BCG for FLUX.1-dev - #38591
Merged
Merged
Conversation
BBuf
requested review from
AgainstEntropy,
HaiShaw,
JustinTong0323,
mickqian,
ping1jing2,
sogalin,
wisclmy0611,
yichiche and
zijiexia
as code owners
September 9, 2026 01:43
Collaborator
Author
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
Enable native FLUX.1-dev breakable CUDA graph execution for lossless requests.
--enable-breakable-cuda-graphpreviously disabled itself for this model; the existing runner now captures its DiT segments and replays them for warmed shapes.On 2× H200 at 1024×1024 / 50 steps, two A/B/B/A rounds reduce warmed engine E2E from 4.315577 s to 4.177754 s (-3.194%), and denoise from 4.119540 s to 3.911356 s (-5.054%). All eight formal PNGs are byte-identical. Peak reserved memory rises from 19.473 GiB to 20.707 GiB in the rank-0 perf dump.
The implementation adds FLUX.1-dev model IDs and
FluxPipelineConfigto the existing support checks. FLUX keeps its unmasked, fixed 512-token T5 conditioning, so the generic runner can copy fresh conditioning/timestep/guidance inputs into the captured buffers. Existing TP graph registration, signature fallback, and quality-fusion checks apply. The patch also adds warmup/model-reference and conditioning-shape tests, plus a cookbook example.Benchmark
black-forest-labs/FLUX.1-devat checkpoint3de623fc3c33e44ffbe2bad470d0f45bccf2eb21; BF16, TP2 on the same two H200 GPUs throughout.2.13.0+cu130, Triton3.7.1, driver595.71.05; loaded NCCL reports2.28.9.quality=lossless,dit=resident, other component residencyauto;torch.compiledisabled.A futuristic cyberpunk city at night, neon lights reflecting on wet streets.482e9f257bb9d9ac57c2245c93768a96ec70edbe, eager. Measured candidate:5e91bc39e7a421be979448661b1b5d93db35cb48, BCG. Final head3d51468a54b8fad047b1d679c0968ac2919613e7adds only tests/docs; its runtime file is byte-identical to the measured candidate.Per-round E2E reductions are 4.771% and 1.620%. Round 2 B1 spent 371.106 ms in text encoding versus roughly 98–102 ms in neighboring requests; that sample remains in the aggregate. No samples were discarded.
All benchmark rows and conditions · raw perf dumps and scripts
Profile comparison
The paired full-stage traces cover two denoise steps on rank 0, using the same checkpoint, shape, prompt, seed, topology, and respective source commits. Overlapping GPU stage annotations are unioned; no selected kernel crosses a stage boundary.
cudaGraphLaunchcallsBCG reduces recurring host launches; the cumulative device time does not improve. Most GEMMs, attention, and existing fused LN/modulation kernels keep their counts. The existing graph-aware custom all-reduce path changes from 228 push calls to 152 pull + 76 push calls. Collective durations include rank waiting, so they are not interpreted as pure communication bandwidth. The profiled CPU durations are diagnostic and differ substantially from the unprofiled timings above.
Eager profile digest · BCG profile digest. Raw trace sizes and SHA-256 hashes are recorded in those digests.
Existing FLUX optimizations from #34126, #34004, #33819, and #33818 were reviewed before choosing the graph replay path. Their fused arithmetic and quality gates are reused.
Output comparison
All eight 50-step benchmark PNGs have SHA-256
a713777ad67b4e82915aef972612f243d6f4cbd8db9aebdfdff976b4c7d2c7d3.All saved benchmark images · Replay correctness results
On final head, persistent native generators at TP1 and TP2 each served six requests across three warmed resolutions, changed prompts and seeds, repeated an earlier request, then requested one deliberately uncaptured resolution. All 12 eager/BCG image pairs (24 PNGs) are byte-identical within their respective topology. Each rank captured exactly three graphs at warmup, with zero serving recaptures; only the final 640×512 request used the expected eager fallback. These six-step images validate replay state and are separate from the 50-step performance rows.
quality=high + BCGwas tested and rejected by the existing DiT fusion compatibility check. The graph captures the lossless branches, so this PR does not claim high/extra-high BCG support. The baseline high eager image has SSIM 0.975800 and PSNR 32.3649 dB against lossless on this prompt; that separate existing quality tradeoff is not used in the lossless speedup.Reproduce
Use an
HF_TOKENwith access to the checkpoint. Run on each pinned source checkout and keep the same GPUs and request parameters:For BCG, add
--enable-breakable-cuda-graph --warmup-resolutions 1024x1024and use distinct output/perf filenames; the runtime automatically changes warmup mode toserver. Run A/B/B/A twice. For diagnostic traces, use two steps and add--profile --profile-all-stages; compare unprofiled requests for latency. The cookbook documents warmed resolution matching and the additional startup/graph memory cost.Validation
Other FLUX variants, quantized transformer overrides, and other hardware require their own validation.
CI States
Latest PR Test (Base): ✅ Run #34300355195
Latest PR Test (Extra): ✅ Run #34300355947
Latest PR Test (AMD ROCm 7.2): ❌ Run #34300355213