[Attention] Add Triton/FlashInfer composite for multimodal prefix attention (#56305)
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com> Co-authored-by: Codex <noreply@openai.com> Co-authored-by: Lucas Wilkinson <LucasWilkinson@users.noreply.github.com> Co-authored-by: Lucas Wilkinson <lwilkins@redhat.com> Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
co-authored by
Codex
Lucas Wilkinson
Lucas Wilkinson
OpenAI Codex
parent
8cf9de9080
commit
82a85dc1d2
@@ -8,6 +8,7 @@ from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Protocol,
|
||||
TypeVar,
|
||||
cast,
|
||||
)
|
||||
|
||||
@@ -45,6 +46,19 @@ logger = init_logger(__name__)
|
||||
PAD_SLOT_ID = -1
|
||||
NULL_BLOCK_ID = 0
|
||||
|
||||
|
||||
ImplT = TypeVar("ImplT", bound=AttentionImpl)
|
||||
|
||||
|
||||
def find_attention_impl_variant(
|
||||
impl: AttentionImpl, impl_cls: type[ImplT]
|
||||
) -> ImplT | None:
|
||||
for variant in impl.get_impl_variants():
|
||||
if isinstance(variant, impl_cls):
|
||||
return cast(ImplT, variant)
|
||||
return None
|
||||
|
||||
|
||||
_LN_2 = math.log(2.0)
|
||||
|
||||
|
||||
@@ -342,8 +356,8 @@ def get_per_layer_parameters(
|
||||
per_layer_params: dict[str, PerLayerParameters] = {}
|
||||
|
||||
for key, layer in layers.items():
|
||||
impl = layer.impl
|
||||
assert isinstance(impl, cls_)
|
||||
impl = find_attention_impl_variant(layer.impl, cls_)
|
||||
assert impl is not None
|
||||
|
||||
# Infer hyperparameters from the attention layer
|
||||
window_size = getattr(impl, "sliding_window", None)
|
||||
@@ -1013,6 +1027,9 @@ def create_fast_prefill_custom_backend(
|
||||
common_attn_metadata.logits_indices_padded
|
||||
)
|
||||
self.num_logits_indices = common_attn_metadata.num_logits_indices
|
||||
self._attention_backend_variant = getattr(
|
||||
metadata, "_attention_backend_variant", 0
|
||||
)
|
||||
|
||||
return KVSharingFastPrefillAttentionMetadata(metadata, common_attn_metadata)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user