Repository navigation
Studio FLUX.3 Klein on T4: run edits, and no slower step CUDA graph over int8 linears - #17949
Conversation
…he measured row, so a FLUX.3 Klein edit runs on a T4 On a T4 (fp16) FLUX.3 Klein loads int8 with the transformer resident from the measured activation row. A reference edit at the default 1248x832 is conditioned, so the generate guard skips the default-resolution exemption and the tiled estimate charged the one 1024 px VAE tile at the flat 8192 MiB per megapixel (6.5 GiB + 2 GiB overhead vs 5.7 GiB usable) and refused an edit that runs at 8.6 GiB allocated on the 15 GiB card. The guard now caps that tile at the family's measured tiled decode (same speed tier and compute width the load placed from, read from _unsloth_measured_reserve). It never prices higher than before; uncalibrated placements and families without a measured row are unchanged.
… when the load kept no measured reserve FLUX.3 Klein Base on a T4 places from the measured row but records no _unsloth_measured_reserve (no phase seed), so its 1248x832 edit still met the flat VAE tile price and was refused. The generate guard now reads the same row the plan read (_calibrated_activation with the fp32 scaling the load applies) when the placement is calibrated and no reserve exists.
…ative int8 linears run compiled The compiled W8A8 function (rotate, quantise, int_mm, rescale in one inductor graph) never runs inside a CUDA-graph capture, so a captured step bakes the eager kernels instead. On fp16 cards the whole-model compile is declined for FLUX.3, so Speed default / max captured the step over the eager path: a T4 rendered FLUX.3 Klein int8 at 42.5 s per image against 34 s at Speed off, same pixels. The step graph is now declined there (status says why); UNSLOTH_DIFFUSION_STEP_GRAPH_NATIVE_W8A8=1 keeps it. A compiled denoiser and loads without native act-int8 linears are unchanged.
|
@codex review |
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 55e56a376c
ℹ️ 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".
| tile_scale = max(0.25, min(w, side) * min(h, side) * vae_batch / megapixel) | ||
| vae = min(vae, max(1024, int(measured.tiled_decode_mib * tile_scale))) |
There was a problem hiding this comment.
Normalize decode scaling to the family's measured tile size
For Qwen-Image-2.1, the calibration table explicitly records tiled decode using 512 px tiles, but this calculation scales that already-tiled measurement by another 512²/1024². For example, a 1152×1024 request with 512 px tiles now estimates only 1152 MiB of tiled runtime, below the row's 2036 MiB measured decode even though the output is larger than the calibration canvas and the tile size is unchanged. Previously this request was priced at 2048 MiB. This can admit requests under tight memory budgets that the guard previously refused. Scale relative to the tile dimensions used for each family's calibration rather than assuming every measured decode used a 1024 px tile.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ebd98da: the measured tiled decode now scales against the tile side each family's row was measured with (512 px for Qwen-Image-2.1, the default otherwise), so a 512 px Qwen tile is priced at the measured row, not a quarter of it. New test test_qwen_tiles_are_priced_against_the_512_px_tile_they_were_measured_with fails before and passes after.
| if _FUSED_STATE["failed"] is not None or int8_fused_disabled(): | ||
| return False |
There was a problem hiding this comment.
Check device-specific fused failures before declining graphs
After a fused W8A8 compilation or execution failure on a CUDA card, _fused_w8a8_failed() records the failure in _FUSED_STATE['devices'], not _FUSED_STATE['failed']. This helper only checks the latter, so subsequent model loads on that card still report that fused W8A8 serves the denoiser and disable its step graph, while _fused_w8a8() permanently returns None for that device. Those loads therefore lose graph acceleration without receiving the compiled-linear acceleration that justified disabling it. Include the relevant device's failure state in this eligibility check.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ebd98da: fused_w8a8_serves now reads the per-card failure in _FUSED_STATE['devices'] for the cards the native int8 linears sit on (the current card for offloaded weights); a card whose compiled linear failed keeps its step graph. New test test_a_card_whose_compiled_linear_failed_keeps_its_graph fails before and passes after.
…ed tile side; a card whose compiled W8A8 failed keeps its step graph [skip ci]
|
@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". |
…ured tile side; decline the step graph over eager W8A8 on fp16 cards only [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! 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". |
…fusion red on main) (#17974) ## Summary `(Python 3.13, diffusion)` is red on main (seen on the staging runs of #17966 and #17971): ``` studio/backend/tests/test_diffusion_flux3_fp32_calibrated.py::test_only_the_load_plan_reads_the_scaled_table E assert 2 == 1 ``` The test pinned that the scaled (float32) activation row, `_calibrated_activation(..., fp32_scaled = True)`, is read in exactly one place in `DiffusionBackend`: the load plan. #17949 (FLUX.3 Klein on T4) added a second read in the generation guard: ```python guard_measured = placement_measured_activation(state.pipe) if guard_measured is None and getattr(state, "calibrated_placement", False): guard_measured = _calibrated_activation(fam, guard_target, fp32_scaled = True) ``` That read re-uses the same row the calibrated placement was sized from, so the guard and the plan agree. It is intended, and it keeps what the test protects (an uncalibrated or post-load reader never sees the scaled row). The string count was just too blunt. ## Change Test only, `test_only_the_load_plan_reads_the_scaled_table`, now walks the AST instead of counting a substring: - exactly two `fp32_scaled=True` reads in `DiffusionBackend`; - one is the load plan's `calibrated_activation=` argument (still pinned verbatim); - the other must sit under an `if` whose test checks `calibrated_placement`. ## Testing - `test_diffusion_flux3_fp32_calibrated.py`: 10 passed. On main the test fails as above. - Sabotage: dropping the `calibrated_placement` condition from the guard fails it; adding a third scaled read fails it.
Summary
Two FLUX.3 Klein problems on GPUs without bfloat16 (T4 class), found running FLUX.3 Klein and Klein Base on a real Colab T4:
Changes
diffusion_memory.py:estimate_tiled_image_runtime_mibtakes the measured activation row the placement was sized from and caps the flat one-tile VAE figure with the row's measured tiled decode, scaled by tile area.placement_measured_activation(pipe)reads that row from the load's recorded reserve.diffusion.py: the generate guard passes that row; when the load kept no measured reserve on a calibrated placement, it reads the same row the plan used. Only calibrated placements change; unknown keeps the flat estimate.diffusion_speed.py/diffusion_native_quant.py: on fp16 cards, the step CUDA graph is declined over an uncompiled denoiser whose native int8 W8A8 linears are served by the compiled function (fused_w8a8_serves: CUDA, not ROCm, inductor available, not disabled, not failed on that card). bf16 loads keep their graph unchanged.UNSLOTH_DIFFUSION_STEP_GRAPH_NATIVE_W8A8=1keeps the graph.Results
Real Colab T4, FLUX.3 Klein int8, 1024 x 1024:
bf16 card (Colab RTX PRO 6000), main and this PR alternated twice: text-to-image is bit-identical, 1.45 s per image both ways, the same 3 compiled graphs and no recompiles; edit differs by LPIPS 0.0011 to 0.0013, the same as two main runs differ from each other (0.0011), 3.24 s both ways. A second bf16 card (A100): all four images (two text-to-image, two edits) byte-identical between main and this PR, 2.54 vs 2.55 s per image.
A100 with bf16 disabled (Studio sees a T4), Klein 1024, 16 steps: Speed Off 3.79 s, Speed Default on main 5.77 s, Speed Default / Max with this PR 3.70 / 3.71 s, identical pixels across all four.
Guard matrix
570,240 guard inputs (11 families x sizes x batch x free memory x tile side x slicing x references x ControlNet x speed tier x compute width x calibrated or not), main vs this branch in separate processes: 4,190 cells move from refuse to tile, none the other way; uncalibrated placements and uncalibrated families never change; no family is priced below its own measured tiled decode.
Tests
tests/test_diffusion_measured_tiled_decode_guard.py: the FLUX.3 edit on a T4 budget is admitted with the measured row and still refused when it truly does not fit; non-calibrated placements keep the flat estimate.tests/test_diffusion_step_graph_native_w8a8.py: the graph is declined only for an uncompiled denoiser with served W8A8 linears; compiled denoisers, ROCm, disabled or failed fused W8A8, and the env override keep it.Not covered