Repository navigation
Studio sd.cpp: keep text-encoder flash attention on (per-module --flash-attn instead of --diffusion-fa) - #18787
Conversation
…n off,diffusion=on,te=on instead of --diffusion-fa
|
@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. |
|
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". |
…n auto (te=auto) instead of forcing it on [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
Studio's sd.cpp speed and offload flags send
--diffusion-fa(native_speed_flagsandoffload_flagsinsd_cpp_args.py). The pinned build,master-982-0518b34-u27b9ddc, now treats that flag as a deprecated alias:So the flag Studio adds for speed turns text-encoder flash attention off. Without it, the binary's own
autowould turn it on for CPU, CUDA MMA and Metal. An LLM text encoder (Qwen3, Qwen3-VL, Mistral) then builds the full[heads, n, n]F32 score matrix for every layer. On CPU that costs time. On Vulkan, once the matrix passes the 4 GiB storage-buffer limit, the op falls back to the CPU. That is leejet/stable-diffusion.cpp #1986: Qwen3-VL-32B at about 4.2k tokens on an RX 7900 XTX, fixed upstream by #1987, which only helps when flash attention is actually on for the text encoder.Change
--helpdocuments per-module--flash-attnassignments (te=on|off), the managed flags now carry--flash-attn off,diffusion=on,te=autoin place of--diffusion-fa.--diffusion-fahad it, so VAE output is unchanged.SdCppEngine.generate. One--flash-attnis emitted even when both the offload and speed lists asked for--diffusion-fa.--diffusion-fa.--diffusion-fa. The help probe is cached per binary path, size and mtime, the same way as the existing--conv-directprobe.Tests
New
tests/test_sd_cpp_flash_attn_modules.py(CPU), using the pinned build's own help text. It covers:--flash-attntest_differential.py: DISCRIMINATING. 4 tests fail on main and pass here, 1 is new API, 1 is unchanged, head_fail=0. The sd.cpp and H3 native suites pass: 2123 passed, 6 skipped. Detection was checked against the real pinned Linuxsd-clibinary.Results
The timings below were taken with
te=on. On the CPU backend the binary's auto resolves to on, sote=autoruns the same kernel there.The CPU of a Colab L4 VM: Xeon @ 2.20 GHz (Cascade Lake), 6 cores. The pinned release's Linux CPU
sd-cliwas used for both arms. Z-Image Turbo Q4_K_M with the Qwen3-4B Q8_0 encoder, 512 px, 1 step, seed 42. The only difference between the arms is the flag. Arms were interleaved over 2 rounds, and both rounds of each arm matched to within 0.3 s.--diffusion-fa--flash-attn off,diffusion=on,te=onARM CPUs (GitHub runners, relative timing; source builds of the same pin; FLUX.2 klein 4B Q4_0 + Qwen3-4B Q4_0, 256 px, 1 step; medians of 3 rotated rounds). Text-encode seconds:
--diffusion-faNot proven here
vkCreateInstance: ERROR_INCOMPATIBLE_DRIVER). The 4 GiB fallback is upstream's report, not measured here.autoalready picks flash attention for the encoder, which this restores.