[Spec Decode] Support mixed KV page sizes for DFlash (#45181)
Signed-off-by: Alex Steiner <asteiner@nvidia.com> Signed-off-by: Giancarlo Delfin <gdelfin@inferact.ai> Signed-off-by: Yifan Qiao <yifanqiao@inferact.ai> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Giancarlo Delfin <gdelfin@inferact.ai> Co-authored-by: Yifan Qiao <yifanqiao@inferact.ai>
This commit is contained in:
co-authored by
Claude Opus 4.8
Giancarlo Delfin
Yifan Qiao
parent
3e6e33526d
commit
2cac89f9da
@@ -20,6 +20,7 @@ from vllm.utils.math_utils import cdiv, round_up
|
||||
from vllm.utils.mem_utils import format_gib
|
||||
from vllm.utils.torch_utils import get_dtype_size
|
||||
from vllm.v1.kv_cache_interface import (
|
||||
AttentionSpec,
|
||||
ChunkedLocalAttentionSpec,
|
||||
FullAttentionSpec,
|
||||
HiddenStateCacheSpec,
|
||||
@@ -1029,9 +1030,14 @@ def unify_kv_cache_spec_page_size(
|
||||
) -> dict[str, KVCacheSpec]:
|
||||
"""
|
||||
Unify the page size of the given KVCacheSpec. If the page size of all layers
|
||||
are the same, return the original KVCacheSpec. If not same, unify the page
|
||||
size by increasing the block size of layers with smaller page size. Raise
|
||||
NotImplementedError if failed to unify the page size.
|
||||
are the same, return the original KVCacheSpec. If not same, first try to
|
||||
unify page size by increasing the block size of layers with smaller page
|
||||
size. If a smaller attention page does not evenly divide the maximum page
|
||||
size, keep its logical block size and pad its physical page instead --- but
|
||||
only for attention layers whose backend opts in via
|
||||
``AttentionSpec.indexes_kv_by_block_stride`` (the padded page is read through
|
||||
a strided view, which not every backend handles). Raise NotImplementedError
|
||||
if failed to unify the page size.
|
||||
|
||||
Args:
|
||||
kv_cache_spec: The KVCacheSpec of each attention layer in the model
|
||||
@@ -1051,14 +1057,23 @@ def unify_kv_cache_spec_page_size(
|
||||
new_kv_cache_spec[layer_name] = layer_spec
|
||||
else:
|
||||
layer_page_size = layer_spec.page_size_bytes
|
||||
if max_page_size % layer_page_size != 0:
|
||||
if max_page_size % layer_page_size == 0:
|
||||
ratio = max_page_size // layer_page_size
|
||||
new_block_size = layer_spec.block_size * ratio
|
||||
new_spec = replace(layer_spec, block_size=new_block_size)
|
||||
elif (
|
||||
isinstance(layer_spec, AttentionSpec)
|
||||
and layer_spec.indexes_kv_by_block_stride
|
||||
):
|
||||
new_spec = replace(layer_spec, page_size_padded=max_page_size)
|
||||
else:
|
||||
raise NotImplementedError(
|
||||
"The page size of the layer is not divisible by the "
|
||||
"maximum page size. Cannot unify by adjusting block_size."
|
||||
f"Layer {layer_name}: page size is not divisible by the "
|
||||
"maximum page size and cannot be padded. Padding is only "
|
||||
"supported for attention layers whose backend indexes KV "
|
||||
"pages by the block stride (indexes_kv_by_block_stride is "
|
||||
"True)."
|
||||
)
|
||||
ratio = max_page_size // layer_page_size
|
||||
new_block_size = layer_spec.block_size * ratio
|
||||
new_spec = replace(layer_spec, block_size=new_block_size)
|
||||
assert new_spec.page_size_bytes == max_page_size
|
||||
new_kv_cache_spec[layer_name] = new_spec
|
||||
return new_kv_cache_spec
|
||||
|
||||
Reference in New Issue
Block a user