flashinfer.comm.moe_a2a_dispatch¶
- flashinfer.comm.moe_a2a_dispatch(token_selected_experts: Tensor, input_payloads: list[Tensor], workspace: Tensor, metainfo: Tensor, runtime_max_tokens_per_rank: int, ep_rank: int, ep_size: int, top_k: int, num_experts: int, enable_pdl: bool | None = None, eplb_local_stats: Tensor | None = None, enable_rank_mask: bool = False, active_rank_mask: Tensor | None = None, recv_view_cache: dict | None = None)¶
Dispatch tokens and payloads to their target expert ranks.
- Parameters:
token_selected_experts (torch.Tensor) –
[local_num_tokens, top_k]int32tensor of expert assignments.input_payloads (list[torch.Tensor]) – Per-token payload tensors, each shaped
[local_num_tokens, *].workspace (torch.Tensor) –
[ep_size, size_per_rank]shared workspace.metainfo (torch.Tensor) – Metainfo tensor returned by
moe_a2a_initialize().runtime_max_tokens_per_rank (int) – Maximum tokens per rank for this batch (must be
<=themax_num_tokensused at initialize time).ep_rank (int) – Current expert-parallel rank.
ep_size (int) – Total expert-parallel world size.
top_k (int) – Number of experts assigned per token.
num_experts (int) – Total number of experts.
enable_pdl (Optional[bool]) – Whether to use programmatic dependent launch.
Noneauto-detects from the device.eplb_local_stats (Optional[torch.Tensor]) – Optional
[eplb_stats_num_experts]int32tensor of this rank’s local EPLB statistics. When provided, the dispatch all-gathers it across ranks and returns the result aseplb_gathered_stats. The length must match theeplb_stats_num_expertspassed tomoe_a2a_initialize().enable_rank_mask (bool) – Whether to instantiate the kernel variant that checks
active_rank_maskat all.False(default) compiles out every rank-mask check for the common no-fault-tolerance case and requiresactive_rank_maskto be omitted.active_rank_mask (Optional[torch.Tensor]) – Optional CPU
uint64tensor of shape[MOE_A2A_RANK_MASK_WORDS](seemoe_a2a_active_rank_mask()). Bitiset means rankiis alive and participates in this collective; tokens routed to a masked-off rank are dropped instead of hanging the collective. Requiresenable_rank_mask=True; the localep_rank’s own bit must always be set.recv_view_cache (dict, optional) – Opaque cache of receive views. Pass an empty dictionary to enable caching;
None(default) disables it and preserves the previous behaviour exactly. The cache retains a reference toworkspaceand is cleared when a different workspace tensor is passed. Keep the backing allocation alive and do not change the workspace or the cached views’ shape, strides, or storage in place. Clear the dictionary to release its references; otherwise leave its contents unchanged.
- Returns:
(output_payloads, combine_payload_offset, eplb_gathered_stats).output_payloadsis a list of workspace-backed views, one perinput_payloadsentry, that contains the data routed to this rank.combine_payload_offsetis the workspace offset reserved for the matchingmoe_a2a_combine()call.eplb_gathered_statsis a workspace-backed[ep_size, eplb_stats_num_experts]int32view (rowrholds rankr’seplb_local_stats) wheneplb_local_statswas provided, elseNone.- Return type:
Tuple[list[torch.Tensor], int, Optional[torch.Tensor]]