Support DeepGEMM for standard MoE dispatch (#33128)
Co-authored-by: Sam Li <lsam@nvidia.com>
This commit is contained in:
@@ -5,13 +5,14 @@ from sglang.test.ci.ci_register import register_cpu_ci
|
||||
register_cpu_ci(est_time=5, suite="base-a-test-cpu")
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import call, patch
|
||||
|
||||
import torch
|
||||
from compressed_tensors.quantization import QuantizationStrategy
|
||||
|
||||
import sglang.srt.layers.quantization.fp8_utils as fp8_utils
|
||||
from sglang.srt.layers import deep_gemm_wrapper
|
||||
from sglang.srt.layers.quantization import fp8 as fp8_quant
|
||||
from sglang.srt.layers.quantization.compressed_tensors.schemes.compressed_tensors_w8a8_fp8 import (
|
||||
CompressedTensorsW8A8Fp8,
|
||||
)
|
||||
@@ -162,6 +163,60 @@ class TestDeepGemmUE8M0Requant(CustomTestCase):
|
||||
self.assertTrue(layer.weight_scale.format_ue8m0)
|
||||
requant.assert_called_once()
|
||||
|
||||
def test_fp8_moe_requants_standard_layer_for_deepgemm(self):
|
||||
method = fp8_quant.Fp8MoEMethod.__new__(fp8_quant.Fp8MoEMethod)
|
||||
method.convert_mxfp8_to_block = False
|
||||
method.use_mxfp8 = False
|
||||
method.is_fp4_expert = False
|
||||
method.dequant_fp4_to_fp8 = False
|
||||
method.quant_config = unittest.mock.Mock(weight_block_size=BLOCK_SIZE)
|
||||
|
||||
layer = torch.nn.Module()
|
||||
layer.w13_weight, layer.w13_weight_scale_inv = _make_params()
|
||||
layer.w2_weight, layer.w2_weight_scale_inv = _make_params()
|
||||
|
||||
def _mark_ue8m0(weight, weight_scale, *args, **kwargs):
|
||||
weight_scale.format_ue8m0 = True
|
||||
return True
|
||||
|
||||
with patch.multiple(
|
||||
fp8_quant,
|
||||
_is_cpu=False,
|
||||
_is_fp8_fnuz=False,
|
||||
_use_aiter=False,
|
||||
), patch.object(
|
||||
method, "is_deepgemm_moe_runner_backend_enabled", return_value=True
|
||||
), patch.object(
|
||||
fp8_quant,
|
||||
"requant_block_scale_ue8m0_for_deepgemm",
|
||||
side_effect=_mark_ue8m0,
|
||||
) as requant:
|
||||
method.process_weights_after_loading_block_quant(layer)
|
||||
|
||||
self.assertEqual(
|
||||
requant.call_args_list,
|
||||
[
|
||||
call(
|
||||
layer.w13_weight,
|
||||
layer.w13_weight_scale_inv,
|
||||
BLOCK_SIZE,
|
||||
use_deepgemm_runner=True,
|
||||
output_dtype=torch.bfloat16,
|
||||
weight_shape=layer.w13_weight.shape[-2:],
|
||||
),
|
||||
call(
|
||||
layer.w2_weight,
|
||||
layer.w2_weight_scale_inv,
|
||||
BLOCK_SIZE,
|
||||
use_deepgemm_runner=True,
|
||||
output_dtype=torch.bfloat16,
|
||||
weight_shape=layer.w2_weight.shape[-2:],
|
||||
),
|
||||
],
|
||||
)
|
||||
self.assertTrue(layer.w13_weight_scale_inv.format_ue8m0)
|
||||
self.assertTrue(layer.w2_weight_scale_inv.format_ue8m0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=3)
|
||||
|
||||
Reference in New Issue
Block a user