Support Hy4-preview (#36805)

Co-authored-by: BBuf <1182563586@qq.com>
Co-authored-by: alphabetc1 <2508695655@qq.com>
This commit is contained in:
Xinyuan Tong
2026-09-04 18:03:49 -07:00
committed by GitHub
co-authored by BBuf alphabetc1
parent 85da5457de
commit 55bf3380e0
47 changed files with 3387 additions and 103 deletions
+59
View File
@@ -4,17 +4,76 @@ from unittest.mock import patch
import torch
from sglang.srt.layers.quantization.fp8 import (
Fp8MoEMethod,
_is_cuda,
_is_gfx95_supported,
_is_hip,
)
from sglang.srt.layers.quantization.fp8_utils import (
inverse_transform_scale_ue8m0,
quant_weight_ue8m0,
transform_scale_ue8m0,
)
from sglang.srt.runtime_context import get_platform
from sglang.test.ci.ci_register import register_cuda_ci
from sglang.test.test_utils import CustomTestCase
register_cuda_ci(est_time=12, stage="base-b", runner_config="1-gpu-large")
class TestMxfp8MoeScaleLayout(CustomTestCase):
@classmethod
def setUpClass(cls):
if not (
(_is_cuda and get_platform().is_sm100) or (_is_hip and _is_gfx95_supported)
):
raise unittest.SkipTest(
"MXFP8 MoE quantization requires SM100 or ROCm gfx95"
)
def test_cutlass_serialized_scales_remain_expert_first(self):
class CutlassBackend:
def is_cutlass(self):
return True
def is_flashinfer_trtllm(self):
return False
def is_flashinfer_trtllm_routed(self):
return False
def is_deep_gemm(self):
return False
layer = SimpleNamespace(
w13_weight=torch.nn.Parameter(
torch.zeros((2, 64, 32), dtype=torch.float8_e4m3fn, device="cuda")
),
w2_weight=torch.nn.Parameter(
torch.zeros((2, 32, 32), dtype=torch.float8_e4m3fn, device="cuda")
),
w13_weight_scale_inv=torch.nn.Parameter(
torch.zeros((2, 64, 1), dtype=torch.uint8, device="cuda"),
requires_grad=False,
),
w2_weight_scale_inv=torch.nn.Parameter(
torch.zeros((2, 32, 1), dtype=torch.uint8, device="cuda"),
requires_grad=False,
),
)
method = object.__new__(Fp8MoEMethod)
with patch(
"sglang.srt.layers.quantization.fp8.get_moe_runner_backend",
return_value=CutlassBackend(),
):
method._process_mxfp8_moe_weights(layer, quantize=False)
self.assertEqual(tuple(layer.w13_weight_scale_inv.shape), (2, 64, 1))
self.assertEqual(tuple(layer.w2_weight_scale_inv.shape), (2, 32, 1))
class TestInverseTransformScaleUe8m0(CustomTestCase):
def test_round_trip(self):
for _ in range(100):