[Perf][MRV2] Reuse Mamba/GDN metadata across KV cache groups (#58762)
Signed-off-by: Luca Motz <luca.motz@icloud.com> Co-authored-by: Xin Yang <xyangx@amazon.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Codex <noreply@openai.com> Co-authored-by: Lucas Wilkinson <LucasWilkinson@users.noreply.github.com>
This commit is contained in:
co-authored by
Xin Yang
Claude Opus 5.5
Codex
Lucas Wilkinson
parent
55de40a2fc
commit
dd3bc9c72f
@@ -29,6 +29,7 @@ from vllm.v1.kv_cache_interface import (
|
||||
AttentionSpec,
|
||||
KVCacheConfig,
|
||||
KVCacheSpec,
|
||||
MambaSpec,
|
||||
UniformTypeKVCacheSpecs,
|
||||
)
|
||||
from vllm.v1.worker.gpu.model_states.interface import ModelSpecificAttnMetadata
|
||||
@@ -462,6 +463,10 @@ def build_attn_metadata(
|
||||
|
||||
attn_metadata: dict[str, Any] = {}
|
||||
token_to_req_indices: torch.Tensor | None = None
|
||||
# Mamba groups with the same spec and builder differ only in their state
|
||||
# indices, so later groups re-gather those from the first group's metadata.
|
||||
# Also at capture, so FULL graphs share the batch-level buffers.
|
||||
cached_metadata: dict[tuple[KVCacheSpec, type], Any] = {}
|
||||
num_kv_cache_groups = len(kv_cache_config.kv_cache_groups)
|
||||
for i in range(num_kv_cache_groups):
|
||||
if not attn_groups[i]:
|
||||
@@ -514,7 +519,16 @@ def build_attn_metadata(
|
||||
|
||||
for attn_group in attn_groups[i]:
|
||||
attn_metadata_builder = attn_group.get_metadata_builder(ubatch_idx)
|
||||
if for_cudagraph_capture:
|
||||
reuse_key = None
|
||||
if attn_metadata_builder.supports_update_block_table and isinstance(
|
||||
attn_group.kv_cache_spec, MambaSpec
|
||||
):
|
||||
reuse_key = (attn_group.kv_cache_spec, type(attn_metadata_builder))
|
||||
if reuse_key in cached_metadata:
|
||||
metadata = attn_metadata_builder.update_block_table(
|
||||
cached_metadata[reuse_key], block_table, slot_mapping
|
||||
)
|
||||
elif for_cudagraph_capture:
|
||||
metadata = attn_metadata_builder.build_for_cudagraph_capture(
|
||||
common_attn_metadata
|
||||
)
|
||||
@@ -532,6 +546,8 @@ def build_attn_metadata(
|
||||
common_attn_metadata=common_attn_metadata,
|
||||
**attn_metadata_extra_kwargs,
|
||||
)
|
||||
if reuse_key is not None and reuse_key not in cached_metadata:
|
||||
cached_metadata[reuse_key] = metadata
|
||||
for layer_name in attn_group.layer_names:
|
||||
attn_metadata[layer_name] = metadata
|
||||
token_to_req_indices = common_attn_metadata._token_to_req_indices_cache
|
||||
|
||||
Reference in New Issue
Block a user