[Core] Prototype diffusion attention execution contracts with FA4 (#7379)
This commit is contained in:
1 parent
97d6c693a6
commit
596487fe62
13 files changed
+1703
-27
No files matched your search
@@ -7,6 +7,10 @@ from typing import Any, Generic, Literal, TypeVar
|
||||
|
||||
import torch
|
||||
|
||||
from vllm_omni.diffusion.attention.capabilities import (
|
||||
ExecutionContext,
|
||||
ExecutionPathResult,
|
||||
)
|
||||
from vllm_omni.platforms import current_omni_platform
|
||||
|
||||
|
||||
@@ -132,6 +136,15 @@ class AttentionBackend(ABC):
|
||||
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def resolve_capabilities(cls, context: ExecutionContext) -> ExecutionPathResult:
|
||||
"""Return conservative pre-construction capabilities.
|
||||
|
||||
Unmigrated backends remain advisory so introducing the contract cannot
|
||||
reject an execution path that works today.
|
||||
"""
|
||||
return ExecutionPathResult.unmigrated(cls.get_name(), context)
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class QueryRange:
|
||||
@@ -218,6 +231,9 @@ class AttentionMetadata:
|
||||
# "valid_kv_length": int — contiguous valid K/V prefix length. Local
|
||||
# backends may slice it directly; ring backends trim each circulated
|
||||
# K/V block from the same global prefix.
|
||||
# "attention_mask_mode": "none" | "padding" | "arbitrary" — producer
|
||||
# assertion used by capability planning. "none" means a present mask
|
||||
# is semantically a no-op; absent means its contents are runtime-dependent.
|
||||
# "npu_attn_varlen": bool — model opt-in for the NPU packed varlen path
|
||||
# (TND npu_fusion_attention driven by cu_seqlens, mask never read).
|
||||
# Requires the [real, pad] two-document packing contract; see
|
||||
@@ -277,6 +293,21 @@ class AttentionImpl(ABC, Generic[T]):
|
||||
return True
|
||||
return kv_cache_dtype in cls._supported_kv_cache_dtypes.get(platform_key, set())
|
||||
|
||||
def resolve_execution_path(
|
||||
self,
|
||||
context: ExecutionContext,
|
||||
query: torch.Tensor,
|
||||
key: torch.Tensor,
|
||||
value: torch.Tensor,
|
||||
attn_metadata: T | None,
|
||||
) -> ExecutionPathResult:
|
||||
"""Resolve the complete path after backend initialization.
|
||||
|
||||
Subclasses report verified results; this inspection API does not enforce them.
|
||||
"""
|
||||
del query, key, value, attn_metadata
|
||||
return ExecutionPathResult.unmigrated(type(self).__name__, context)
|
||||
|
||||
def forward(
|
||||
self,
|
||||
query: torch.Tensor,
|
||||
|
||||
Reference in new issue
Block a user