Repository navigation
Studio: decode the FLUX.2 / FLUX.3 VAE in row strips (36-43% less decode VRAM, same speed) - #17202
Merged
Merged
Conversation
…decode VRAM) GroupNorm statistics stay global; normalisation, SiLU, edge padding and the 3x3 convs run on bounded row strips with a one-row halo, so no normalised activation exists at full size. Equal-channel residual blocks add into their input in place, channel-halving blocks write their output into the front half of their input's storage, each level shares one hidden buffer that cuDNN writes without a strip copy, and upsample and the final norm/conv also run in strips. NVIDIA CUDA only, eager only, small tiles keep the fused path. Kill switch UNSLOTH_FLUX_VAE_STRIPS=0. The tile planner prices the strip decode with its own figure.
T4 (sm75) and L4 (sm89) take the strip decode for every FLUX.2 / FLUX.3 decode; other cards (A100 measured 4% slower) take it only for a decode the fused path would not fit in the free VRAM, the tile planner's own rule, where the alternative is more tiles. UNSLOTH_FLUX_VAE_STRIPS=1 forces it on any NVIDIA card, 0 turns it off.
Codex Review Summary: ✅ CompletedThis 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 |
1 similar comment
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
Nov 9, 2026
…uff-unsloth wheel (#17211) ## Summary The Backend CI step that installs the pinned `ruff-unsloth` wheel retries 3 times with 5 s and 10 s gaps. Between 05:19 and 05:40 UTC today, GitHub served intermittent 504s for the release asset, and every attempt of an unlucky job landed inside one burst. That turned `Repo tests (CPU, fsdp2 / gloo-cp / gloo-pp / gloo-tp / rest / studio-install)` red on #17188, #17191, #17197, #17201 and #17202, while sibling jobs in the same runs installed the wheel fine a minute later. This raises the loop to 6 attempts with exponential backoff (10, 20, 40, 80, 160 s, about 5 minutes total). A healthy download still never sleeps, and a lasting outage still fails the job with the same `::error::` line, so the fixed-point formatter guard keeps failing loudly in CI when the wheel is truly unavailable. ## Changes - `.github/workflows/studio-backend-ci.yml`: 6 attempts, `sleep $((10 << (attempt - 1)))`. - `tests/test_ruff_unsloth_install_retries.py`: runs the step's own `run:` script under bash with `pip` and `sleep` faked on `PATH`, and checks that - 5 failed downloads in a row still install, after at least 300 s of backoff, - a download that never recovers still fails the job, in under 10 minutes, - a healthy download does not wait at all. ## Testing - `pytest tests/test_ruff_unsloth_install_retries.py`: 3 passed. - Against the old step from `main`, the burst test fails with `ruff-unsloth install failed after 3 attempts`. - The other tests that read `studio-backend-ci.yml` pass.
[skip ci]
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.
What
FLUX.2 and FLUX.3 decode through
AutoencoderKLFlux2. Studio's fused VAE path already fuses GroupNorm, SiLU and the bias/residual adds, but each residual block still materialises full-resolution intermediates. Each GroupNorm+SiLU output and each conv output exists at full size, so a 2048x2048 bf16 decode peaks at 5.6 GiB.This PR adds
diffusion_vae_strips.py, a row-strip decoder for that VAE, installed on top of the fused kernels:group_norm_stats). Normalisation, SiLU, the edge padding and the 3x3 conv then run on bounded row strips with a one-row halo. A normalised activation never exists at full size.[a, b)overwrite input rows[a/2, b/2), which only earlier strips read.cudnn_convolution.out, so no strip copy is made.The same idea is in the baseline. It computes global GroupNorm statistics, then does row-strip norm/SiLU/pad/conv with a decoder scratch buffer reused across levels.
Where it is on by default
runtime_ok)UNSLOTH_FLUX_VAE_STRIPS=0turns it off.=1uses it for every decode on any NVIDIA card. The decode stays eager. WhenUNSLOTH_COMPILE_VAEforces the compiled decode, the fused path, and with it this one, is not installed. The strip path also falls back whentorch.compiler.is_compiling(), so it adds no graph breaks or recompiles. Any non-OOM exception switches that VAE back to the fused path for good. An OOM propagates to the existing OOM retry, which decodes in smaller tiles.Tile planner
diffusion_vae_tilingprices the strip decode with its own figure. The peak is0.048 MiB per latent + four strip buffers(16-bit), which bounds every measured tile side from 48 to 256. Tiles that keep the fused path keep the fused 0.09 figure. The untiled-shortfall check indiffusion.pyuses the same figure. FLUX.2 / FLUX.3 VAE, same free VRAM after the fp32 accumulator:Numbers
Real FLUX.2-klein VAE weights (the VAE FLUX.3 ships). The latent comes from encoding a real photo. This is decode-only time (CUDA events), untiled, 5 interleaved repeats after 2 warm-ups. BEFORE is current
main(merge base) on its own VAE instance. The kill-switch arm is this PR withUNSLOTH_FLUX_VAE_STRIPS=0, which gives a second base sample (A/A).Median ms [min, max]. Peak = max allocated during the decode, over what was allocated before it. Reserved = allocator peak.
=1)=1)The A100 rows are why A100 does not take the strip decode by default.
Policy on a card outside the always-on list was checked on a T4 with that list emptied, fp16, 2048^2.
uninstallrestores the stock decoder forward.Strip size is chosen per card: 2^24 elements on sm80+, 2^26 on Turing, whose implicit-GEMM convs lost 5-10% on shorter strips. That is why T4 fp16 saves less at 1024^2.
Per-latent decode peak (bf16, L4 and A100 identical), main vs this PR, by tile side: 32: 0.086 vs 0.086 (fused path kept), 48: 0.086 vs 0.078, 64: 0.086 vs 0.078, 96: 0.086 vs 0.060, 128: 0.086 vs 0.055, 160: 0.086 vs 0.052, 256: 0.086 vs 0.049 MiB.
Output error is at the rounding floor. Against a stock fp32 decode of the same latent, this PR's mean-abs error equals main's to 3 significant digits, and its max-abs and LPIPS are no worse.
The kill switch is bit-identical to main on every arm.
Tests
studio/backend/tests/test_diffusion_vae_strips.py, CPU: the strip decoder with its Triton launches swapped for torch references matches the stock decoder in fp32 (max-abs 3e-6). This covers three channel layouts (equal blocks, 2x halving in place, a 4x shortcut transition), odd latent sizes (9x13, 5x17, 1x3), and one-row strips that exercise every halo, edge pad and the halving overwrite order. The tests also cover the halving block writing inside its input's storage, structural gating (padding, upsampler kind, accelerate hooks), install gating (CPU, env, other classes), the card / free-VRAM policy, and planner pricing.AutoencoderKLFlux2against main and against a stock fp32 decode. That is 90 cases per card: 3 configs x fp32/fp16/bf16 x 5 latent sizes, at both 2^24 and 2^13 element strips. This PR's error against fp32 matches main's in every dtype. Kill switch: 0.0 on all.