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
112 lines
3.6 KiB
Python
112 lines
3.6 KiB
Python
import sys
|
|
|
|
import pytest
|
|
import torch
|
|
from sgl_kernel import fp8_scaled_mm
|
|
|
|
|
|
def torch_scaled_mm(a, b, scale_a, scale_b, out_dtype, bias):
|
|
o = torch.matmul(a.to(torch.float32), b.to(torch.float32))
|
|
o = o.to(torch.float32)
|
|
temp1 = o * scale_a.view(-1, 1)
|
|
temp2 = temp1 * scale_b.view(1, -1)
|
|
final = temp2.to(out_dtype)
|
|
if bias is not None:
|
|
final = final + bias.view(1, -1)
|
|
return final
|
|
|
|
|
|
def _test_accuracy_once(M, N, K, with_bias, out_dtype, device):
|
|
fp8_info = torch.finfo(torch.float8_e4m3fn)
|
|
fp8_max, fp8_min = fp8_info.max, fp8_info.min
|
|
a_fp32 = (torch.rand(M, K, dtype=torch.float32, device=device) - 0.5) * 2 * fp8_max
|
|
a_fp8 = a_fp32.clamp(min=fp8_min, max=fp8_max).to(torch.float8_e4m3fn)
|
|
b_fp32 = (torch.rand(N, K, dtype=torch.float32, device=device) - 0.5) * 2 * fp8_max
|
|
b_fp8 = b_fp32.clamp(min=fp8_min, max=fp8_max).to(torch.float8_e4m3fn)
|
|
scale_a = torch.randn((M,), device=device, dtype=torch.float32) * 0.001
|
|
scale_b = torch.randn((N,), device=device, dtype=torch.float32) * 0.001
|
|
if with_bias:
|
|
bias = torch.randn((N,), device=device, dtype=out_dtype)
|
|
else:
|
|
bias = None
|
|
b_fp8 = b_fp8.t()
|
|
o = torch_scaled_mm(a_fp8, b_fp8, scale_a, scale_b, out_dtype, bias)
|
|
o1 = fp8_scaled_mm(a_fp8, b_fp8, scale_a, scale_b, out_dtype, bias)
|
|
rtol = 0.02
|
|
atol = 1
|
|
torch.testing.assert_close(o, o1, rtol=rtol, atol=atol)
|
|
print(f"M={M}, N={N}, K={K}, with_bias={with_bias}, out_dtype={out_dtype}: OK")
|
|
|
|
|
|
@pytest.mark.parametrize("M", [1, 128, 512, 1024, 4096])
|
|
@pytest.mark.parametrize("N", [16, 128, 512, 1024, 4096])
|
|
@pytest.mark.parametrize("K", [512, 1024, 4096, 8192, 16384])
|
|
@pytest.mark.parametrize("with_bias", [True, False])
|
|
@pytest.mark.parametrize("out_dtype", [torch.bfloat16, torch.float16])
|
|
def test_accuracy(M, N, K, with_bias, out_dtype):
|
|
_test_accuracy_once(M, N, K, with_bias, out_dtype, "cuda")
|
|
|
|
|
|
# (M, N) shapes that exercise each dispatch bucket / boundary. K is varied
|
|
# separately below so every (M, N) is tested across multiple K values.
|
|
SM90_SWAP_AB_MN_SHAPES = [
|
|
(1, 128),
|
|
(1, 4096),
|
|
(8, 1024),
|
|
(8, 8192),
|
|
(16, 1280),
|
|
(16, 8192),
|
|
(17, 128),
|
|
(17, 4096),
|
|
(32, 1024),
|
|
(32, 8192),
|
|
(64, 1280),
|
|
(64, 8192),
|
|
(65, 4096),
|
|
(96, 4096),
|
|
(128, 4096),
|
|
# Cluster-misaligned M_orig in the M64_smallN bucket (TileN=16, cluster_N=4).
|
|
# For M_orig in {17, 20, 33, 48}, grid_N = ceil(M_orig/16) in {2, 2, 3, 3},
|
|
# not a multiple of cluster_N=4. Explicit coverage so any can_implement
|
|
# failure or silent miscompute surfaces here.
|
|
(20, 128),
|
|
(20, 1024),
|
|
(20, 1280),
|
|
(33, 128),
|
|
(33, 1024),
|
|
(33, 1280),
|
|
(48, 128),
|
|
(48, 1024),
|
|
(48, 1280),
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"shape_mn", SM90_SWAP_AB_MN_SHAPES, ids=lambda s: f"M{s[0]}_N{s[1]}"
|
|
)
|
|
@pytest.mark.parametrize("K", [2048, 4096, 8192])
|
|
@pytest.mark.parametrize("with_bias", [True, False])
|
|
@pytest.mark.parametrize("out_dtype", [torch.bfloat16, torch.float16])
|
|
def test_accuracy_sm90_swap_ab(shape_mn, K, with_bias, out_dtype):
|
|
M, N = shape_mn
|
|
_test_accuracy_once(M, N, K, with_bias, out_dtype, "cuda")
|
|
|
|
|
|
PRODUCTION_LIKE_FP8_GEMM_CASES = [
|
|
(189, 4608, 8192, False, torch.bfloat16),
|
|
(3330, 256, 8192, False, torch.bfloat16),
|
|
(17, 9216, 2048, False, torch.bfloat16),
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"M,N,K,with_bias,out_dtype",
|
|
PRODUCTION_LIKE_FP8_GEMM_CASES,
|
|
)
|
|
def test_accuracy_production_like_shapes(M, N, K, with_bias, out_dtype):
|
|
_test_accuracy_once(M, N, K, with_bias, out_dtype, "cuda")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(pytest.main([__file__]))
|