All-to-all communication is a collective network operation, critical to expert parallelism, where every device in a distributed system simultaneously sends distinct data to, and receives distinct data from, every other device. In Mixture of Experts (MoE) inference, this pattern is used twice: first to scatter tokens from all devices to the specific devices hosting their assigned experts after routing, and again to gather the processed expert outputs back to all devices for the next layer. This operation is the primary communication bottleneck for scaling sparse models.
Glossary
All-to-All Communication

What is All-to-All Communication?
A collective communication pattern fundamental to expert parallelism in Mixture of Experts models.
The efficiency of this collective communication is paramount for MoE performance, as it directly impacts inference latency. Unlike simpler patterns like all-reduce, all-to-all involves a complete exchange of unique data blocks. Its cost scales with the number of devices and the volume of routed tokens, making optimized implementations—often leveraging hardware-specific libraries like NCCL—essential for maintaining high GPU utilization and throughput in large-scale deployments.
Key Characteristics of All-to-All in MoE Systems
All-to-All communication is the collective operation that enables expert parallelism by redistributing tokens to the devices hosting their assigned experts after routing and gathering the results.
Core Communication Pattern
All-to-All is a collective communication primitive where every device (e.g., GPU) in a parallel group sends a distinct chunk of data to every other device and receives a chunk from all others. In Mixture of Experts (MoE), this pattern manifests in two critical phases:
- Scatter/All-to-All: After the gating network decides token-expert assignments, tokens are scattered from all devices to the specific devices hosting their assigned experts.
- Gather/All-to-All: After experts process their assigned tokens, the resulting outputs are gathered back from all expert devices to the original devices for the next layer. This pattern is fundamental to expert parallelism, where experts are sharded across devices.
Bandwidth-Bound Nature
The performance of All-to-All operations in MoE is typically bandwidth-bound, not compute-bound. The limiting factor is the speed at which data can be moved across the interconnect (e.g., NVLink, InfiniBand) between devices, not the speed of the expert computations themselves.
- Communication Volume: Scales with
batch_size * sequence_length * hidden_dim * k, wherekis the number of experts selected per token. - Critical Interconnect: High-bandwidth, low-latency networks like NVLink within a node or InfiniBand across nodes are essential to prevent this phase from becoming the dominant bottleneck in MoE inference and training throughput.
Token Permutation & Expert Capacity
The All-to-All operation is preceded by a local token permutation that groups tokens by their assigned expert ID. This creates the data chunks to be sent. A key related concept is expert capacity.
- Capacity Factor: A buffer multiplier (e.g., 1.25) applied to the theoretical minimum tokens per expert. It sets a soft limit to allow for imbalanced routing.
- Dropped Tokens: If an expert receives more tokens than its allocated capacity, the excess tokens are dropped (often passed through unchanged), degrading model quality. The All-to-All must handle this padded, potentially imbalanced data layout.
Integration with Model Parallelism
All-to-All for MoE often operates in conjunction with other model parallelism strategies, creating a 3D parallelism setup:
- Expert Parallelism (EP): Experts are sharded across devices. Enabled by All-to-All.
- Tensor Parallelism (TP): Individual experts or layers are split across devices.
- Pipeline Parallelism (PP): Different model layers are placed on different devices. The All-to-All communication group is typically confined to the expert parallelism dimension. Sophisticated frameworks like Megatron-DeepSpeed coordinate these parallel strategies, ensuring the All-to-All happens within the correct subgroup of devices.
Optimization via Fused MoE Kernels
To mitigate the latency of separate routing, permutation, communication, and computation steps, systems use fused MoE kernels.
- Kernel Fusion: Combines the token permutation, the All-to-All communication (or its on-device equivalent), and the batched sparse matrix multiplication across experts into a single, optimized GPU kernel.
- Reduced Overhead: Minimizes memory movement between GPU global memory and registers, and reduces the launch overhead of multiple small kernels. This is critical for maintaining high FLOPs utilization despite the conditional and communication-heavy nature of MoE.
Contrast with All-Reduce
All-to-All is distinct from the more common All-Reduce pattern used in data parallelism for gradient synchronization.
| All-Reduce | All-to-All |
|---|---|
| Goal: Reduce (sum/average) data across devices and broadcast result back to all. | Goal: Rearrange and exchange distinct data chunks between all devices. |
| Use Case: Synchronizing gradients in data-parallel training. | Use Case: Routing tokens to experts in expert-parallel MoE. |
| Output: All devices get the same aggregated result. | Output: All devices get different assembled chunks of data. |
| Understanding this distinction is key for systems architects designing high-performance MoE clusters. |
All-to-All vs. Other Collective Communication Patterns
A comparison of collective communication patterns used in distributed machine learning, focusing on their role in expert parallelism and other model parallelism strategies.
| Communication Pattern | All-to-All (AllGather + AlltoAll) | All-Reduce | Broadcast | Scatter / Gather |
|---|---|---|---|---|
Primary Function | Complete redistribution of data blocks among all participants. | Global aggregation (e.g., sum, mean) of tensors across devices. | One-to-many distribution of a tensor from a root device to all others. | One-to-many distribution of different tensor slices (Scatter) and many-to-one collection (Gather). |
Typical Use Case in ML | Token routing and result aggregation in Mixture of Experts (MoE) expert parallelism. | Synchronizing gradients during distributed data-parallel training. | Distributing model weights or input data from a central coordinator. | Distributing different shards of a dataset or gathering results to a root node. |
Data Movement Complexity | O(P²) where P is the number of devices; each device sends a unique block to every other device. | O(P) or O(P log P) depending on algorithm (e.g., ring, tree). | O(P); root sends data to all P-1 other devices. | O(P); root sends unique slices to each device (Scatter) or receives from all (Gather). |
Bandwidth Cost | High. Total data moved scales with P * (tensor size). | Moderate. Total data moved is proportional to the tensor size. | Low. Data is replicated, not permuted. | Moderate. Data is split or concatenated, not fully permuted. |
Latency Profile | High. Requires coordination of many pairwise exchanges; often the bottleneck in MoE inference. | Moderate. Can be optimized with pipelining and topology-aware algorithms. | Low. Simple one-way fan-out operation. | Moderate. Sequential or parallel distribution/collection. |
Critical for MoE Inference | ||||
Sparse Activation Compatibility | ||||
Example in MoE Pipeline | After routing: Scatter tokens to expert devices. After computation: Gather outputs back. | Used in the backward pass for gradient synchronization if experts are trained. | Initial distribution of the model's router parameters or shared embeddings. | Less common; could be used in simpler, static expert assignment schemes. |
Optimization Techniques for All-to-All in MoE
All-to-All (A2A) communication is the dominant performance bottleneck in expert-parallel Mixture of Experts (MoE) inference. These techniques aim to minimize its latency and bandwidth impact.
Overlapping Communication with Computation
A core optimization that hides network latency by performing useful computation while data is in transit. In MoE, this involves:
- Compute the Gating Decision First: Run the router locally to determine token-expert assignments.
- Initiate All-to-All Early: Start scattering the tokens to their target expert devices immediately after routing.
- Compute Non-MoE Layers Concurrently: While tokens are being communicated, the system can proceed with computing the next transformer layer's attention mechanism or other non-expert parallel operations on the already-gathered tokens from the previous layer. This technique transforms communication time from pure overhead into partially masked latency, significantly improving throughput.
Hierarchical All-to-All for Multi-Node Clusters
Optimizes A2A for large-scale deployments spanning multiple nodes (e.g., pods with NVLink within a node, Ethernet/InfiniBand between nodes). The strategy is:
- Intra-Node A2A First: Perform a fast, collective A2A within each node using high-bandwidth links (NVLink) to aggregate tokens destined for experts on other devices within the same node.
- Inter-Node A2A Second: Perform a slower, cross-node A2A where each node sends/receives only the consolidated batches for experts on remote nodes.
- Intra-Node Redistribution: Finally, redistribute the received tokens within each node to the correct local expert device. This reduces the volume and frequency of slower inter-node communication, cutting tail latency.
Expert Capacity Tuning & Token Dropping Policies
Directly controls the size and efficiency of the A2A payloads. Expert Capacity is a buffer limiting tokens per expert to enable batched computation.
- High Capacity: Minimizes dropped tokens but increases A2A payload size and memory usage, leading to higher communication latency.
- Low Capacity: Reduces communication volume but risks more dropped tokens, which are typically passed through the layer unprocessed, degrading model quality. Optimization involves:
- Dynamic Capacity: Adjusting capacity based on observed load per batch.
- Auxiliary Load Balancing Loss: Used during training to ensure uniform token distribution, making static capacity tuning more effective.
- Smart Fallbacks: Routing overflow tokens to a shared expert or the original token, rather than dropping them.
Fused MoE Kernels with Integrated Communication
Replaces a sequence of small, inefficient operations with a single, custom GPU kernel. A naive implementation involves separate steps for: routing, permuting tokens for A2A, launching communication, receiving data, and finally computing expert FFNs. A fused MoE kernel combines these steps:
- Kernel-Level Permutation: Token sorting/gathering happens on-GPU before communication prep.
- Direct Memory Access (DMA) Integration: The kernel can prepare buffers in a format optimal for the network card (GPUDirect RDMA).
- Overlap Management: The kernel manages the handoff to communication libraries (e.g., NCCL) and the subsequent computation on received data. This reduces kernel launch overhead and CPU-GPU synchronization, shaving microseconds off critical paths.
Topology-Aware Expert Placement
Strategically maps experts to physical devices to minimize network hop distance for the most frequent token routes. This requires analyzing or predicting token-expert affinity (the learned tendency for certain tokens to route to specific experts).
- Affinity Clustering: Place experts that are frequently activated together (e.g., for similar linguistic features) on the same node or NVLink-connected GPU group.
- Communication Cost Matrix: Model the latency/bandwidth between all device pairs and use it as a cost function for placement algorithms.
- Joint Optimization with Routing: In some dynamic MoE systems, the router can be made aware of placement costs, slightly adjusting expert selection to favor locally available experts when scores are similar. The goal is to make the majority of A2A traffic flow over the fastest physical links.
Quantization for Communication Volume Reduction
Reduces the precision of data sent over the network during A2A. While experts compute internally in BF16 or FP16, the tokens sent between devices can use lower precision.
- INT8 A2A: Converting token hidden states (activations) to 8-bit integers before scattering and converting back after gathering. This halves the communication volume compared to FP16/BF16.
- Sparse Communication Encoding: Leveraging the fact that activation tensors often have a non-uniform value distribution. Techniques like Float16 compression can pack values, reducing payload size.
- Asymmetric Quantization: Using different quantization parameters for pre- and post-expert activation tensors to minimize the impact on final model accuracy. This is a direct bandwidth saver, most effective in bandwidth-bound scenarios.
Frequently Asked Questions
All-to-All (A2A) is a critical collective communication pattern in distributed systems, particularly for Mixture of Experts (MoE) models. This FAQ addresses its role, mechanics, and optimization within expert parallelism.
All-to-All Communication is a collective communication pattern where every process (e.g., a GPU) in a distributed system sends a distinct piece of data to every other process and receives a distinct piece from every other process. In the context of Mixture of Experts (MoE) inference, it is the fundamental operation that enables expert parallelism. After a routing decision assigns tokens to experts residing on different devices, an All-to-All operation scatters the tokens from all source devices to their specific target devices hosting the assigned experts. Once the experts process their received tokens, a second All-to-All gathers the outputs back to the original devices for the next layer.
This pattern is distinct from point-to-point or broadcast communication and is essential for the sparse activation characteristic of MoE models, where computational load is conditionally distributed across a large, sharded parameter set.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
All-to-All communication is a fundamental collective operation in distributed computing. Understanding its related patterns and the parallelism strategies it enables is crucial for designing efficient large-scale systems, especially for sparse models like Mixture of Experts.
Collective Communication
A class of communication operations in parallel computing where all processes in a defined group participate in a coordinated data exchange. All-to-All is one specific pattern within this class. Other key patterns include:
- Broadcast: One process sends identical data to all others.
- Scatter: One process sends distinct chunks of data to all others.
- Gather: One process collects distinct chunks from all others.
- Reduce: Data from all processes is combined (e.g., summed, maxed) and the result is sent to a root process. These primitives are the building blocks for frameworks like NVIDIA's NCCL and MPI, which optimize them for high-performance clusters.
Expert Parallelism
A model parallelism strategy designed explicitly for Mixture of Experts (MoE) architectures. In this scheme, different expert networks are placed on different physical devices (e.g., GPUs). The All-to-All communication pattern is the critical enabler:
- After the routing decision, an All-to-All Scatter sends each token from its source device to the specific device hosting its assigned expert.
- Experts process their assigned tokens in parallel.
- An All-to-All Gather collects the processed outputs from all devices and returns them to the original token positions. This strategy allows the massive parameter count of an MoE model to be distributed across a device cluster, with computation activated sparsely and conditionally per token.
Sparse Activation
The defining computational characteristic of conditional computation models like Mixture of Experts. For a given input, only a small, dynamically selected subset of the model's total parameters is activated and computed. This contrasts with dense models, where all parameters are used for every input. All-to-All communication is the mechanism that makes sparse activation feasible across multiple devices. Instead of every device computing the full dense model, tokens are routed only to the devices containing their necessary experts. This creates a sparse computational graph where communication (the All-to-All) is traded for a massive reduction in FLOPs per device, enabling models with trillions of parameters to run efficiently.
Model Parallelism
A family of techniques for distributing a single neural network model across multiple accelerators. Expert Parallelism is a specialized form of model parallelism for MoE. Other primary strategies include:
- Tensor Parallelism: Splits individual weight matrices and the associated computation (e.g., a matrix multiplication) across devices, requiring All-Reduce communication after each parallelized operation.
- Pipeline Parallelism: Splits the model's layers (stages) across devices, with micro-batches flowing through the pipeline; requires point-to-point communication between adjacent stages.
- Sequence Parallelism: Splits the sequence dimension (e.g., tokens) across devices for certain operations to reduce activation memory. The choice of parallelism strategy dictates the required communication pattern, with All-to-All being paramount for expert-parallel MoE.
Communication Overhead
The latency and bandwidth cost incurred by transferring data between devices in a distributed system. For All-to-All operations in MoE inference, this overhead is a primary bottleneck and must be meticulously optimized. Key factors include:
- Network Topology: The physical interconnect (e.g., NVLink, InfiniBand) drastically impacts bandwidth and latency.
- Message Size: Determined by the token batch size, embedding dimension, and the value of k (experts per token).
- Kernel Efficiency: Using optimized collective communication libraries (e.g., NCCL) and fused MoE kernels that combine routing and computation. The goal is to overlap this communication with computation as much as possible to hide its latency, making the efficiency of the All-to-All operation critical for overall throughput.
Fused MoE Kernels
Highly optimized, low-level GPU kernels that combine multiple steps of the Mixture of Experts forward pass into a single operation. A key optimization they provide is reducing the overhead of All-to-All communication. A naive implementation might:
- Compute router scores.
- Perform an explicit All-to-All Scatter via NCCL.
- Launch separate matrix multiplications for each expert.
- Perform an explicit All-to-All Gather via NCCL. A fused kernel can combine steps 1-3 into one kernel, using shared memory and thread blocks to internally permute and route tokens to expert weight matrices without launching separate, costly collective operations. This minimizes memory movement and kernel launch overhead, making the implied All-to-All pattern much more efficient.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us