File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,9 +46,11 @@ are detected from their weights.
4646Omitting ` --audio-vae ` still runs the joint diffusion model but produces video without a
4747decoded audio track.
4848
49- ` --diffusion-fa ` also enables flash attention in the video VAE decoder (a ViT), which removes
50- most of its attention cost without touching the text encoder. Set ` SD_H3_VAE_FLASH_ATTN=0 `
51- to decode with the previous mul_mat + softmax attention.
49+ On CUDA and ROCm, ` --diffusion-fa ` also enables flash attention in the video VAE decoder (a ViT),
50+ which removes most of its attention cost without touching the text encoder. Set
51+ ` SD_H3_VAE_FLASH_ATTN=0 ` to decode with the previous mul_mat + softmax attention. Other backends
52+ keep that attention by default (on Vulkan the flash attention decode was slower);
53+ ` SD_H3_VAE_FLASH_ATTN=1 ` turns it on there.
5254
5355On NVIDIA GPUs from Ampere on, the unmasked DiT and VAE attention runs a pipelined
5456long-sequence variant of the ggml-cuda flash attention kernel (up to 4x faster at H3
Original file line number Diff line number Diff line change @@ -1178,12 +1178,15 @@ bool StableDiffusionGGML::validate_and_load_runners() {
11781178 high_noise_diffusion_model->set_flash_attention_enabled (true );
11791179 }
11801180 }
1181- // The H3 video VAE decoder is a ViT whose f32 L x L attention scores dominate decode time, so --diffusion-fa
1182- // covers it too, without switching the text encoder. SD_H3_VAE_FLASH_ATTN=0 restores the old path.
1181+ // The H3 video VAE decoder is a ViT whose f32 L x L attention scores dominate decode time, so on CUDA and ROCm
1182+ // --diffusion-fa covers it too, without switching the text encoder. It decoded slower on Vulkan, so other
1183+ // backends keep the old path unless SD_H3_VAE_FLASH_ATTN=1; SD_H3_VAE_FLASH_ATTN=0 restores it everywhere.
11831184 if (!sd_ctx_params->flash_attn && sd_ctx_params->diffusion_flash_attn && first_stage_model &&
11841185 sd_version_is_minimax_h3 (version)) {
1185- const char * env = getenv (" SD_H3_VAE_FLASH_ATTN" );
1186- if (env == nullptr || strcmp (env, " 0" ) != 0 ) {
1186+ const char * env = getenv (" SD_H3_VAE_FLASH_ATTN" );
1187+ ggml_backend_t vae_backend = backend_for (SDBackendModule::VAE );
1188+ const bool fa_faster_by_default = sd_backend_is (vae_backend, " CUDA" ) || sd_backend_is (vae_backend, " ROCm" );
1189+ if (env != nullptr ? strcmp (env, " 0" ) != 0 : fa_faster_by_default) {
11871190 LOG_INFO (" Using flash attention in the MiniMax-H3 video VAE" );
11881191 first_stage_model->set_flash_attention_enabled (true );
11891192 }
You can’t perform that action at this time.
0 commit comments