sgl-project--sglang
94057c3d3e
PR Test (NPU) / check-changes (push) Has been cancelled
PR Test (NPU) / pr-gate (push) Has been cancelled
PR Test (NPU) / set-image-config (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-4-npu-a3 (push) Has been cancelled
PR Test (NPU) / stage-b-test-16-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-1-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-2-npu-a3 (push) Has been cancelled
PR Test (Arm64) / pr-gate (push) Has been cancelled
PR Test (Arm64) / check-changes (push) Has been cancelled
PR Test (Arm64) / build-test (push) Has been cancelled
PR Test (sgl-router) / gate (push) Has been cancelled
PR Test (sgl-router) / tier-1 — lint (push) Has been cancelled
PR Test (sgl-router) / tier-2 — build + test (push) Has been cancelled
PR Test (sgl-router) / tier-3 — docker (placeholder) (push) Has been cancelled
PR Test (sgl-router) / tier-3 — k8s integration (push) Has been cancelled
PR Test (sgl-router) / tier-3 — e2e (push) Has been cancelled
PR Test (sgl-router) / finish (push) Has been cancelled
PR Test (NPU) / single-node-poc (map[name:qwen3_6_27b_w8a8_1p_in64k_out1k_50ms runner:linux-aarch64-a3-2 test_case:test/registered/ascend/performance/qwen3_6_27b/test_npu_qwen3_6_27b_w8a8_1p_in64k_out1k_50ms.py test_type:perf]) (push) Has been cancelled
PR Test (NPU) / pr-test-npu-finish (push) Has been cancelled
PR Test (Xeon) / pr-gate (push) Has been cancelled
PR Test (Xeon) / check-changes (push) Has been cancelled
PR Test (Xeon) / build-test (, xeon-gnr, base-b-test-cpu) (push) Has been cancelled
PR Test (XPU) / check-changes (push) Has been cancelled
PR Test (XPU) / pr-gate (push) Has been cancelled
PR Test (XPU) / stage-a-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / wait-for-stage-a (push) Has been cancelled
PR Test (XPU) / stage-b-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / finish (push) Has been cancelled
CI Model Inventory / build-inventory (push) Has been cancelled
Lint / lint (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Compilation Check (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Manual Policy (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Request Processing (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Summary (push) Has been cancelled
PR Test (SMG) / build-wheel (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on windows (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (x86_64 - auto) (push) Has been cancelled
PR Test (SMG) / python-unit-tests (push) Has been cancelled
PR Test (SMG) / unit-tests (push) Has been cancelled
PR Test (SMG) / benchmarks (push) Has been cancelled
PR Test (SMG) / chat-completions (push) Has been cancelled
PR Test (SMG) / chat-completions-4gpu (push) Has been cancelled
PR Test (SMG) / e2e (push) Has been cancelled
PR Test (SMG) / docker-build-test (push) Has been cancelled
PR Test (SMG) / k8s-integration (push) Has been cancelled
PR Test (SMG) / finish (push) Has been cancelled
PR Test (SMG) / summarize-benchmarks (push) Has been cancelled
Release SGLang Model Gateway Docker Image / publish (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Build SDist (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Upload to PyPI (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (aarch64, 12.9, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (x86_64, 12.9, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu129 (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (aarch64, 13.0, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (x86_64, 13.0, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu130 (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 700) (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 720) (push) Has been cancelled
Release SGLang Kernels / release-rocm700 (push) Has been cancelled
Release SGLang Kernels / release-rocm720 (push) Has been cancelled
Release SGLang Kernels / build-musa43 (43, 3.10) (push) Has been cancelled
Release SGLang Kernels / release-musa43 (push) Has been cancelled
154 行
5.4 KiB
Python
154 行
5.4 KiB
Python
import unittest
|
|
|
|
import torch
|
|
from utils import precision
|
|
|
|
from sglang.test.ci.ci_register import register_cpu_ci
|
|
from sglang.test.test_utils import CustomTestCase
|
|
|
|
register_cpu_ci(est_time=10, suite="base-b-test-cpu")
|
|
register_cpu_ci(est_time=10, suite="base-b-test-cpu-arm64")
|
|
|
|
torch.manual_seed(1234)
|
|
|
|
|
|
def fix_query_key_value_ordering_reshape_cat(
|
|
mixed_qkvz, mixed_ba, num_k_heads, num_v_heads, attn_tp_size, head_k_dim, head_v_dim
|
|
):
|
|
new_tensor_shape_qkvz = mixed_qkvz.size()[:-1] + (
|
|
num_k_heads // attn_tp_size,
|
|
(
|
|
head_k_dim
|
|
+ head_k_dim
|
|
+ (head_v_dim + head_v_dim) * num_v_heads // num_k_heads
|
|
),
|
|
)
|
|
new_tensor_shape_ba = mixed_ba.size()[:-1] + (
|
|
num_k_heads // attn_tp_size,
|
|
2 * num_v_heads // num_k_heads,
|
|
)
|
|
|
|
mixed_qkvz = mixed_qkvz.view(*new_tensor_shape_qkvz)
|
|
mixed_ba = mixed_ba.view(*new_tensor_shape_ba)
|
|
|
|
split_arg_list_qkvz = [
|
|
head_k_dim,
|
|
head_k_dim,
|
|
(num_v_heads // num_k_heads * head_v_dim),
|
|
(num_v_heads // num_k_heads * head_v_dim),
|
|
]
|
|
split_arg_list_ba = [
|
|
num_v_heads // num_k_heads,
|
|
num_v_heads // num_k_heads,
|
|
]
|
|
# [b, sq, ng, (hn + hn + np/ng * hn + np/ng + np/ng)]
|
|
# --> [b, sq, ng, hn], [b, sq, ng, hn], [b, sq, ng, np/ng * hn], [b, sq, ng, np/ng * hn], [b, sq, ng, np/ng], [b, sq, ng, np/ng]
|
|
query, key, value, z = torch.split(mixed_qkvz, split_arg_list_qkvz, dim=2)
|
|
b, a = torch.split(mixed_ba, split_arg_list_ba, dim=2)
|
|
|
|
# [b, sq, ng, np/ng * hn] -> [b, sq, np, hn]
|
|
value = value.reshape(value.size(0), -1, head_v_dim)
|
|
z = z.reshape(z.size(0), -1, head_v_dim)
|
|
b = b.reshape(b.size(0), num_v_heads // attn_tp_size)
|
|
a = a.reshape(a.size(0), num_v_heads // attn_tp_size)
|
|
query, key, value = map(lambda x: x.reshape(x.shape[0], -1), (query, key, value))
|
|
mixed_qkv = torch.cat((query, key, value), dim=-1)
|
|
|
|
return mixed_qkv, z, b, a
|
|
|
|
|
|
def fix_query_key_value_ordering_reshape_cat_contiguous(
|
|
mixed_qkvz: torch.Tensor,
|
|
mixed_ba: torch.Tensor,
|
|
key_dim: int,
|
|
value_dim: int,
|
|
num_v_heads: int,
|
|
head_v_dim: int,
|
|
attn_tp_size: int,
|
|
):
|
|
"""
|
|
Derives `query`, `key` and `value` tensors from `mixed_qkvzba`.
|
|
"""
|
|
k_tp = key_dim // attn_tp_size
|
|
v_tp = value_dim // attn_tp_size
|
|
nv_tp = num_v_heads // attn_tp_size
|
|
|
|
# Directly split, no head group reshape
|
|
query, key, value, z = mixed_qkvz.split([k_tp, k_tp, v_tp, v_tp], dim=-1)
|
|
b, a = mixed_ba.split([nv_tp, nv_tp], dim=-1)
|
|
|
|
# value / z reshape to (seq, num_v_heads/tp, head_v_dim)
|
|
value = value.reshape(value.size(0), -1, head_v_dim)
|
|
z = z.reshape(z.size(0), -1, head_v_dim)
|
|
query, key, value = map(lambda x: x.reshape(x.shape[0], -1), (query, key, value))
|
|
mixed_qkv = torch.cat((query, key, value), dim=-1)
|
|
return mixed_qkv, z, b, a
|
|
|
|
|
|
class TestQwen3(CustomTestCase):
|
|
def test_fused_qkvzba_split_reshape_cat(self):
|
|
mixed_qkvz = torch.rand(1024, 12288, dtype=torch.bfloat16)
|
|
mixed_ba = torch.rand(1024, 64, dtype=torch.bfloat16)
|
|
head_k_dim = 128
|
|
head_v_dim = 128
|
|
num_v_heads = 32
|
|
num_k_heads = 16
|
|
attn_tp_size = 1
|
|
mixed_qkv_ref, z_ref, b_ref, a_ref = fix_query_key_value_ordering_reshape_cat(
|
|
mixed_qkvz,
|
|
mixed_ba,
|
|
num_k_heads,
|
|
num_v_heads,
|
|
attn_tp_size,
|
|
head_k_dim,
|
|
head_v_dim,
|
|
)
|
|
num_heads_qk = num_k_heads // attn_tp_size
|
|
num_heads_v = num_v_heads // attn_tp_size
|
|
mixed_qkv, z, b, a = torch.ops.sgl_kernel.fused_qkvzba_split_reshape_cat_cpu(
|
|
mixed_qkvz, mixed_ba, num_heads_qk, num_heads_v, head_k_dim, head_v_dim
|
|
)
|
|
atol = rtol = precision[mixed_qkv.dtype]
|
|
torch.testing.assert_close(mixed_qkv, mixed_qkv_ref, atol=atol, rtol=rtol)
|
|
torch.testing.assert_close(z, z_ref, atol=atol, rtol=rtol)
|
|
torch.testing.assert_close(b, b_ref, atol=atol, rtol=rtol)
|
|
torch.testing.assert_close(a, a_ref, atol=atol, rtol=rtol)
|
|
|
|
def test_fused_qkvzba_split_reshape_cat_contiguous(self):
|
|
mixed_qkvz = torch.rand(1, 12288, dtype=torch.bfloat16)
|
|
mixed_ba = torch.rand(1, 64, dtype=torch.bfloat16)
|
|
head_k_dim = 128
|
|
head_v_dim = 128
|
|
num_v_heads = 32
|
|
num_k_heads = 16
|
|
attn_tp_size = 1
|
|
key_dim = head_k_dim * num_k_heads
|
|
value_dim = head_v_dim * num_v_heads
|
|
mixed_qkv_ref, z_ref, b_ref, a_ref = (
|
|
fix_query_key_value_ordering_reshape_cat_contiguous(
|
|
mixed_qkvz,
|
|
mixed_ba,
|
|
key_dim,
|
|
value_dim,
|
|
num_v_heads,
|
|
head_v_dim,
|
|
attn_tp_size,
|
|
)
|
|
)
|
|
num_heads_qk = num_k_heads // attn_tp_size
|
|
num_heads_v = num_v_heads // attn_tp_size
|
|
mixed_qkv, z, b, a = (
|
|
torch.ops.sgl_kernel.fused_qkvzba_split_reshape_cat_contiguous_cpu(
|
|
mixed_qkvz, mixed_ba, num_heads_qk, num_heads_v, head_k_dim, head_v_dim
|
|
)
|
|
)
|
|
atol = rtol = precision[mixed_qkv.dtype]
|
|
torch.testing.assert_close(mixed_qkv, mixed_qkv_ref, atol=atol, rtol=rtol)
|
|
torch.testing.assert_close(z, z_ref, atol=atol, rtol=rtol)
|
|
torch.testing.assert_close(b, b_ref, atol=atol, rtol=rtol)
|
|
torch.testing.assert_close(a, a_ref, atol=atol, rtol=rtol)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|