[7/N] MoE Refactor: the implementation of new framework (#9269)
This commit is contained in:
@@ -9,6 +9,7 @@ from transformers import AutoConfig
|
||||
from sglang.srt.layers.moe.cutlass_moe import cutlass_fused_experts_fp8
|
||||
from sglang.srt.layers.moe.fused_moe_triton.fused_moe import fused_experts
|
||||
from sglang.srt.layers.moe.moe_runner.base import MoeRunnerConfig
|
||||
from sglang.srt.layers.moe.topk import StandardTopKOutput
|
||||
|
||||
|
||||
# Copy from: https://github.com/deepseek-ai/DeepGEMM/blob/main/deep_gemm/utils.py
|
||||
@@ -152,14 +153,32 @@ def run_test(tp_size, batch_size, model_config, check=False):
|
||||
problem_sizes2,
|
||||
)
|
||||
|
||||
topk_output = StandardTopKOutput(
|
||||
topk_weights=topk_weights,
|
||||
topk_ids=topk_ids,
|
||||
router_logits=torch.randn(
|
||||
(batch_size, topk), device=topk_weights.device, dtype=dtype
|
||||
),
|
||||
)
|
||||
|
||||
moe_runner_config = MoeRunnerConfig(
|
||||
num_experts=E,
|
||||
topk=topk,
|
||||
hidden_size=H,
|
||||
shard_intermediate_size=I,
|
||||
dtype=dtype,
|
||||
block_shape=block_shape,
|
||||
activation="silu",
|
||||
inplace=False,
|
||||
)
|
||||
|
||||
# Note: Triton expects non-transposed weights
|
||||
moe_config = MoeRunnerConfig(inplace=False)
|
||||
triton_lambda = lambda: fused_experts(
|
||||
x,
|
||||
w1,
|
||||
w2,
|
||||
(topk_weights, topk_ids, "dummy"),
|
||||
moe_config,
|
||||
topk_output,
|
||||
moe_runner_config,
|
||||
use_fp8_w8a8=True,
|
||||
w1_scale=w1_scale,
|
||||
w2_scale=w2_scale,
|
||||
@@ -224,8 +243,8 @@ def run_test(tp_size, batch_size, model_config, check=False):
|
||||
x,
|
||||
w1, # Original shape
|
||||
w2, # Original shape
|
||||
(topk_weights, topk_ids, "dummy"),
|
||||
moe_config,
|
||||
topk_output,
|
||||
moe_runner_config,
|
||||
use_fp8_w8a8=True,
|
||||
w1_scale=w1_scale,
|
||||
w2_scale=w2_scale,
|
||||
|
||||
Reference in New Issue
Block a user