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

DistributedEPDispatchBlockScaledNV

struct DistributedEPDispatchBlockScaledNV

Registers the mo.distributed.ep.dispatch.block.scaled.nv graph op with the graph compiler.

Implemented traits​

AnyType, ImplicitlyDeletable

Methods​

execute​

static def execute[input_dtype: DType, dispatch_dtype: DType, dispatch_scale_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], output_scales: VariadicTensors[IOSpec[_, _].Output, static_specs=output_scales.static_specs], row_offsets: VariadicTensors[IOSpec[_, _].Output, static_specs=row_offsets.static_specs], scales_offsets: VariadicTensors[IOSpec[_, _].Output, static_specs=scales_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], input_scales: VariadicTensors[IOSpec[_, _].Input, static_specs=input_scales.static_specs], atomic_counters: VariadicTensors[IOSpec[_, _].MutableInput, static_specs=atomic_counters.static_specs], dev_ctxs: DeviceContextArray)

Multi-device fused Expert Parallelism NVFP4 dispatch.

Launches the EP dispatch kernel on all devices simultaneously via _ep_launch_device_collective. Each device routes its tokens to experts based on top-k IDs, quantizes them to NVFP4 format, and sends them to the appropriate peer devices.

Parameters:

  • ​input_dtype (DType): DType of the input tokens before quantization (inferred).
  • ​dispatch_dtype (DType): DType used for the quantized token payload during dispatch (inferred).
  • ​dispatch_scale_dtype (DType): DType of the block scales accompanying the dispatched tokens (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 NVFP4-quantized tokens, one per device.
  • ​output_scales (VariadicTensors[IOSpec[_, _].Output, static_specs=output_scales.static_specs]): Output variadic tensors storing the NVFP4 block scales, 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.
  • ​scales_offsets (VariadicTensors[IOSpec[_, _].Output, static_specs=scales_offsets.static_specs]): Output variadic tensors storing the offsets into the scales buffer, 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.
  • ​input_scales (VariadicTensors[IOSpec[_, _].Input, static_specs=input_scales.static_specs]): Input variadic tensors of global input scales for NVFP4 quantization, 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.