research27 min studyLesson 574 in Engineering

Dispatch and combine: preserve token identity across expert ranks

Follow routing metadata, packing, variable peer splits, expert execution, and inverse weighted combination through a defined expert-parallel communication path.

On this page

What you’ll understand

  • Map token-expert assignments into and out of destination buffers.
  • Calculate a clearly bounded dispatch-plus-return payload count.
  • Identify collective participation and backward-routing correctness requirements.

Expert parallelism places different expert parameters on different ranks, so a token's selected computation may be remote. Dispatch is more than calling all-to-all: it packs assignments, agrees on peer sizes, preserves identities, and reconstructs each token's weighted result. An arithmetic saving is useful only if the communication and permutation path remains correct and affordable in both the forward and backward passes.

Pack assignments while retaining their inverse map

Start with the accepted token-expert assignment list after the chosen capacity policy. Each entry needs enough information to associate a token representation with a destination expert and later restore its contribution to the original token. Top-k can create several entries from one token. A local permutation groups entries by destination rank, and another arrangement may group arrivals by local expert. Keep the inverse mapping or equivalent indices; expert output order is not automatically the original sequence order.

A variable-split all-to-all exchanges the packed representations according to an agreed peer layout. Send and receive counts, dtypes, ordering, communicator membership, and matching collective sequence must be compatible. A rank with zero useful assignments still participates according to the communication protocol. PyTorch 2.14 documents split-size forms for all_to_all_single, but the exact runtime and backend support must be checked. Megatron-Core 0.15.0 also offers dispatcher variants, so all-to-all is a selected implementation path rather than the definition of every sparse layer.

yt=∑e: (t,e)∈Aacceptedgt,e Fe(xt)y_t=\sum_{e:\,(t,e)\in A_{\rm accepted}}g_{t,e}\,F_e(x_t)
A_accepted is the explicitly admitted assignment set, and g are the implemented combine weights after any stated normalization policy. Expert outputs must have compatible token dimensions. The equation defines restoration and combination; it does not prescribe a particular collective or require every requested branch to survive.↔ Scroll wide equations horizontally.

Count payload at one named communication boundary

Under a simple path that sends one representation per remote accepted assignment and returns one same-width expert output, count each payload once in each direction. Local expert work contributes no network payload at this boundary. A remote fraction can convert assignment count into remote count only when its denominator is explicit. Padding, routing metadata, collective protocol overhead, repeated link traversals, tensor-parallel traffic, and backward exchanges are additional quantities. Do not call this payload count total network bytes without stating what has been omitted.

If several selected experts share a destination rank, a dispatcher might reduce duplicate transfer of the same token and expand it locally, while another implementation sends each branch separately. Such deduplication changes the simple per-assignment count. Activation compression or differing output widths also changes it. Measure peer volumes and bytes using the actual packing protocol. A rank's aggregate sends do not reveal the busiest link or simultaneous contention, and dividing cluster-total bytes by one link's bandwidth usually produces an invalid timing estimate.

R=ρTk,Qpayload=2RdsR=\rho Tk,\qquad Q_{\rm payload}=2Rds
In this simplified no-deduplication, no-padding forward path, R is the integer number of remote accepted assignments, expressed as fraction ρ of Tk requested assignments only when that convention is applicable. d is elements per representation and s is bytes per element. Q counts aggregate injected dispatch-plus-return payload bytes, not per-link traffic, metadata, or backward communication.↔ Scroll wide equations horizontally.

The backward pass must invert the same logical operation

Gradient flow follows the actual accepted and weighted branches. Expert gradients need the token activations assigned to that expert, while token-input gradients combine contributions from its surviving branches. Router gradients depend on where weighting occurred and which gate convention was used. Expert replicas in a data-parallel dimension may need gradient synchronization over their own group rather than an unrelated world group. Check these axes explicitly; a forward path that preserves values can still train incorrectly if backward uses a stale permutation or wrong reduction group.

The modular lab offers only a small ordering exercise. Reset, set m=4 and a=1, predict period four visiting all four residues, then Play or Step. Separately Reset, set m=4 and a=2, predict period two, then Play or Step. The second orbit misses half the residues, illustrating why an assumed inverse map needs a real bijection over its intended entries. This is not an all-to-all or dispatcher simulator: it has no peer buffers, replicated token branches, communication time, or gradient storage. Verify actual pack/unpack identities with labeled tensors.

Bound a simple forward payload

A fictional routing group has 1,024 tokens, top-two requested assignments, no drops, and a remote-assignment fraction 0.75. Each representation and returned output has 4,096 two-byte elements. Assume no deduplication or padding.

  1. Requested and accepted assignments total 1,024×2=2,048. Remote count is 0.75×2,048=1,536.

  2. Each remote assignment sends 4,096×2=8,192 representation bytes, totaling 12,582,912 bytes in the dispatch direction.

  3. An equal-width return doubles that payload to 25,165,824 bytes, exactly 24 MiB. Metadata, backend overhead, backward exchange, and repeated physical-link crossings are outside this count.

The result

The model counts 24 MiB of aggregate forward injected payload under explicit assumptions. It does not predict a collective's elapsed time.

Explore the model

Interactive lab

Interactive lab · modular

An ordering map must cover its intended entries

Reset, set m=4 and a=1, predict period 4, then Play or Step. Separately Reset, set m=4 and a=2, predict period 2, then Play or Step. This residue orbit does not pack tokens, simulate peers, or execute all-to-all.

An ordering map must cover its intended entriesAddition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Current readings: Residue r0: 0; Orbit period · m/gcd(m,a): 12; Distinct residues visited: 1 of 12. All parameters are adjustable with the labeled controls below.Repeated addition modulo 12: the current residue is 0, and the orbit period is 12.01234567891011+ 5mod 12An additive orbitn = 0rₙ = 0Period = 12Cycle starts at 0:0 → 5 → 10 → 3 →8 → 1 → 6 → 11 →4 → 9 → 2 → 7 → 0Exact residues · two additions per second
Additive orbitCurrent residue / next edge
Residue r0
0
Orbit period · m/gcd(m,a)
12
Distinct residues visited
1 of 12
t = 0 s

Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forPreserve a tested inverse identity map rather than assuming received order matches token order.

Check your understanding

Why is the inverse routing map necessary after expert computation?

Try it yourself

One token has two accepted scalar expert outputs 2 and 4 with combine weights 0.25 and 0.75. Compute its result. Explain why swapping the outputs without swapping their associated weights is incorrect.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Weights belong to token-expert identities, not arbitrary buffer positions.

Compare with the solution

The correct result is 0.25×2+0.75×4=3.5. Pairing the unchanged weights with swapped outputs gives 0.25×4+0.75×2=2.5, a different function. A pack/unpack test should label assignments and verify identity preservation, not merely compare total buffer size.

Take it with you

  • Dispatch preserves token-expert identities through packing and inverse combination.
  • Payload counts need a named direction, scope, and duplication policy.
  • Backward routing and expert gradient groups require their own correctness checks.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.