Skip to content
Merged
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
16 changes: 9 additions & 7 deletions python/sglang/srt/models/deepseek_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1936,11 +1936,9 @@ def post_load_weights(self, is_nextn=False, weight_names=None):
and hasattr(self.quant_config, "weight_block_size")
and self.quant_config.weight_block_size is not None
):
self._weight_requant_ue8m0()
self._weight_requant_ue8m0(is_nextn)

def _weight_requant_ue8m0(self):
if self.config.architectures[0] == "DeepseekV3ForCausalLMNextN":
return
def _weight_requant_ue8m0(self, is_nextn=False):
weight_block_size = self.quant_config.weight_block_size

moe_layers = list(
Expand All @@ -1951,8 +1949,12 @@ def _weight_requant_ue8m0(self):
)
)

for layer_id in range(self.config.num_hidden_layers):
layer = self.model.layers[layer_id]
num_hidden_layers = 1 if is_nextn else self.config.num_hidden_layers
for layer_id in range(num_hidden_layers):
if is_nextn:
layer = self.model.decoder
else:
layer = self.model.layers[layer_id]
Comment on lines +1953 to +1957
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding a comment to explain why the decoder is used when is_nextn is true, and layers otherwise.

            if is_nextn:
                layer = self.model.decoder  # Use decoder for NextN
            else:
                layer = self.model.layers[layer_id]  # Use layers for normal layers


for module in [
layer.self_attn.fused_qkv_a_proj_with_mqa,
Expand All @@ -1964,7 +1966,7 @@ def _weight_requant_ue8m0(self):
module.weight, module.weight_scale_inv, weight_block_size
)

if layer_id in moe_layers:
if layer_id in moe_layers or is_nextn:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding a comment to explain why is_nextn is included in this conditional.

            if layer_id in moe_layers or is_nextn:  # Also apply to NextN

shared_experts = getattr(layer.mlp, "shared_experts", None)
if shared_experts is not None:
for module in [
Expand Down
Loading