Repository navigation
Studio: flash attention by default for FLUX.2-klein on ROCm gfx11 - #12703
Conversation
FLUX.1 / FLUX.2 denoisers on ROCm now run diffusers' apply_rotary_emb as one Triton kernel (the existing FLUX.2 fp16 kernel, bit-identical to stock) and AdaLayerNormZero / AdaLayerNormZeroSingle / AdaLayerNormContinuous as one LayerNorm plus modulation kernel that keeps the stock rounding chain. Switches UNSLOTH_DIFFUSION_FUSED_ROPE and UNSLOTH_DIFFUSION_FUSED_ADALN (auto|0|1, auto = ROCm only, so CUDA loads are unchanged). Inference only, skipped while compiling, per-call fallback to the forward live at install.
…identical); fused RoPE stays auto
…gfx11 On gfx1151 FLUX.2-klein-4B with the fused RoPE renders in 7.37 to 7.40 s with flash_attn against 8.04 to 8.09 s on SDPA (LPIPS 0.008). auto now selects flash for the flux.2-klein family on a gfx11 card when flash_attn is installed and passes the on-card check, under a speed profile or with the speed left unset (ROCm resolves unset to off, so that is the default path). An explicit speed_mode off, other families, other arches and every NVIDIA path keep their current pick.
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. |
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. |
…eline install_rope() only calls importlib.import_module on a module name that is already a key of _ROPE_FNS, which is built from the fixed _MODULES tuple of the two diffusers Flux transformer modules. No model, request or download can choose the imported name, so the call site is safe to record.
test_diffusion_backend.py can leave Studio's compile-safe eager patch live on diffusers' AdaLN classes. When it runs first in the same session, every teardown here saw that forward instead of stock and failed (1 failed, 14 errors off-GPU). Remove the eager patch before capturing the stock forwards and before each test, so the suite passes in either file order on CPU and GPU.
…ip tests without torch
|
Codex Review: Didn't find any major issues. Chef's kiss. 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". |
|
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". |
Stacked on #12701 (fused RoPE on ROCm). Merge that first.
Problem
On a Strix Halo (Radeon 8060S, gfx1151, Linux, ROCm), FLUX.2-klein-4B with #12701's fused RoPE takes 7.37, 7.40 and 7.40 s per 1024x1024 image with
attention_backend=flash(DAO-AILab flash-attention, Triton AMD backend). The same runner takes 8.04 to 8.09 s on the default SDPA path, so flash is about 8.5% faster. The two outputs differ by LPIPS 0.008.That meets the rule for turning flash on by default:
But Studio's
autoattention never picks flash on ROCm (ROCM_AUTO_FLASH = False). It only would under a speed profile, and on ROCm an unset speed resolves tooff. FLUX.1 has no valid flash measurement on this runner yet.Change
select_attention_backendtakes the load'sfamily.autonow picks verified ROCm flash when all of these hold:ROCM_AUTO_FLASH_FAMILIES(onlyflux.2-klein);gfx11;flash_attnis installed and passes the existing per-device check (_rocm_flash_attn_runs).speed_unset, which is what the UI sends; ROCm resolves it tooff).speed_mode=off;native/sdpa;flash_attnis installed is checked without importing it, so anautoload on a card without it logs nothing new.diffusion.pypassesfamilyandspeed_unsetat the load-time pick, andfamilyat the deferred re-pick.Results
gfx1151: Strix Halo CI runner, Radeon 8060S, Linux, torch 2.11.0+rocm7.13.0, flash_attn installed with
FLASH_ATTENTION_TRITON_AMD_ENABLE=TRUE. Base is main plus #12701, head is base plus this change, same runner, same job. The pre-run check found 62.54 GiB of the pool free. 1024x1024, 3 renders per arm.autoautoauto: the head is 8.5% faster than pinned SDPA (ratio 0.915). Each arm's three renders sit within 0.03 s of each other.autoequals pinned SDPA, so the default only changed in the head. LPIPS of headautovs pinned SDPA is 0.010, inside the 0.02 limit. The run's differential verdict is CONFIRMED.auto: stays on SDPA in the head (16.04 vs 16.03 s), as intended.FLUX.1 stays off the list. On the base with flash requested explicitly, FLUX.1 is 8.8% faster (14.58 / 14.58 / 14.59 s against 16.00 / 15.98 / 16.00 s on SDPA, 3.35 vs 3.69 s/step). But its output moves by LPIPS 0.048 against SDPA, above the 0.02 limit, so it does not meet the bar for a default. Users can still request flash explicitly.
test_diffusion_backend.pytake the new keywords.Not covered
flash_attnis installed but built for CK without the Triton flag, the import fails. The existing one-time "flash_attn is not importable" warning then appears on a kleinautoload.