[Bugfix] Fix degenerate KV cache stride causing TMA cudaErrorIllegalInstruction (#40737)
Signed-off-by: David Oy <david@baseten.co> Signed-off-by: David Oy <58150256+the-david-oy@users.noreply.github.com> Signed-off-by: David Oy <david.oy@baseten.co> Co-authored-by: David Oy <david@baseten.co> Co-authored-by: Claude <claude@anthropic.com> Co-authored-by: Vadim Gimpelson <156319763+vadiklyutiy@users.noreply.github.com>
This commit is contained in:
co-authored by
David Oy
Claude
Vadim Gimpelson
parent
db9a84e0cd
commit
66dfee7121
@@ -4,7 +4,11 @@
|
||||
|
||||
import torch
|
||||
|
||||
from vllm.utils.torch_utils import is_quantized_kv_cache
|
||||
from vllm.logger import init_logger
|
||||
from vllm.utils.torch_utils import (
|
||||
canonicalize_singleton_dim_strides,
|
||||
is_quantized_kv_cache,
|
||||
)
|
||||
from vllm.v1.attention.backend import AttentionType
|
||||
from vllm.v1.attention.backends.fa_utils import (
|
||||
get_flash_attn_version,
|
||||
@@ -25,6 +29,8 @@ from .flash_attn import (
|
||||
cascade_attention,
|
||||
)
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
class FlashAttentionDiffKVBackend(FlashAttentionBackend):
|
||||
# Default to 128 for this backend
|
||||
@@ -204,6 +210,23 @@ class FlashAttentionDiffKVImpl(FlashAttentionImpl):
|
||||
# Different head_size for K and V
|
||||
key_cache = kv_cache[..., : self.head_size]
|
||||
value_cache = kv_cache[..., self.head_size :]
|
||||
# Fix degenerate strides on size-1 dims (e.g. num_kv_heads=1 with TP).
|
||||
# FA3/4 on H100+ uses TMA, which requires ≥16-byte stride alignment.
|
||||
# See vllm.utils.torch_utils.canonicalize_singleton_dim_strides.
|
||||
fixed_k = canonicalize_singleton_dim_strides(key_cache)
|
||||
fixed_v = canonicalize_singleton_dim_strides(value_cache)
|
||||
if fixed_k is not key_cache or fixed_v is not value_cache:
|
||||
logger.debug(
|
||||
"Canonicalized degenerate KV cache strides (FlashAttentionDiffKV): "
|
||||
"shape=%s, key strides before=%s after=%s, "
|
||||
"value strides before=%s after=%s",
|
||||
key_cache.shape,
|
||||
key_cache.stride(),
|
||||
fixed_k.stride(),
|
||||
value_cache.stride(),
|
||||
fixed_v.stride(),
|
||||
)
|
||||
key_cache, value_cache = fixed_k, fixed_v
|
||||
|
||||
if is_quantized_kv_cache(self.kv_cache_dtype):
|
||||
# queries are quantized in the attention layer
|
||||
|
||||
Reference in New Issue
Block a user