Skip to content
Merged
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
5 changes: 5 additions & 0 deletions python/sglang/srt/model_loader/weight_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1756,6 +1756,11 @@ def initialize_dummy_weights(
the parameter's number of elements and its data type.
"""
for name, param in model.state_dict().items():
# UE8M0 MXFP8 block scales (uint8): 127 is 2**0. Left at zero, every
# MXFP8 weight scales to 2**-127.
if name.endswith("weight_scale_inv") and param.dtype == torch.uint8:
param.fill_(127)
continue
if torch.is_floating_point(param):
# Neutral FP4 global scales keep fused gate/up projections compatible.
if name.endswith(("weight_scale_inv", "weight_scale_2")):
Expand Down
14 changes: 14 additions & 0 deletions test/registered/unit/model_loader/test_weight_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,20 @@ def test_nvfp4_dummy_scales_are_neutral(self):
self.assertTrue(torch.equal(model.w2_weight_scale_2, torch.ones(4)))
self.assertTrue(torch.all((model.weight >= 0.25) & (model.weight <= 0.75)))

def test_ue8m0_dummy_block_scales_are_neutral(self):
model = torch.nn.Linear(8, 4, bias=False)
model.register_buffer(
"w13_weight_scale_inv", torch.zeros(4, 2, dtype=torch.uint8)
)

initialize_dummy_weights(model, low=0.25, high=0.75)

self.assertTrue(
torch.equal(
model.w13_weight_scale_inv, torch.full((4, 2), 127, dtype=torch.uint8)
)
)


if __name__ == "__main__":
unittest.main()
Loading