[4/n jit_kernel restruct] speed up CI tests and add benchmark workflow (#20268)
This commit is contained in:
@@ -3,6 +3,8 @@ import itertools
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from sglang.jit_kernel.utils import get_ci_test_range
|
||||
|
||||
|
||||
def sglang_jit_fused_add_rmsnorm(
|
||||
input: torch.Tensor, residual: torch.Tensor, weight: torch.Tensor, eps: float
|
||||
@@ -22,7 +24,11 @@ def flashinfer_fused_add_rmsnorm(
|
||||
|
||||
BS_LIST = [2**n for n in range(0, 14)]
|
||||
BS_LIST += [x + 1 + i for i, x in enumerate(BS_LIST)]
|
||||
HIDDEN_SIZE_LIST = [512, 1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192]
|
||||
BS_LIST = get_ci_test_range(BS_LIST, [1, 9, 256, 4109])
|
||||
HIDDEN_SIZE_LIST = get_ci_test_range(
|
||||
[512, 1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192],
|
||||
[512, 2048, 8192],
|
||||
)
|
||||
DEVICE = "cuda"
|
||||
DTYPE = torch.bfloat16
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import pytest
|
||||
import torch
|
||||
import triton
|
||||
|
||||
from sglang.jit_kernel.utils import get_ci_test_range
|
||||
|
||||
|
||||
def sglang_aot_qknorm(
|
||||
q: torch.Tensor,
|
||||
@@ -61,9 +63,10 @@ def torch_impl_qknorm(
|
||||
|
||||
BS_LIST = [2**n for n in range(0, 14)]
|
||||
BS_LIST += [x + 1 + i for i, x in enumerate(BS_LIST)]
|
||||
N_K_LIST = [2, 4]
|
||||
N_Q_LIST = [8, 16]
|
||||
HEAD_DIM_LIST = [64, 128, 256, 512, 1024]
|
||||
BS_LIST = get_ci_test_range(BS_LIST, [1, 9, 256, 4109])
|
||||
N_K_LIST = get_ci_test_range([2, 4], [2, 4])
|
||||
N_Q_LIST = get_ci_test_range([8, 16], [8, 16])
|
||||
HEAD_DIM_LIST = get_ci_test_range([64, 128, 256, 512, 1024], [64, 256, 1024])
|
||||
DEVICE = "cuda"
|
||||
DTYPE = torch.bfloat16
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import pytest
|
||||
import torch
|
||||
import triton
|
||||
|
||||
from sglang.jit_kernel.utils import get_ci_test_range
|
||||
|
||||
|
||||
def sglang_jit_qknorm_across_heads(
|
||||
q: torch.Tensor,
|
||||
@@ -46,7 +48,8 @@ def torch_impl_qknorm_across_heads(
|
||||
|
||||
BS_LIST = [2**n for n in range(0, 14)]
|
||||
BS_LIST += [x + 1 + i for i, x in enumerate(BS_LIST)]
|
||||
HIDDEN_DIM_LIST = [512, 1024, 2048, 4096]
|
||||
BS_LIST = get_ci_test_range(BS_LIST, [1, 9, 256, 4109])
|
||||
HIDDEN_DIM_LIST = get_ci_test_range([512, 1024, 2048, 4096], [512, 2048, 4096])
|
||||
DEVICE = "cuda"
|
||||
DTYPE = torch.bfloat16
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import pytest
|
||||
import torch
|
||||
import triton
|
||||
|
||||
from sglang.jit_kernel.utils import get_ci_test_range
|
||||
|
||||
|
||||
def sglang_jit_rmsnorm(input: torch.Tensor, weight: torch.Tensor) -> None:
|
||||
from sglang.jit_kernel.norm import rmsnorm
|
||||
@@ -19,7 +21,11 @@ def flashinfer_rmsnorm(input: torch.Tensor, weight: torch.Tensor) -> None:
|
||||
|
||||
BS_LIST = [2**n for n in range(0, 14)]
|
||||
BS_LIST += [x + 1 + i for i, x in enumerate(BS_LIST)]
|
||||
HIDDEN_SIZE_LIST = [512, 1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192]
|
||||
BS_LIST = get_ci_test_range(BS_LIST, [1, 9, 256, 4109])
|
||||
HIDDEN_SIZE_LIST = get_ci_test_range(
|
||||
[512, 1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192],
|
||||
[512, 2048, 8192],
|
||||
)
|
||||
DEVICE = "cuda"
|
||||
DTYPE = torch.bfloat16
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ import pytest
|
||||
import torch
|
||||
import triton
|
||||
|
||||
from sglang.jit_kernel.utils import get_ci_test_range
|
||||
|
||||
DEVICE = "cuda"
|
||||
DTYPE = torch.bfloat16
|
||||
MAX_SEQ_LEN = 131072 # common seq length
|
||||
@@ -87,11 +89,16 @@ def torch_impl_rope(
|
||||
|
||||
BS_LIST = [2**x for x in range(12)]
|
||||
BS_LIST += [x + 1 for x in BS_LIST] # odd sizes to stress non-aligned paths
|
||||
NUM_KV_HEADS_LIST = [1, 2, 8]
|
||||
GQA_RATIO = [1, 4, 8]
|
||||
ROPE_DIM_LIST = [64, 128, 256, 512]
|
||||
BS_LIST = get_ci_test_range(BS_LIST, [1, 129, 2048, 2049])
|
||||
NUM_KV_HEADS_LIST = get_ci_test_range([1, 2, 8], [1, 8])
|
||||
GQA_RATIO = get_ci_test_range([1, 4, 8], [1, 8])
|
||||
ROPE_DIM_LIST = get_ci_test_range([64, 128, 256, 512], [64, 256])
|
||||
IS_NEOX_LIST = [False, True]
|
||||
DTYPE_LIST = [torch.bfloat16, torch.float16]
|
||||
DTYPE_LIST = get_ci_test_range(
|
||||
[torch.bfloat16, torch.float16], [torch.bfloat16, torch.float16]
|
||||
)
|
||||
PARTIAL_ROPE_DIM_LIST = get_ci_test_range([64, 80, 96, 128], [64, 96])
|
||||
HEAD_DIM_LIST = get_ci_test_range([64, 128, 256], [64, 256])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("batch_size", BS_LIST)
|
||||
@@ -151,8 +158,8 @@ def test_rope_position_dtypes(dtype: torch.dtype) -> None:
|
||||
|
||||
@pytest.mark.parametrize("batch_size", BS_LIST)
|
||||
@pytest.mark.parametrize("is_neox", IS_NEOX_LIST)
|
||||
@pytest.mark.parametrize("rope_dim", [64, 80, 96, 128])
|
||||
@pytest.mark.parametrize("head_dim", [64, 128, 256])
|
||||
@pytest.mark.parametrize("rope_dim", PARTIAL_ROPE_DIM_LIST)
|
||||
@pytest.mark.parametrize("head_dim", HEAD_DIM_LIST)
|
||||
def test_partial_rope(batch_size: int, is_neox: bool, rope_dim: int, head_dim: int):
|
||||
if head_dim < rope_dim:
|
||||
pytest.skip("Invalid config: head_dim must be >= rope_dim.")
|
||||
|
||||
@@ -4,10 +4,14 @@ import pytest
|
||||
import torch
|
||||
|
||||
from sglang.jit_kernel.kvcache import can_use_store_cache, store_cache
|
||||
from sglang.jit_kernel.utils import get_ci_test_range
|
||||
|
||||
BS_LIST = [2**n for n in range(0, 15)]
|
||||
BS_LIST += [x + 1 + i for i, x in enumerate(BS_LIST)]
|
||||
HIDDEN_DIMS = [64, 128, 256, 512, 1024, 96, 98, 100]
|
||||
BS_LIST = get_ci_test_range(BS_LIST, [1, 9, 256, 16399])
|
||||
HIDDEN_DIMS = get_ci_test_range(
|
||||
[64, 128, 256, 512, 1024, 96, 98, 100], [64, 512, 1024, 98]
|
||||
)
|
||||
CACHE_SIZE = 1024 * 1024
|
||||
DTYPE = torch.bfloat16
|
||||
DEVICE = "cuda"
|
||||
@@ -32,8 +36,8 @@ def test_store_cache(batch_size: int, element_dim: int) -> None:
|
||||
|
||||
|
||||
# Smaller subset for targeted tests below
|
||||
REPR_BS = [1, 7, 128]
|
||||
REPR_DIMS = [64, 128, 512, 1024, 96]
|
||||
REPR_BS = get_ci_test_range([1, 7, 128], [1, 128])
|
||||
REPR_DIMS = get_ci_test_range([64, 128, 512, 1024, 96], [64, 1024, 96])
|
||||
SMALL_CACHE = 4096
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,26 @@ except Exception:
|
||||
from sglang.jit_kernel.timestep_embedding import (
|
||||
timestep_embedding as timestep_embedding_cuda,
|
||||
)
|
||||
from sglang.jit_kernel.utils import get_ci_test_range
|
||||
|
||||
CORRECTNESS_BATCH_SIZES = get_ci_test_range(
|
||||
[1, 2, 8, 128, 256, 512, 1536, 2048, 4096, 11008, 16384],
|
||||
[1, 128, 2048, 16384],
|
||||
)
|
||||
CORRECTNESS_DIMS = get_ci_test_range(
|
||||
[32, 128, 256, 512, 1536, 2048, 4096, 8192],
|
||||
[32, 512, 8192],
|
||||
)
|
||||
DIFFUSERS_BATCH_SIZES = get_ci_test_range(
|
||||
[1, 2, 8, 128, 256, 512, 1536, 2048, 16384],
|
||||
[1, 512, 16384],
|
||||
)
|
||||
DIFFUSERS_DIMS = get_ci_test_range([32, 256, 512, 1536, 8192], [32, 512, 8192])
|
||||
DTYPES = get_ci_test_range(
|
||||
[torch.float16, torch.bfloat16, torch.float32],
|
||||
[torch.float16, torch.bfloat16],
|
||||
)
|
||||
SCALES = get_ci_test_range([1, 0.01], [1, 0.01])
|
||||
|
||||
|
||||
def get_timestep_embedding_reference(
|
||||
@@ -47,11 +67,9 @@ def get_timestep_embedding_reference(
|
||||
return emb
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"batch_size", [1, 2, 8, 128, 256, 512, 1536, 2048, 4096, 11008, 16384]
|
||||
)
|
||||
@pytest.mark.parametrize("dim", [32, 128, 256, 512, 1536, 2048, 4096, 8192])
|
||||
@pytest.mark.parametrize("dtype", [torch.float16, torch.bfloat16, torch.float32])
|
||||
@pytest.mark.parametrize("batch_size", CORRECTNESS_BATCH_SIZES)
|
||||
@pytest.mark.parametrize("dim", CORRECTNESS_DIMS)
|
||||
@pytest.mark.parametrize("dtype", DTYPES)
|
||||
def test_timestep_embedding_correctness_with_sgld(batch_size, dim, dtype):
|
||||
device = "cuda"
|
||||
t = torch.randint(low=0, high=1000, size=(batch_size,), device=device).to(dtype)
|
||||
@@ -64,12 +82,12 @@ def test_timestep_embedding_correctness_with_sgld(batch_size, dim, dtype):
|
||||
torch.testing.assert_close(torch_output, cuda_output, atol=1e-3, rtol=1e-3)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("batch_size", [1, 2, 8, 128, 256, 512, 1536, 2048, 16384])
|
||||
@pytest.mark.parametrize("dim", [32, 256, 512, 1536, 8192])
|
||||
@pytest.mark.parametrize("dtype", [torch.float16, torch.bfloat16, torch.float32])
|
||||
@pytest.mark.parametrize("batch_size", DIFFUSERS_BATCH_SIZES)
|
||||
@pytest.mark.parametrize("dim", DIFFUSERS_DIMS)
|
||||
@pytest.mark.parametrize("dtype", DTYPES)
|
||||
@pytest.mark.parametrize("flip_sin_to_cos", [False, True])
|
||||
@pytest.mark.parametrize("downscale_freq_shift", [0, 1])
|
||||
@pytest.mark.parametrize("scale", [1, 0.01])
|
||||
@pytest.mark.parametrize("scale", SCALES)
|
||||
def test_timestep_embedding_correctness_with_diffusers(
|
||||
batch_size, dim, flip_sin_to_cos, downscale_freq_shift, scale, dtype
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user