Reland [1/2] Optimizations and refactors about quant kernel (#10312)

Co-authored-by: Yineng Zhang <me@zhyncs.com>
This commit is contained in:
fzyzcjy
2025-10-11 15:59:03 +08:00
committed by GitHub
co-authored by Yineng Zhang
parent 129d299278
commit 21337b22b9
13 changed files with 1065 additions and 178 deletions
@@ -8,11 +8,17 @@ import torch
import triton
import triton.language as tl
from sglang.srt.utils import get_device_name, is_cuda
from sglang.srt.utils import get_bool_env_var, get_device_name, is_cuda
_is_cuda = is_cuda()
if _is_cuda:
from sgl_kernel import sgl_per_token_group_quant_int8
# Temporary
try:
from sgl_kernel import sgl_per_token_group_quant_8bit
except ImportError:
from sgl_kernel import (
sgl_per_token_group_quant_int8 as sgl_per_token_group_quant_8bit,
)
logger = logging.getLogger(__name__)
@@ -187,6 +193,7 @@ def sglang_per_token_group_quant_int8(
group_size: int,
eps: float = 1e-10,
dtype: torch.dtype = torch.int8,
enable_v2: Optional[bool] = None,
):
assert (
x.shape[-1] % group_size == 0
@@ -204,7 +211,9 @@ def sglang_per_token_group_quant_int8(
dtype=torch.float32,
)
sgl_per_token_group_quant_int8(x, x_q, x_s, group_size, eps, int8_min, int8_max)
sgl_per_token_group_quant_8bit(
x, x_q, x_s, group_size, eps, int8_min, int8_max, enable_v2=enable_v2
)
return x_q, x_s