[Core][Feat] Pluggable KVCacheConfigBuilder for platform/model-specific KV cache planning (#53558)
Signed-off-by: wangxiyuan <wangxiyuan1007@gmail.com> Signed-off-by: Yifan Qiao <yifanqiao@inferact.ai> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Yifan Qiao <yifanqiao@inferact.ai>
This commit is contained in:
co-authored by
Claude Opus 5.5
Yifan Qiao
parent
2268d83bd9
commit
b544587408
@@ -64,6 +64,7 @@ if TYPE_CHECKING:
|
||||
from vllm.tasks import ScoreType
|
||||
from vllm.tokenizers import TokenizerLike
|
||||
from vllm.v1.attention.backends.registry import MambaAttentionBackendEnum
|
||||
from vllm.v1.kv_cache_interface import KVCacheGroupSpec, KVCacheSpec
|
||||
from vllm.v1.worker.encoder_cudagraph_defs import (
|
||||
EncoderCudaGraphCaptureInputs,
|
||||
EncoderCudaGraphConfig,
|
||||
@@ -669,6 +670,47 @@ def supports_score_template(
|
||||
return getattr(model, "supports_score_template", False)
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class SupportsKVCacheGrouping(Protocol):
|
||||
"""The interface required for models that own their KV cache grouping.
|
||||
|
||||
.. note::
|
||||
Experimental. The classmethod contract may change as model-owned
|
||||
grouping stabilizes.
|
||||
|
||||
Implementing it lets a model replace the default KV cache grouping (which
|
||||
layers share a block table) while Core keeps owning placement, byte
|
||||
accounting, and admission.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def get_kv_cache_groups(
|
||||
cls,
|
||||
vllm_config: "VllmConfig",
|
||||
kv_cache_spec: dict[str, "KVCacheSpec"],
|
||||
) -> list["KVCacheGroupSpec"]:
|
||||
"""Split the model's layers into logical KV cache groups."""
|
||||
...
|
||||
|
||||
|
||||
@overload
|
||||
def supports_kv_cache_grouping(
|
||||
model: type[object],
|
||||
) -> TypeIs[type[SupportsKVCacheGrouping]]: ...
|
||||
|
||||
|
||||
@overload
|
||||
def supports_kv_cache_grouping(
|
||||
model: object,
|
||||
) -> TypeIs[SupportsKVCacheGrouping]: ...
|
||||
|
||||
|
||||
def supports_kv_cache_grouping(
|
||||
model: type[object] | object,
|
||||
) -> TypeIs[type[SupportsKVCacheGrouping]] | TypeIs[SupportsKVCacheGrouping]:
|
||||
return isinstance(model, SupportsKVCacheGrouping)
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class SupportsLoRA(Protocol):
|
||||
"""The interface required for all models that support LoRA."""
|
||||
|
||||
@@ -50,6 +50,7 @@ from .interfaces import (
|
||||
is_hybrid,
|
||||
requires_raw_input_tokens,
|
||||
supports_hc_sp,
|
||||
supports_kv_cache_grouping,
|
||||
supports_multimodal,
|
||||
supports_multimodal_encoder_tp_data,
|
||||
supports_multimodal_raw_input_only,
|
||||
@@ -882,6 +883,7 @@ class _ModelInfo:
|
||||
supports_replayssm: bool
|
||||
supports_transcription: bool
|
||||
supports_transcription_only: bool
|
||||
supports_kv_cache_grouping: bool
|
||||
supported_video_pruning_methods: tuple[str, ...]
|
||||
supports_mm_device_do_normalize: bool
|
||||
|
||||
@@ -913,6 +915,7 @@ class _ModelInfo:
|
||||
supports_transcription_only=(
|
||||
supports_transcription(model) and model.supports_transcription_only
|
||||
),
|
||||
supports_kv_cache_grouping=supports_kv_cache_grouping(model),
|
||||
has_noops=has_noops(model),
|
||||
supported_video_pruning_methods=getattr(
|
||||
model, "supported_video_pruning_methods", ()
|
||||
|
||||
Reference in New Issue
Block a user