[CPU] Refactor CPU attention backend (#27954)
Signed-off-by: jiang1.li <jiang1.li@intel.com>
This commit is contained in:
@@ -2583,6 +2583,88 @@ def onednn_scaled_mm(
|
||||
return output
|
||||
|
||||
|
||||
def cpu_attn_get_scheduler_metadata(
|
||||
num_reqs: int,
|
||||
num_heads: int,
|
||||
num_kv_heads: int,
|
||||
head_dim: int,
|
||||
seq_lens: torch.Tensor,
|
||||
dtype: torch.dtype,
|
||||
query_start_loc: torch.Tensor,
|
||||
causal: bool,
|
||||
sliding_window_size: int,
|
||||
isa: str,
|
||||
enable_kv_split: bool,
|
||||
) -> torch.Tensor:
|
||||
sheduler_metadata = torch.ops._C.get_scheduler_metadata(
|
||||
num_reqs,
|
||||
num_heads,
|
||||
num_kv_heads,
|
||||
head_dim,
|
||||
seq_lens,
|
||||
dtype,
|
||||
query_start_loc,
|
||||
causal,
|
||||
sliding_window_size,
|
||||
isa,
|
||||
enable_kv_split,
|
||||
)
|
||||
return sheduler_metadata
|
||||
|
||||
|
||||
def cpu_attn_reshape_and_cache(
|
||||
key: torch.Tensor,
|
||||
value: torch.Tensor,
|
||||
key_cache: torch.Tensor,
|
||||
value_cache: torch.Tensor,
|
||||
slot_mapping: torch.Tensor,
|
||||
isa: str,
|
||||
) -> None:
|
||||
torch.ops._C.cpu_attn_reshape_and_cache(
|
||||
key,
|
||||
value,
|
||||
key_cache,
|
||||
value_cache,
|
||||
slot_mapping,
|
||||
isa,
|
||||
)
|
||||
|
||||
|
||||
def cpu_attention_with_kv_cache(
|
||||
query: torch.Tensor,
|
||||
key_cache: torch.Tensor,
|
||||
value_cache: torch.Tensor,
|
||||
output: torch.Tensor,
|
||||
query_start_loc: torch.Tensor,
|
||||
seq_lens: torch.Tensor,
|
||||
scale: float,
|
||||
causal: bool,
|
||||
alibi_slopes: torch.Tensor | None,
|
||||
sliding_window: tuple[int, int],
|
||||
block_table: torch.Tensor,
|
||||
softcap: float,
|
||||
scheduler_metadata: torch.Tensor,
|
||||
s_aux: torch.Tensor | None,
|
||||
) -> None:
|
||||
torch.ops._C.cpu_attention_with_kv_cache(
|
||||
query,
|
||||
key_cache,
|
||||
value_cache,
|
||||
output,
|
||||
query_start_loc,
|
||||
seq_lens,
|
||||
scale,
|
||||
causal,
|
||||
alibi_slopes,
|
||||
sliding_window[0],
|
||||
sliding_window[1],
|
||||
block_table,
|
||||
softcap,
|
||||
scheduler_metadata,
|
||||
s_aux,
|
||||
)
|
||||
|
||||
|
||||
if hasattr(torch.ops._qutlass_C, "matmul_mxf4_bf16_tn"):
|
||||
|
||||
@register_fake("_qutlass_C::matmul_mxf4_bf16_tn")
|
||||
|
||||
Reference in New Issue
Block a user