Amd/deepseek v4 rebase main 0509 (#24933)

Co-authored-by: root <root@smci355-ccs-aus-m12-33.cs-aus.dcgpu>
Co-authored-by: wunhuang <wunhuang@amd.com>
Co-authored-by: Thomas Wang <1am9trash@gmail.com>
Co-authored-by: Xinyi Song <86638975+RolaoDenthu@users.noreply.github.com>
Co-authored-by: HaiShaw <hixiao@gmail.com>
Co-authored-by: amd-danli103 <danli103@amd.com>
Co-authored-by: Lin, Soga <soga.lin@amd.com>
Co-authored-by: Raiden-Makoto <Raiden-Makoto@users.noreply.github.com>
Co-authored-by: Hubert Lu <55214931+hubertlu-tw@users.noreply.github.com>
Co-authored-by: yichiche@amd.com <jacky.cheng>
Co-authored-by: yctseng0211 <yctseng@amd.com>
Co-authored-by: Bingxu Chen <bingxche@amd.com>
This commit is contained in:
kk
2026-05-18 09:15:07 -07:00
committed by GitHub
co-authored by root wunhuang Thomas Wang Xinyi Song HaiShaw amd-danli103 Lin, Soga Raiden-Makoto Hubert Lu yichiche@amd.com yctseng0211 Bingxu Chen
parent 110bbdcad7
commit 866793c502
17 changed files with 3677 additions and 69 deletions
+26
View File
@@ -13,6 +13,13 @@ from sglang.jit_kernel.utils import (
make_cpp_args,
)
from sglang.srt.environ import envs
from sglang.srt.utils import get_bool_env_var, is_hip
_is_hip = is_hip()
_use_aiter = get_bool_env_var("SGLANG_USE_AITER") and _is_hip
if _use_aiter:
from aiter.tuned_gemm import tgemm
if TYPE_CHECKING:
from tvm_ffi.module import Module
@@ -644,6 +651,23 @@ def fused_rope(
positions: torch.Tensor,
inverse: bool = False,
) -> None:
"""Apply rotary embeddings to both Q and K in a single fused CUDA kernel.
Args:
q: [batch_size, num_q_heads, rope_dim] bfloat16
k: [batch_size, num_k_heads, rope_dim] bfloat16 or None
freqs_cis: [max_seq_len, rope_dim // 2] complex64 (full table)
positions: [batch_size] int32 or int64, indices into freqs_cis
inverse: if True, apply inverse rotation (conjugate freqs)
"""
if _is_hip:
from sglang.srt.layers.deepseek_v4_rope import apply_rotary_emb_triton
apply_rotary_emb_triton(q, freqs_cis, positions=positions, inverse=inverse)
if k is not None:
apply_rotary_emb_triton(k, freqs_cis, positions=positions, inverse=inverse)
return
freqs_real = torch.view_as_real(freqs_cis).flatten(-2).contiguous()
module = _jit_fused_rope_module()
module.forward(q, k, freqs_real, positions, inverse)
@@ -1029,5 +1053,7 @@ def _dispatch_bf16_fp32_backend(
z = x.new_empty(x.size(0), y.size(0), dtype=torch.float32)
deep_gemm.bf16_gemm_nt(x, y, z)
return z
elif _use_aiter:
return tgemm.mm(x, y, otype=torch.float32)
else:
return torch.nn.functional.linear(x.float(), y.float())