[dsv4] support eplb (#25948)

Co-authored-by: xutizhou <xutingz@nvidia.com>
This commit is contained in:
Siyuan Chen
2026-05-24 10:09:41 -07:00
committed by GitHub
co-authored by xutizhou
parent 5c3775823e
commit 7f45bcdd2a
2 changed files with 18 additions and 6 deletions
@@ -7,6 +7,9 @@ import torch
from torch import nn
from sglang.srt.environ import envs
from sglang.srt.eplb.expert_distribution import (
get_global_expert_distribution_recorder,
)
from sglang.srt.eplb.expert_location_dispatch import (
ExpertLocationDispatchInfo,
topk_ids_logical_to_physical,
@@ -145,6 +148,7 @@ class HashTopK(nn.Module):
topk_ids = topk_ids_logical_to_physical(topk_ids, expert_location_dispatch_info)
_mask_topk_ids_padded_region(topk_ids, num_token_non_padded)
get_global_expert_distribution_recorder().on_select_experts(topk_ids=topk_ids)
topk_output = StandardTopKOutput(
topk_weights=topk_weights, topk_ids=topk_ids, router_logits=router_logits
)
+14 -6
View File
@@ -3,6 +3,7 @@ from __future__ import annotations
import concurrent.futures
import logging
import time
from contextlib import nullcontext
from typing import (
TYPE_CHECKING,
Iterable,
@@ -33,6 +34,7 @@ from sglang.srt.distributed import (
get_tp_group,
)
from sglang.srt.environ import envs
from sglang.srt.eplb.expert_distribution import get_global_expert_distribution_recorder
from sglang.srt.eplb.expert_location import ModelConfigForExpertLocation
from sglang.srt.layers.attention.dsa.utils import (
can_dsa_cp_split,
@@ -1269,13 +1271,19 @@ class DeepseekV4Model(nn.Module):
for i in range(self.start_layer, self.end_layer):
layer = self.layers[i]
hidden_states = layer(
positions=positions,
hidden_states=hidden_states,
forward_batch=forward_batch,
input_ids=input_ids,
input_ids_global=input_ids_global,
ctx = (
nullcontext()
if not get_global_server_args().disable_piecewise_cuda_graph
else get_global_expert_distribution_recorder().with_current_layer(i)
)
with ctx:
hidden_states = layer(
positions=positions,
hidden_states=hidden_states,
forward_batch=forward_batch,
input_ids=input_ids,
input_ids_global=input_ids_global,
)
# CP all-gather only on the last PP rank; PP IPC carries CP-split tensors.
if self.pp_group.is_last_rank and dsa_use_prefill_cp(forward_batch):