[ROCm][CI] Fix cross-attention dispatch for encoder-decoder models (#38450)
Signed-off-by: Andreas Karatzas <akaratza@amd.com>
This commit is contained in:
+22
-6
@@ -439,7 +439,10 @@ class RocmPlatform(Platform):
|
||||
f"this configuration. Reason: {invalid_reasons}"
|
||||
)
|
||||
else:
|
||||
logger.info("Using %s backend.", selected_backend)
|
||||
logger.info_once(
|
||||
"Using %s backend (selected via --attention-backend).",
|
||||
selected_backend.name,
|
||||
)
|
||||
return selected_backend.get_path()
|
||||
|
||||
# No selected backend or the selected backend is invalid,
|
||||
@@ -476,12 +479,25 @@ class RocmPlatform(Platform):
|
||||
)
|
||||
selected_index = sorted_indices[0]
|
||||
selected_backend = valid_backends_priorities[selected_index][0]
|
||||
logger.info_once(
|
||||
"Using %s attention backend out of potential backends: %s.",
|
||||
selected_backend.name,
|
||||
"[" + ", ".join(f"'{b[0].name}'" for b in valid_backends_priorities) + "]",
|
||||
scope="local",
|
||||
valid_str = (
|
||||
"[" + ", ".join(f"'{b[0].name}'" for b in valid_backends_priorities) + "]"
|
||||
)
|
||||
if invalid_reasons:
|
||||
rejected_str = ", ".join(b.name for b in invalid_reasons)
|
||||
logger.info(
|
||||
"Found incompatible backend(s) [%s] with %s. "
|
||||
"Overriding with %s out of potential backends: %s.",
|
||||
rejected_str,
|
||||
attn_selector_config.attn_type,
|
||||
selected_backend.name,
|
||||
valid_str,
|
||||
)
|
||||
else:
|
||||
logger.info_once(
|
||||
"Using %s backend out of potential backends: %s.",
|
||||
selected_backend.name,
|
||||
valid_str,
|
||||
)
|
||||
|
||||
return selected_backend.get_path()
|
||||
|
||||
|
||||
@@ -758,11 +758,12 @@ class AiterFlashAttentionBackend(AttentionBackend):
|
||||
|
||||
@classmethod
|
||||
def supports_attn_type(cls, attn_type: str) -> bool:
|
||||
"""ROCM AITER FA supports decoder and encoder-decoder (cross) attention."""
|
||||
return attn_type in (
|
||||
AttentionType.DECODER,
|
||||
AttentionType.ENCODER_DECODER,
|
||||
)
|
||||
"""ENCODER_DECODER is not supported because the prefill path uses
|
||||
flash_attn_varlen_func with cu_seqlens_k set to decoder
|
||||
query_start_loc (not encoder seq lens) and causal=True, both of
|
||||
which are incorrect for cross-attention layers.
|
||||
"""
|
||||
return attn_type in (AttentionType.DECODER,)
|
||||
|
||||
@staticmethod
|
||||
def get_supported_kernel_block_sizes() -> list[int | MultipleOf]:
|
||||
|
||||
@@ -212,12 +212,17 @@ class RocmAttentionBackend(AttentionBackend):
|
||||
|
||||
@classmethod
|
||||
def supports_attn_type(cls, attn_type: str) -> bool:
|
||||
"""RocmAttention supports all attention types."""
|
||||
"""ENCODER_DECODER is not supported because
|
||||
chunked_prefill_paged_decode's prefill kernel (context_attention_fwd)
|
||||
assumes self-attention semantics: it treats passed K/V as new tokens
|
||||
to mix with cached K/V. For cross-attention layers the encoder K/V
|
||||
are already fully cached, so mixing them again produces incorrect
|
||||
results when max_query_len > 1 (e.g. beam search).
|
||||
"""
|
||||
return attn_type in (
|
||||
AttentionType.DECODER,
|
||||
AttentionType.ENCODER,
|
||||
AttentionType.ENCODER_ONLY,
|
||||
AttentionType.ENCODER_DECODER,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user