[Diffusion][Attention] Support per-role attention backend via CLI (#2681)
Signed-off-by: gcanlin <canlinguosdu@gmail.com> Signed-off-by: Hongsheng Liu <liuhongsheng4@huawei.com> Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
1 parent
26d481fc84
commit
11c4c7f0ff
29 files changed
+1262
-106
No files matched your search
@@ -15,7 +15,6 @@ It does NOT support:
|
||||
|
||||
import inspect
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from typing import Any, cast
|
||||
|
||||
@@ -211,7 +210,8 @@ class DiffusersAdapterPipeline(nn.Module, DiffusionPipelineProfilerMixin):
|
||||
logging.info("No transformer found in diffusers pipeline. Skipping attention backend setting.")
|
||||
return
|
||||
|
||||
attention_backend_config = self.od_config.attention_backend or os.environ.get("DIFFUSION_ATTENTION_BACKEND")
|
||||
default_spec = self.od_config.attention_config.default
|
||||
attention_backend_config = default_spec.backend if default_spec is not None else None
|
||||
attention_backend_attempts: list[str] = []
|
||||
match attention_backend_config:
|
||||
case "FLASH_ATTN" | None:
|
||||
|
||||
@@ -373,6 +373,7 @@ class WanSelfAttention(nn.Module):
|
||||
num_kv_heads=self.num_kv_heads,
|
||||
softmax_scale=1.0 / (head_dim**0.5),
|
||||
causal=False,
|
||||
role="self",
|
||||
)
|
||||
|
||||
def forward(
|
||||
@@ -525,6 +526,8 @@ class WanCrossAttention(nn.Module):
|
||||
num_kv_heads=self.num_heads,
|
||||
softmax_scale=1.0 / (head_dim**0.5),
|
||||
causal=False,
|
||||
role="cross",
|
||||
qkv_layout="BSND",
|
||||
skip_sequence_parallel=True,
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user