Inferensys

Glossary

All-to-All Communication

All-to-All Communication is a collective network operation where every device in a distributed system sends a distinct piece of data to every other device, and vice versa.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
INFERENCE OPTIMIZATION AND LATENCY REDUCTION

What is All-to-All Communication?

A collective communication pattern fundamental to expert parallelism in Mixture of Experts models.

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.

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.

COMMUNICATION PATTERN

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.

01

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.
02

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, where k is 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.
03

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.
04

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.
05

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.
06

Contrast with All-Reduce

All-to-All is distinct from the more common All-Reduce pattern used in data parallelism for gradient synchronization.

All-ReduceAll-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.
COMPARISON

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 PatternAll-to-All (AllGather + AlltoAll)All-ReduceBroadcastScatter / 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.

SYSTEMS OPTIMIZATION

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.

01

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.
02

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.
03

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.
04

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.
05

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.
06

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.
ALL-TO-ALL COMMUNICATION

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.

Prasad Kumkar

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.