[CPU] Optimize Qwen3-next model on CPU (#12525)
Co-authored-by: Ma Mingfei <mingfei.ma@intel.com> Co-authored-by: Fan Yin <1106310035@qq.com>
This commit is contained in:
@@ -78,7 +78,13 @@ from sgl_kernel.kvcacheio import (
|
||||
transfer_kv_per_layer,
|
||||
transfer_kv_per_layer_mla,
|
||||
)
|
||||
from sgl_kernel.mamba import causal_conv1d_fwd, causal_conv1d_update
|
||||
from sgl_kernel.mamba import (
|
||||
causal_conv1d_fn_cpu,
|
||||
causal_conv1d_fwd,
|
||||
causal_conv1d_update,
|
||||
causal_conv1d_update_cpu,
|
||||
chunk_gated_delta_rule_cpu,
|
||||
)
|
||||
from sgl_kernel.marlin import (
|
||||
awq_marlin_moe_repack,
|
||||
awq_marlin_repack,
|
||||
|
||||
@@ -48,3 +48,73 @@ def causal_conv1d_update(
|
||||
conv_state_indices,
|
||||
pad_slot_id,
|
||||
)
|
||||
|
||||
|
||||
def causal_conv1d_fn_cpu(
|
||||
mixed_qkv_transposed,
|
||||
conv_weights,
|
||||
bias,
|
||||
activation,
|
||||
conv_states,
|
||||
has_initial_state,
|
||||
cache_indices,
|
||||
query_start_loc,
|
||||
seq_lens_cpu,
|
||||
):
|
||||
return torch.ops.sgl_kernel.causal_conv1d_fwd_cpu(
|
||||
mixed_qkv_transposed,
|
||||
conv_weights,
|
||||
bias,
|
||||
conv_states,
|
||||
query_start_loc,
|
||||
cache_indices,
|
||||
has_initial_state,
|
||||
activation == "silu",
|
||||
-1,
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
def causal_conv1d_update_cpu(
|
||||
mixed_qkv, conv_states, conv_weights, bias, activation, conv_state_indices
|
||||
):
|
||||
return torch.ops.sgl_kernel.causal_conv1d_update_cpu(
|
||||
mixed_qkv,
|
||||
conv_states,
|
||||
conv_weights,
|
||||
bias,
|
||||
activation == "silu",
|
||||
None,
|
||||
conv_state_indices,
|
||||
-1,
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
def chunk_gated_delta_rule_cpu(
|
||||
q,
|
||||
k,
|
||||
v,
|
||||
g,
|
||||
beta,
|
||||
initial_state,
|
||||
cu_seqlens,
|
||||
head_first,
|
||||
use_qk_l2norm_in_kernel,
|
||||
):
|
||||
core_attn_out, last_recurrent_state = (
|
||||
torch.ops.sgl_kernel.chunk_gated_delta_rule_cpu(
|
||||
q,
|
||||
k,
|
||||
v,
|
||||
g,
|
||||
beta,
|
||||
initial_state,
|
||||
True, # output_final_state
|
||||
cu_seqlens,
|
||||
head_first,
|
||||
use_qk_l2norm_in_kernel,
|
||||
)
|
||||
)
|
||||
h = None # Todo: add return h support
|
||||
return core_attn_out, last_recurrent_state, h
|
||||
|
||||
Reference in New Issue
Block a user