IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Mojo struct

DistributedEPDispatch

struct DistributedEPDispatch

Registers the mo.distributed.ep.dispatch graph op with the graph compiler.

Implemented traits​

AnyType, ImplicitlyDeletable

Methods​

execute​

static def execute[dispatch_dtype: DType, hidden_size: Int, top_k: Int, n_experts: Int, max_token_per_rank: Int, n_gpus_per_node: Int, n_nodes: Int, fused_shared_expert: Bool, //, target: StringSlice[ImmStaticOrigin], _trace_name: StringSlice[ImmStaticOrigin]](output_tokens: VariadicTensors[IOSpec[_, _].Output, static_specs=output_tokens.static_specs], row_offsets: VariadicTensors[IOSpec[_, _].Output, static_specs=row_offsets.static_specs], expert_ids: VariadicTensors[IOSpec[_, _].Output, static_specs=expert_ids.static_specs], src_info: VariadicTensors[IOSpec[_, _].Output, static_specs=src_info.static_specs], input_tokens: VariadicTensors[IOSpec[_, _].Input, static_specs=input_tokens.static_specs], topk_ids: VariadicTensors[IOSpec[_, _].Input, static_specs=topk_ids.static_specs], send_ptrs: VariadicTensors[IOSpec[_, _].Input, static_specs=send_ptrs.static_specs], recv_ptrs: VariadicTensors[IOSpec[_, _].Input, static_specs=recv_ptrs.static_specs], recv_count_ptrs: VariadicTensors[IOSpec[_, _].Input, static_specs=recv_count_ptrs.static_specs], atomic_counters: VariadicTensors[IOSpec[_, _].MutableInput, static_specs=atomic_counters.static_specs], dev_ctxs: DeviceContextArray)

Multi-device fused Expert Parallelism BF16 dispatch.

Parameters:

  • ​dispatch_dtype (DType): DType used for token dispatch to experts (inferred).
  • ​hidden_size (Int): Size of the model's hidden dimension (inferred).
  • ​top_k (Int): Number of experts each token is routed to (inferred).
  • ​n_experts (Int): Total number of experts across all GPUs (inferred).
  • ​max_token_per_rank (Int): Maximum number of tokens per GPU (inferred).
  • ​n_gpus_per_node (Int): Number of GPUs per node (inferred).
  • ​n_nodes (Int): Number of physical nodes (inferred).
  • ​fused_shared_expert (Bool): Whether a shared expert is fused into the dispatch kernel (inferred).
  • ​target (StringSlice[ImmStaticOrigin]): Compile-time device target.
  • ​_trace_name (StringSlice[ImmStaticOrigin]): Trace label for this op.

Args:

  • ​output_tokens (VariadicTensors[IOSpec[_, _].Output, static_specs=output_tokens.static_specs]): Output variadic tensors storing the dispatched tokens, one per device.
  • ​row_offsets (VariadicTensors[IOSpec[_, _].Output, static_specs=row_offsets.static_specs]): Output variadic tensors storing the row offsets for the received tokens, one per device.
  • ​expert_ids (VariadicTensors[IOSpec[_, _].Output, static_specs=expert_ids.static_specs]): Output variadic tensors storing the expert ID for each received token, one per device.
  • ​src_info (VariadicTensors[IOSpec[_, _].Output, static_specs=src_info.static_specs]): Output variadic tensors recording the originating rank and token index for each received token, one per device.
  • ​input_tokens (VariadicTensors[IOSpec[_, _].Input, static_specs=input_tokens.static_specs]): Input variadic tensors of tokens to dispatch, one per device.
  • ​topk_ids (VariadicTensors[IOSpec[_, _].Input, static_specs=topk_ids.static_specs]): Input variadic tensors of top-k expert IDs per token, one per device.
  • ​send_ptrs (VariadicTensors[IOSpec[_, _].Input, static_specs=send_ptrs.static_specs]): Send buffer pointers for the dispatch phase, one per device.
  • ​recv_ptrs (VariadicTensors[IOSpec[_, _].Input, static_specs=recv_ptrs.static_specs]): Receive buffer pointers for the dispatch phase, one per device.
  • ​recv_count_ptrs (VariadicTensors[IOSpec[_, _].Input, static_specs=recv_count_ptrs.static_specs]): Receive count buffer pointers tracking tokens received per expert, one per device.
  • ​atomic_counters (VariadicTensors[IOSpec[_, _].MutableInput, static_specs=atomic_counters.static_specs]): Atomic counters coordinating work across thread blocks, one per device.
  • ​dev_ctxs (DeviceContextArray): List of GPU device contexts, one per device.