[WIP]enable mxfp8 on nvidia sm120 (#19112)

Co-authored-by: Your Name <you@example.com>
This commit is contained in:
Henry
2026-03-01 22:06:43 -05:00
committed by GitHub
parent e3e71f275a
commit e5edf222cd
4 changed files with 23 additions and 8 deletions

View File

@@ -80,6 +80,7 @@ from sglang.srt.utils import (
is_npu,
is_sm90_supported,
is_sm100_supported,
is_sm120_supported,
log_info_on_rank0,
print_warning_once,
set_weight_attrs,
@@ -703,7 +704,9 @@ class Fp8MoEMethod(FusedMoEMethodBase):
cutlass_fp8_supported()
), "cutlass_fp8 MoE requires CUDA 12.0+ with SM90 or CUDA 12.4+ with SM89"
assert self.block_quant, "cutlass_fp8 MoE requires block quantization"
assert is_sm100_supported() or is_sm90_supported()
assert (
is_sm100_supported() or is_sm90_supported() or is_sm120_supported()
), "cutlass_fp8 MoE requires SM90, SM100, or SM120 GPUs"
@staticmethod
def is_deepgemm_moe_runner_backend_enabled() -> bool:

View File

@@ -37,6 +37,8 @@ from sglang.srt.utils import (
is_cpu,
is_cuda,
is_hip,
is_sm100_supported,
is_sm120_supported,
log_info_on_rank0,
)
from sglang.srt.utils.custom_op import register_custom_op
@@ -1286,9 +1288,16 @@ def mxfp8_block_scaled_matmul_triton(
block_m: int = 128,
block_n: int = 256,
block_k: int = 128,
num_stages: int = 4,
num_stages: Optional[int] = None,
) -> torch.Tensor:
"""Block-scaled matmul for MXFP8 using Triton dot_scaled."""
"""Block-scaled matmul for MXFP8 using Triton dot_scaled.
Args:
num_stages: Number of pipeline stages. If None, auto-selects based on GPU:
SM120: 1, SM100: 4.
"""
if num_stages is None:
num_stages = 1 if is_sm120_supported() else (4 if is_sm100_supported() else 1)
M, K = a.shape
N, K_b = b.shape
assert K == K_b

View File

@@ -41,6 +41,7 @@ from sglang.srt.utils import (
is_hip,
is_sm90_supported,
is_sm100_supported,
is_sm120_supported,
offloader,
)
@@ -670,8 +671,8 @@ def triton_mxfp8_blockscaled_linear(
bias: Optional[torch.Tensor] = None,
output_dtype: Optional[torch.dtype] = None,
) -> torch.Tensor:
if not (_is_cuda and is_sm100_supported()):
raise RuntimeError("MXFP8 dense linear requires Blackwell GPUs (SM100+).")
if not (_is_cuda and (is_sm100_supported() or is_sm120_supported())):
raise RuntimeError("MXFP8 dense linear requires Blackwell GPUs (SM100/SM120).")
input_2d = input.view(-1, input.shape[-1]).contiguous()
output_shape = [*input.shape[:-1], weight.shape[0]]
@@ -722,6 +723,7 @@ def triton_mxfp8_blockscaled_linear(
a_scale_packed = _pack_mxfp8_scales(x_scale_u8)
b_scale_packed = _pack_mxfp8_scales(weight_scale)
num_stages = 1 if is_sm120_supported() else (4 if is_sm100_supported() else 1)
output = mxfp8_block_scaled_matmul_triton(
q_input,
a_scale_packed,
@@ -731,6 +733,7 @@ def triton_mxfp8_blockscaled_linear(
block_m=block_m,
block_n=block_n,
block_k=block_k,
num_stages=num_stages,
)
output = output[:m, :]
if bias is not None:

View File

@@ -19,7 +19,7 @@ from sglang.srt.layers.quantization.fp8_utils import (
mxfp8_group_quantize,
triton_mxfp8_blockscaled_linear,
)
from sglang.srt.utils import is_sm100_supported
from sglang.srt.utils import is_sm100_supported, is_sm120_supported
from sglang.test.test_utils import CustomTestCase
_is_cuda = torch.cuda.is_available() and torch.version.cuda
@@ -452,8 +452,8 @@ class TestMXFP8DenseLinear(CustomTestCase):
def setUpClass(cls):
if not torch.cuda.is_available():
raise unittest.SkipTest("CUDA is not available")
if not is_sm100_supported():
raise unittest.SkipTest("MXFP8 requires Blackwell (SM100+)")
if not (is_sm100_supported() or is_sm120_supported()):
raise unittest.SkipTest("MXFP8 requires Blackwell (SM100/SM120)")
torch.set_default_device("cuda")
def _mxfp8_dense_linear(self, M, NK, dtype, seed):