[Bugfix] Make Attention Backend Auto-Selection Batch-Invariance-Aware (#40193)

Signed-off-by: Srreyansh Sethi <srreyansh.sethi@gmail.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Co-authored-by: Matthew Bonanni <mbonanni@redhat.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Srreyansh Sethi
2026-04-23 14:57:03 +00:00
committed by GitHub
co-authored by Matthew Bonanni mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent d0009ddb0b
commit b7a2605020
9 changed files with 38 additions and 50 deletions
+7
View File
@@ -236,6 +236,10 @@ class AttentionBackend(ABC):
"""
return False
@classmethod
def supports_batch_invariance(cls) -> bool:
return False
@classmethod
def supports_attn_type(cls, attn_type: str) -> bool:
"""Check if backend supports a given attention type.
@@ -278,6 +282,7 @@ class AttentionBackend(ABC):
device_capability: "DeviceCapability",
attn_type: str,
use_non_causal: bool = False,
use_batch_invariant: bool = False,
) -> list[str]:
invalid_reasons = []
if not cls.supports_head_size(head_size):
@@ -312,6 +317,8 @@ class AttentionBackend(ABC):
invalid_reasons.append(f"attention type {attn_type} not supported")
if use_non_causal and not cls.supports_non_causal():
invalid_reasons.append("non-causal attention not supported")
if use_batch_invariant and not cls.supports_batch_invariance():
invalid_reasons.append("batch invariance not supported")
combination_reason = cls.supports_combination(
head_size,
dtype,