CPU, GPU AND RAM

Expert all-to-all: pack tokens before moving them between GPUs

In this article
THE QUICK TAKE

Expert all-to-all performance includes counting, packing, exchange, and inverse permutation; network bandwidth alone cannot explain a ragged routing phase.

Mixture-of-experts execution often needs to move token representations to the devices hosting selected experts. The mathematical routing decision is only the beginning. A practical all-to-all path must count destinations, pack records into contiguous ranges, exchange them, run expert work, and restore the original token order. Metadata and layout can dominate when useful expert computation is small or uneven.

Routing produces a ragged destination layout

Different destinations can receive different numbers of token records. The sender needs a representation of these counts and offsets so records for each destination can be found reliably. A prefix-based layout can assign contiguous ranges after counting. Check that the count describes the transmitted records rather than only unique source tokens, because one token may contribute to several selected experts. This distinction affects buffer sizes and inverse mapping.

Primary reference: NCCL User Guide: Point-to-point Communication.

Packing trades scattered reads for useful transport

Token records may begin scattered in the source tensor. Packing groups them by destination so the transport handles larger contiguous ranges. This preprocessing reads and writes device memory and needs its own synchronization before communication. It can be worthwhile, but its cost belongs in the layer budget. A benchmark that starts after packing can substantially overstate the performance improvement available to the complete expert-routing pipeline.

Primary reference: CUDA Programming Guide: Asynchronous Execution.

Counts and matching calls must agree

A receiving participant must know the expected layout and compatible data types for each peer. Point-to-point exchanges used to construct an all-to-all need matching sends and receives, with appropriate grouping for concurrent progress. A count mismatch is a correctness problem, not merely inefficient balance. Validate metadata using a deterministic toy routing map before using random model outputs. Include destinations that receive no records and destinations that receive nearly all records.

Primary reference: CUDA C++ Best Practices Guide.

The return path needs an inverse permutation

Expert outputs arrive grouped by the processing layout, not necessarily by original sequence order. The system must retain enough information to restore each contribution to the correct token and combine multiple expert contributions as required. Reusing a packing buffer without preserving the inverse mapping can produce numerically plausible but semantically misplaced output. Test with distinguishable synthetic records so swapped destinations or duplicated contributions are easy to identify.

Measure imbalance as well as bytes

A heavily selected expert can determine completion time even when average network utilization looks low. Record destination counts, packing duration, transport duration, expert execution, and return reordering separately. Compare the full critical path across representative routing distributions. More link bandwidth cannot eliminate an overloaded expert or an expensive inverse permutation. The useful optimization targets the phase that actually determines when the complete batch can leave the layer.

Related reading: A GPU inference benchmark you can trust; Reproducible inference stacks: preserving a GPU pilot’s result.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles