Repository navigation
Studio diffusion: report the attention backend that actually runs - #18418
Conversation
The attention_backend status entry is now read off the DiT's attention modules instead of the load's request: - An explicit pick that did not engage (SageAttention not installed, its probe failed, dtype or head_dim unsupported, cuDNN without a kernel for the head_dim, FlashAttention 3 off Hopper, a non NVIDIA platform) reads fell_back or unsupported, names what ran instead and says why. Before, it read "applied" with the reason "diffusers default". - INT8 attention On over an explicit pick says the INT8 kernel runs and on how many modules. - The value is never a backend with 0 modules: the entry carries the module census (engaged, modules, routed), and the image status re-reads it when a later race moves modules. - MiniMax-H3-Image now honours the load's attention pick: an explicit "sage" pins SageAttention on the DiT blocks with no race against native and no INT8 race (INT8 only when its control is On), and any other explicit pick keeps the checkpoint's SageAttention off. Its status gains an attention_backend entry.
- The existing attention ResolvedBadge shows a declined pick as "SAGE -> NATIVE" with the backend's reason in its tooltip, and INT8 as "INT8". - The loaded build summary names the backend the modules run. - The Attention select keeps the user's own pick when it fell back, so the next load asks for it again.
The status path stamps a select-level decline on the pipeline objects only, never on a DiT that may already be compiled. A new test compiles a DiT whose forward reads each processor's backend, runs every status read between renders, and checks there are no graph breaks, no recompiles and no tensor ops on that path.
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. |
|
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". |
…esponse model The attention_backend entry gained engaged, modules and routed, but the status response model did not declare them, so pydantic dropped them before any client saw the module census. Declare them (defaulting to null) and pin it with a test through both status response models. [skip ci]
|
Codex Review: Didn't find any major issues. Delightful! 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/core/inference/diffusion.py [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
[skip ci]
…ok, H3-Image LoRA reload message) (#18583) `test_attention_hook_installs_on_cudnn_pins` (#18083) read the source of `_apply_attention_backend` and looked for the literal `if backend == "_native_cudnn" and target is not None and _is_cuda_nvidia(target):` line. #18418 moved that branch into `_apply_attention_backend_impl`, so on main the test fails with `ValueError: substring not found` before it checks anything. The production hook is still installed; only the test broke, and a test that greps source text would break again on the next refactor. ## Change Test only (`tests/test_diffusion_qwenimage21_strided_attn.py`). The test now runs the real `_apply_attention_backend` on a fake DiT, with the card checks stubbed (`_is_cuda_nvidia`, `_cudnn_serves_pipe`, kernel install, ROCm guards) and the Qwen-Image-2.1 and FLUX.3 strided installs replaced by recorders. No production code changes. ## Tests - `test_attention_hook_installs_on_cudnn_pins`: a `_native_cudnn` pin on an NVIDIA target engages, pins the DiT, and calls the Qwen-Image-2.1 strided install with `(pipe, "_native_cudnn", target, logger)`. The old version fails on main (`ValueError`), the new one passes here. With the `install_q21_strided(...)` call removed from `_apply_attention_backend_impl`, the new test fails, so it still guards the hook. - `test_attention_hook_skips_other_pins` (2 cases): a cuDNN pin on a non-NVIDIA target and a `_native_math` pin on NVIDIA engage without calling either strided install. Suite (`test_diffusion_qwenimage21_strided_attn.py`, `test_diffusion_flux3_strided_attn.py`, `test_diffusion_int8_attention_auto.py`, `test_diffusion_int8_attention_dispatch.py`, `test_diffusion_int8_attention_persisted.py`, `test_diffusion_attention.py`, `test_diffusion_attention_honest_status.py`, `test_diffusion_attention_cudnn_head_dim.py`): main 272 passed, 1 skipped, 1 failed (`test_attention_hook_installs_on_cudnn_pins`); this branch 275 passed, 1 skipped, 0 failed. ## Not proven here No GPU run; none is needed for a test-only change. The new test fakes the card and the installs, so it shows the apply calls the hook, not that the strided processors run on a real NVIDIA card (the existing `gpu`-marked tests in the same file cover that). ## Second stale test: MiniMax-H3-Image LoRA reload message `tests/test_diffusion_h3_image_trainer.py::test_backend_runs_only_the_load_time_lora_set_for_h3_image` also fails on main: #18420 reworded the reload error to the shared `LORA_RELOAD_REMEDY` ("Reload the model with the LoRA selection: ..."), but the test still matched the old "Load the model again". The behaviour it checks is unchanged (a different LoRA set or weight on an H3-Image load is refused), so the test now matches the current message. The file goes from 1 failed, 20 passed on main to 21 passed here.
Summary
When a load asks for a specific attention backend (SageAttention, flash, cuDNN, native, or INT8 attention On), Studio now either runs that backend or the status says what ran instead and why. The status is read off the DiT's attention modules, so it never names a backend that no module routes to.
Before this change, an explicit
attention_backend="sage"that could not run (SageAttention not installed, its probe failed, unsupported dtype or head_dim, a ROCm / Apple Silicon / CPU load) fell back to SDPA, and the status saidvalue: "native", status: "applied", reason: "diffusers default". The badge stayed hidden, so the page looked as if the pick had been honoured.Changes
Status (
resolved.attention_backend)fell_back, orunsupportedwhere the platform or card cannot run it. The reason names the cause, for example:sageattention is not installed and the Hugging Face kernels-hub build could not be loaded (...)SageAttention failed its check on this GPU (self-check: cosine ...)SageAttention serves head_dim <= 128 and this model uses 256SageAttention needs an NVIDIA CUDA GPU and this load runs on Apple Silicon (MPS)cuDNN attention has no kernel for this model's head_dim with this torch/cuDNN buildFlashAttention 3 needs a sm90 to below sm100 GPU and this one is sm89engaged(the backend the modules run),modules(how many run it) androuted(every backend's count). A split is named in the reason, for example40 of 60 attention modules run SageAttention, 20 run native SDPA.Explicit picks are never raced over
sagepins SageAttention on the DiT blocks, with no race against native and no INT8 race (INT8 only when its control is On);attention_backendentry.Frontend
SAGE -> NATIVE, with the backend's reason in the tooltip.unsloth_int8readsINT8. No new UI elements.Tests
tests/test_diffusion_attention_honest_status.py(24 tests, fake backends, real module census). It covers:graph_break()is counted first to prove the counters work.tests/attention-resolved-badge.test.ts(9 tests).tscis clean.GPU check (Colab L4)
One Colab L4 VM (torch 2.13.0+cu130, diffusers 0.42.1). Studio was installed with
./install.sh --localat the merge base. The head tree is that tree plus this change. Every arm is a fresh process withattention_backend="sage"and speed left at its default (the DiT compiles). FLUX.2-klein-4B renders 768 px in 4 steps. Qwen-Image-2.1 (model_kind=pipeline) renders 768 px in 8 steps.sage(kernels0.12.3, no pipsageattention).kernelsandsageattentionremoved, withUNSLOTH_DIFFUSION_ATTENTION_INSTALL=0.sage_hub/ appliedsage_hub/ appliedsage_hub/ appliedsage_hub/ appliednative/ appliednative/ fell_backnative/ appliednative/ fell_backNot covered
Nothing on the per-call attention path changed: the Sage / FA4 guards, the strided processors, the INT8 op and the dispatch route are untouched. The new code runs at load time and when the status is read. Graph breaks and recompiles were counted on CPU (torch 2.14.1) with Dynamo counters. They were not counted on the GPU arms, which ran torch 2.13. Other torch versions were not run.
Per-call fallbacks inside an engaged Sage backend (a masked call, a head_dim above 128 on some modules) are not in the status. Under compile those calls are traced, not counted. The census is per module.
pip SageAttention 2 was not run end to end on the GPU. Only the kernels-hub build was; the pip path is covered by the CPU tests.
ROCm, Apple Silicon and Windows fallbacks, the MiniMax-H3 video and MiniMax-H3-Image picks, and flash / cuDNN / FlashAttention 3 picks were tested on CPU with fake backends only. None ran on a GPU here.
The INT8 On over Sage arm was not run on the GPU.
UI before / after
Images page, loaded diffusers build on a CUDA host, Advanced > Attention set to SageAttention. Left = main (merge base
ec3ba179c), right = this PR (f9a0c756f). The status served to each side was produced by that side's own backend code for the same load.SageAttention requested but not installed (no hub build): main shows no badge, so the UI implies Sage ran. This PR shows
SAGE → NATIVEnext to Attention, and the tooltip says why.SageAttention requested with INT8 attention On: main shows no badge. This PR shows
SAGE → INT8, and the tooltip names Studio's INT8 kernel and how many attention modules it runs.Loaded build summary, same INT8 On load: the Attention row reads
UNSLOTH_INT8on main andINT8with this PR, naming what the attention modules run.