Support kv8 (FP8) with torch_native attention backend (#12596)
Signed-off-by: Ho-Ren (Jack) Chuang <horenchuang@bytedance.com>
This commit is contained in:
committed by
GitHub
parent
183b65190a
commit
349ce2dd19
@@ -93,6 +93,11 @@ class TorchNativeAttnBackend(AttentionBackend):
|
||||
per_req_key = k_cache[per_req_tokens].movedim(0, query.dim() - 2)
|
||||
per_req_value = v_cache[per_req_tokens].movedim(0, query.dim() - 2)
|
||||
|
||||
if not (per_req_query.dtype == per_req_key.dtype == per_req_value.dtype):
|
||||
# scaled_dot_product_attention() expects query, key, and value to have the same dtype
|
||||
per_req_key = per_req_key.to(per_req_query.dtype)
|
||||
per_req_value = per_req_value.to(per_req_query.dtype)
|
||||
|
||||
per_req_out_redudant = (
|
||||
scaled_dot_product_attention(
|
||||
per_req_query_redudant.unsqueeze(0),
|
||||
@@ -162,6 +167,11 @@ class TorchNativeAttnBackend(AttentionBackend):
|
||||
per_req_key = k_cache[per_req_tokens].movedim(0, query.dim() - 2)
|
||||
per_req_value = v_cache[per_req_tokens].movedim(0, query.dim() - 2)
|
||||
|
||||
if not (per_req_query.dtype == per_req_key.dtype == per_req_value.dtype):
|
||||
# scaled_dot_product_attention() expects query, key, and value to have the same dtype
|
||||
per_req_key = per_req_key.to(per_req_query.dtype)
|
||||
per_req_value = per_req_value.to(per_req_query.dtype)
|
||||
|
||||
per_req_out = (
|
||||
scaled_dot_product_attention(
|
||||
per_req_query.unsqueeze(0),
|
||||
|
||||
Reference in New Issue
Block a user