Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/sglang/srt/layers/moe/fused_moe_triton/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def weight_loader(
# if expert_id is None, then
# all the experts are loaded at the same time
if (
not expert_id
expert_id is None
and self.quant_config is not None
and self.quant_config.get_name() == "mxfp4"
and self.quant_config.is_static_cfg()
Expand Down
52 changes: 52 additions & 0 deletions test/registered/unit/layers/moe/test_mxfp4_expert_weight_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from types import SimpleNamespace
from unittest.mock import Mock, patch

import torch

from sglang.srt.layers.moe.fused_moe_triton.layer import FusedMoE
from sglang.test.ci.ci_register import register_cpu_ci

register_cpu_ci(est_time=3, suite="base-a-test-cpu")


class _StaticMxfp4Config:
@staticmethod
def get_name():
return "mxfp4"

@staticmethod
def is_static_cfg():
return True


def test_static_mxfp4_expert_zero_uses_per_expert_loader():
load_impl = Mock()
layer = SimpleNamespace(
quant_config=_StaticMxfp4Config(),
_map_global_expert_id_to_local_expert_id=lambda expert_id: expert_id,
_weight_loader_impl=load_impl,
)
param = torch.nn.Parameter(torch.empty(1))
loaded_weight = torch.empty((4, 8))

with patch(
"sglang.srt.layers.moe.fused_moe_triton.layer."
"get_global_expert_location_metadata",
return_value=None,
):
FusedMoE.weight_loader(
layer,
param,
loaded_weight,
"experts.w1.weight",
"w1",
expert_id=0,
)

load_impl.assert_called_once_with(
param=param,
loaded_weight=loaded_weight,
weight_name="experts.w1.weight",
shard_id="w1",
expert_id=0,
)
Loading