Skip to content
Closed
22 changes: 20 additions & 2 deletions ep/bench/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ def get_dispatch_config(num_ranks: int) -> Config:
2: Config(Buffer.num_sms, 24, 256, 6, 128),
4: Config(Buffer.num_sms, 6, 256, 6, 128),
8: Config(Buffer.num_sms, 6, 256, 6, 128),
12: Config(Buffer.num_sms, 6, 288, 6, 256),
16: Config(Buffer.num_sms, 36, 288, 20, 512 if Buffer._is_efa() else 128),
24: Config(Buffer.num_sms, 8, 288, 32, 128),
32: Config(Buffer.num_sms, 32, 288, 32, 512 if Buffer._is_efa() else 128),
Expand Down Expand Up @@ -781,7 +782,8 @@ def get_combine_config(num_ranks: int) -> Config:
config_map = {
2: Config(Buffer.num_sms, 10, 256, 6, 128),
4: Config(Buffer.num_sms, 9, 256, 6, 128),
8: Config(Buffer.num_sms, 4, 256, 6, 128),
8: Config(Buffer.num_sms, 4, 256, 8, 128),
12: Config(Buffer.num_sms, 4, 288, 12, 128),
16: Config(Buffer.num_sms, 4, 288, 12, 512 if Buffer._is_efa() else 128),
24: Config(Buffer.num_sms, 1, 288, 8, 128),
32: Config(Buffer.num_sms, 1, 288, 8, 512 if Buffer._is_efa() else 128),
Expand Down Expand Up @@ -1577,6 +1579,18 @@ def internode_dispatch(
dtype=torch.int32,
device=x.device,
)
# Device-visible per-expert counts for CUDA-graph mode: the
# host list is unavailable without a sync when num_worst_tokens
# is set, so the notify kernel also writes a device tensor.
recv_expert_counts = (
torch.zeros(
(int(num_tokens_per_expert.size(0)) // self.group_size,),
dtype=torch.int32,
device=x.device,
)
if num_worst_tokens > 0
else None
)
(
num_recv_tokens,
num_rdma_recv_tokens,
Expand All @@ -1595,6 +1609,7 @@ def internode_dispatch(
int(num_tokens_per_expert.size(0)),
int(expert_alignment),
int(num_worst_tokens),
0 if recv_expert_counts is None else recv_expert_counts.data_ptr(),
config,
rdma_channel_prefix_matrix.data_ptr(),
recv_rdma_rank_prefix_sum.data_ptr(),
Expand Down Expand Up @@ -1759,7 +1774,9 @@ def internode_dispatch(
(recv_x, recv_x_scales) if x_scales is not None else recv_x,
recv_topk_idx,
recv_topk_weights,
num_recv_tokens_per_expert_list,
recv_expert_counts
if recv_expert_counts is not None
else num_recv_tokens_per_expert_list,
handle,
EventOverlap(
event,
Expand Down Expand Up @@ -1848,6 +1865,7 @@ def internode_combine(
rdma_channel_prefix_matrix.data_ptr(),
rdma_rank_prefix_sum.data_ptr(),
gbl_channel_prefix_matrix.data_ptr(),
gbl_rank_prefix_sum.data_ptr(),
send_rdma_head.data_ptr(),
send_nvl_head.data_ptr(),
config,
Expand Down
Loading