[feat] Add FP8 per-tensor Q scale support to Triton attention backend (#42080)
Signed-off-by: Dom Brown <3886319+DomBrown@users.noreply.github.com>
This commit is contained in:
@@ -39,6 +39,7 @@ from vllm.v1.attention.ops.triton_reshape_and_cache_flash import (
|
||||
from vllm.v1.attention.ops.triton_unified_attention import unified_attention
|
||||
from vllm.v1.kv_cache_interface import (
|
||||
AttentionSpec,
|
||||
KVQuantMode,
|
||||
get_kv_quant_mode,
|
||||
kv_cache_uses_per_token_head_scales,
|
||||
)
|
||||
@@ -585,6 +586,7 @@ class TritonAttentionImpl(AttentionImpl):
|
||||
if key_cache.dtype == torch.uint8:
|
||||
key_cache = key_cache.view(self.fp8_dtype)
|
||||
value_cache = value_cache.view(self.fp8_dtype)
|
||||
q_descale = None
|
||||
k_descale = None
|
||||
v_descale = None
|
||||
k_scale_cache = self._k_scale_cache
|
||||
@@ -592,17 +594,24 @@ class TritonAttentionImpl(AttentionImpl):
|
||||
# FP8 per-tensor / auto path (original flow).
|
||||
else:
|
||||
key_cache, value_cache = kv_cache.unbind(1)
|
||||
if is_quantized_kv_cache(self.kv_cache_dtype):
|
||||
if key_cache.dtype != self.fp8_dtype:
|
||||
key_cache = key_cache.view(self.fp8_dtype)
|
||||
value_cache = value_cache.view(self.fp8_dtype)
|
||||
assert layer._q_scale_float == 1.0, (
|
||||
"A non 1.0 q_scale is not currently supported."
|
||||
)
|
||||
if (
|
||||
is_quantized_kv_cache(self.kv_cache_dtype)
|
||||
and key_cache.dtype != self.fp8_dtype
|
||||
):
|
||||
key_cache = key_cache.view(self.fp8_dtype)
|
||||
value_cache = value_cache.view(self.fp8_dtype)
|
||||
descale_shape = (
|
||||
attn_metadata.query_start_loc.shape[0] - 1,
|
||||
key_cache.shape[2],
|
||||
)
|
||||
q_descale = (
|
||||
layer._q_scale
|
||||
if (
|
||||
self._kv_quant_mode == KVQuantMode.FP8_PER_TENSOR
|
||||
and query.dtype == self.fp8_dtype
|
||||
)
|
||||
else None
|
||||
)
|
||||
k_descale = layer._k_scale.expand(descale_shape)
|
||||
v_descale = layer._v_scale.expand(descale_shape)
|
||||
k_scale_cache = None
|
||||
@@ -638,7 +647,7 @@ class TritonAttentionImpl(AttentionImpl):
|
||||
window_size=self.sliding_window,
|
||||
block_table=block_table,
|
||||
softcap=self.logits_soft_cap,
|
||||
q_descale=None, # Not supported
|
||||
q_descale=q_descale,
|
||||
k_descale=k_descale,
|
||||
v_descale=v_descale,
|
||||
seq_threshold_3D=seq_threshold_3D,
|
||||
|
||||
Reference in New Issue
Block a user