[Core][Model] Gemma4: Unified FA4 for all layers + FlashAttention mm_prefix support (#42175)
Signed-off-by: Luciano Martins <lucianommartins@users.noreply.github.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com> Signed-off-by: Matthew Bonanni <mbonanni@redhat.com> Co-authored-by: Luciano Martins <lucianommartins@users.noreply.github.com> Co-authored-by: Lucas Wilkinson <lwilkins@redhat.com> Co-authored-by: Matthew Bonanni <mbonanni@redhat.com>
This commit is contained in:
co-authored by
Luciano Martins
Lucas Wilkinson
Matthew Bonanni
parent
d82ac00923
commit
6deb05e0e4
@@ -17,6 +17,7 @@ from typing_extensions import runtime_checkable
|
||||
|
||||
from vllm.config import VllmConfig, get_layers_from_vllm_config
|
||||
from vllm.utils.math_utils import cdiv
|
||||
from vllm.utils.torch_utils import async_tensor_h2d
|
||||
from vllm.v1.kv_cache_interface import KVCacheSpec, MambaSpec
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -45,6 +46,35 @@ PAD_SLOT_ID = -1
|
||||
NULL_BLOCK_ID = 0
|
||||
|
||||
|
||||
def compute_mm_prefix_range_tensor(
|
||||
mm_prefix_range: dict[int, list[tuple[int, int]]] | None,
|
||||
num_seqs: int,
|
||||
device: torch.device,
|
||||
) -> torch.Tensor | None:
|
||||
"""Convert mm_prefix_range dict to padded tensor for Triton kernel.
|
||||
|
||||
Returns shape: (num_seqs, max_ranges, 2) with 0-padding for empty ranges.
|
||||
Empty ranges have start==end==0, which kernel skips via is_valid check.
|
||||
"""
|
||||
if mm_prefix_range is None:
|
||||
return None
|
||||
|
||||
range_lists = [
|
||||
mm_prefix_range.get(i, [(0, 0)]) or [(0, 0)] for i in range(num_seqs)
|
||||
]
|
||||
|
||||
if all(r == [(0, 0)] for r in range_lists):
|
||||
return None
|
||||
|
||||
max_ranges = max(len(r) for r in range_lists)
|
||||
padded = []
|
||||
for r in range_lists:
|
||||
padded_r = list(r) + [(0, 0)] * (max_ranges - len(r))
|
||||
padded.append(padded_r)
|
||||
padded = async_tensor_h2d(padded, dtype=torch.int32, device=device)
|
||||
return padded.view(num_seqs, max_ranges, 2)
|
||||
|
||||
|
||||
def is_valid_kv_cache_layout(value: str) -> bool:
|
||||
return value in get_args(KVCacheLayoutType)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user