Repository navigation
Studio diffusion: hold cudnn.benchmark off for FLUX.2 klein so a seed decodes the same image in every process - #14770
Conversation
…atch FLUX.2 klein decodes with the same VAE as FLUX.2-dev, which already holds cudnn.benchmark off. With it on, each process times the VAE convs once and can pick another algorithm, so the same seed decodes to different images in different Studio processes. On B200 (FLUX.2-klein-base-4B, 768x768, 12 steps, CFG 4, offloaded) the denoised latent was bitwise equal in all 12 fresh processes, CFG batching on or off, but 9 processes with the benchmark on gave 6 distinct images. With it off, 6 of 6 matched. The transformer has no convolutions, so only the VAE decode changes: warm decode 10.4 -> 10.8 ms at 768 and 15.9 -> 17.8 ms at 1024 on an exclusive B200.
…and Qwen-Image-Layered These families decode with VAEs whose cudnn.benchmark pick already split renders for flux.1 and qwen-image, but they kept the benchmark on. Decoding one fixed latent with Studio's VAE layer in 5 fresh B200 processes, with the benchmark on, gave 4 images for the FLUX.1 VAE (Kontext), 2 for the Qwen-Image VAE (Edit 2511) and 2 for the RGBA Qwen-Image VAE (Layered) at 768 px. With it off, each gave 1 image in 5 processes at both 768 and 1024 px. Warm 1024 px decode on an exclusive B200: Kontext 15.3 -> 17.1 ms, Edit 8.95 -> 14.7 ms, Layered 8.96 -> 14.7 ms. The FLUX.2 test now covers every family whose VAE was shown to split. [skip ci]
|
@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.
ℹ️ 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".
| filter_reduction_configs_archs = ((10, 0),), | ||
| # Same VAE as FLUX.2-dev: cudnn.benchmark's per-process conv pick decoded one latent into 6 images over 9 fresh | ||
| # B200 processes (base 4B, 12 steps, CFG 4); with it off all 3 matched, the denoised latent equal in all 12. | ||
| cudnn_benchmark = False, |
There was a problem hiding this comment.
Actually hold cuDNN benchmarking off during VAE decode
When torch.backends.cudnn.benchmark is already true—such as when a co-resident optimized pipeline enabled this process-global flag—this field does not make it false: apply_speed_optims merely skips _enable_cudnn_benchmark, and _cudnn_off_post only disables it when applied["cudnn_benchmark"] is true, which cannot happen for an opted-out family. A later co-resident load can likewise re-enable it before decode. Thus these newly opted-out families can still produce the per-process image variants this change is intended to prevent; the VAE decode needs a scoped disable or equivalent enforcement rather than only suppressing this load's enable call.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, the family flag only skipped this load's enable. Unloading restores the flag snapshot, so a sequential model switch was already fine, but a pipeline co-resident in the same process that had set the flag would leave an opted-out family's VAE on a per-process conv pick. Renders of an opted-out family now run inside cudnn_benchmark_scope(False), wrapped around the whole pipeline call, encode and decode included. A write from another load during the render goes to the scope's saved value instead of the live flag, and the prior value comes back when the render ends. New tests: the render of an opted-out family enters the scope around the pipeline call, and the scope forces the flag off when it was already on, leaves benchmark-keeping families alone and does nothing off CUDA.
FLUX.1 already pins inductor's reduction-config filter on sm80, sm89 and sm120, where cold-cache servers benchmarked near-tied norm reduction configs per process and rendered other images for one seed. B200 was left out as measured deterministic, but FLUX.1-schnell int8 under a 12 GiB cap with Studio defaults and a fresh inductor cache denoised one seed into 3 different latents over 15 fresh B200 processes (8, 5 and 2). With the filter engaged all 12 processes matched bitwise. cudnn.benchmark is already off for FLUX.1, and its VAE decode is stable across processes without it. Kontext runs the same DiT, so it pins on B200 too.
pre-commit.ci fails `ruff-format-with-kwargs` on every open PR (#14806, #14805, #14803, #14790, #14785, #14781, #14780, #14777, #14776, #14775, #14774, #14773, #14772, #14770, #14769, #14768, and others): "files were modified by this hook". pre-commit.ci runs the hooks on all files, and 20 files on main (26 by the time this lands) are not in the formatter's output, so every PR is reformatted outside its own diff. Where pre-commit.ci can push, its autofix commit drags those unrelated files into the PR (for example #14790's touches `tests/test_block_compile.py`, `tests/test_bnb_integration_compile.py` and `unsloth/models/_utils.py`). The drift came in with PRs merged today, among them #14702, #14751, #14759, #14784, #14786, #14787, #14788, #14791 and the FP8 block decode, GRPO routing replay, 4-bit decode, compiled blocks and MoE LoRA target changes. ### Change `python scripts/run_ruff_format.py` (the hook's own entry point, `ruff==0.6.9` as pinned in `.pre-commit-config.yaml`) applied to those 20 files, plus 6 more from #14739, #14779 and #14806, which merged while this was open. Formatting only. ### Verification - Every changed file parses to an identical AST before and after. - A second run of the hook over the same files changes nothing (fixed point), and over all tracked Python files on this branch it changes nothing. - `ruff check` passes on the changed files; `tests/test_formatter_fixed_point.py` passes (16). Open PRs pick this up on their next pre-commit.ci run after merging main.
…milies cudnn.benchmark is process-wide. A family with cudnn_benchmark = False only skipped turning it on at load, so a pipeline that was co-resident in the same process and had set it left the VAE convs on a per-process pick anyway. Sequential loads were fine (unload restores the snapshot), but a co-resident one was not. The render of an opted-out family now runs inside cudnn_benchmark_scope(False), which also keeps a write from another load in the meantime from reaching the flag, and the previous value comes back after the render. [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
# Conflicts: # studio/backend/tests/test_diffusion_backend.py
Summary
FLUX.2 klein (4B, 9B, base 4B, base 9B), FLUX.1 Kontext, Qwen-Image-Edit and Qwen-Image-Layered now hold
cudnn.benchmarkoff. FLUX.2-dev, FLUX.1 and Qwen-Image already do for the same VAEs. With the benchmark on, every Studio process times the VAE convolutions once and can settle on a different algorithm, so one seed renders different pixels depending on which process served it.What was happening
An offloaded FLUX.2-klein-base-4B render with CFG batching forced gave two different image digests on two runs of the same tree. CFG batching and the offload prefetch path were the first suspects. They are not the cause:
vae.decodewas bitwise equal in all 12 fresh processes (CFG batching forced, CFG batching off, cudnn benchmark on and off). The CFG batched step is bit-exact against the plain pair for this load.A VAE-only check (one fixed latent, 5 fresh processes per arm, Studio's own channels-last and fused-norm VAE layer):
Other families on the same VAEs
Same check for the VAEs loaded by FLUX.1 Kontext (FLUX.1
AutoencoderKL), Qwen-Image-Edit 2511 (AutoencoderKLQwenImage) and Qwen-Image-Layered (the RGBAAutoencoderKLQwenImage): one fixed latent, 5 fresh processes per arm.(distinct outputs over 5 processes)
Change
diffusion_families.py:cudnn_benchmark = Falseonflux.2-klein,flux.1-kontext,qwen-image-editandqwen-image-layered.test_split_vae_families_hold_cudnn_benchmark_offchecks that every repo whose VAE was shown to split (FLUX.2-dev, the klein variants, Kontext, Edit 2511, Layered, plus the unsloth mirrors) resolves to its family with the benchmark off. On main it fails for every repo except FLUX.2-dev, and it passes here. The opt-out set test, the family data freeze fixture and the autoopt parity fixture are updated. The parity fixture diff only dropscudnn_benchmarkfromappliedfor the 96 CUDA cases of these four families, which matches a live base-vs-head snapshot exactly.Cost
The transformer has no convolutions, so s/step is unchanged. Only the VAE decode moves. Warm decode on an exclusive B200, 3 fresh processes per arm, two interleaved arms each (median of 10 decodes, untiled):
For FLUX.2 that is about 2 ms per 1024 px image, under 0.1% of a guided base render and under 0.5% of a 4-step distilled one. FLUX.2-dev already pays the same trade. The Qwen VAEs lose about 6 ms per 1024 px decode, which is small next to a 20B DiT edit render and the same cost Qwen-Image already pays.
Testing
pytest tests/test_diffusion_speed.py tests/test_diffusion_family_data_freeze.py tests/test_diffusion_autoopt_core.py tests/test_diffusion_autoopt_parity.py tests/test_diffusion_qwenimage21_vae_layout.py: pass.test_native_audio(missing optional modules) andtest_mirrored_base_still_trips_the_flux2_shape_guard. Nothing new fails.