MoE Serving & Scheduling: Token Dispatch, All-to-All, Disaggregated Parallelism

Serving a mixture-of-experts model turns sparse computation into a scheduling problem: uneven routing creates stragglers and sending tokens to experts costs communication, which motivates careful scheduling and, in systems such as MegaScale-Infer, separate GPU pools for attention and experts.

Advanced · Graduate mathematics · about 20 minutes

Reading map and next steps

Intuition

The idea in plain words, before the symbols.

A mixture-of-experts (MoE) layer sends each token to only a few of its experts. Serving such a model requires dispatching tokens to their selected experts and collecting the outputs. We compare uneven expert loads and count remote bytes for a small routed batch. The figure checks when load imbalance or communication limits the layer. Sparse computation alone does not establish low latency.

In serving, MoE also becomes a scheduling problem:

  • Tokens are routed unevenly, so some experts receive far more work than others, and the whole layer waits for the busiest one (a straggler).
  • When experts are spread across GPUs (expert parallelism), each MoE layer must send token activations to the GPUs holding their selected experts and gather the results. When every GPU holds both attention and experts, this is an all-to-all exchange; when attention and experts run on separate pools of GPUs, as in MegaScale-Infer, it becomes an M-to-N exchange between the pools (Zhu et al., 2025).
  • During decoding the KV cache also has to fit in memory, so the system manages memory and communication at once.

Sparse FLOPs alone do not make MoE serving fast. The gains come from the scheduling, batching and communication plan around the experts.

Study prompts for this section: Intuition
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

Mathematics

Definitions, assumptions and the derivation.

Token dispatch communication (why layout matters)

Per MoE layer, tokens are sent to their experts and the results are sent back. A rough count of the bytes moved is:

Bytescomm≈2⋅T⋅k⋅dmodel⋅b,\mathrm{Bytes}_{\mathrm{comm}} \approx 2\cdot T\cdot k\cdot d_{\mathrm{model}}\cdot b,

where:

  • TT is tokens in the microbatch,
  • kk is top-kk experts per token,
  • dmodeld_{\mathrm{model}} is hidden width,
  • bb is bytes per element (e.g., 2 for fp16),
  • the factor of 2 is dispatch + combine.

The traffic grows with kk, not with the number of experts: going from top-1 to top-2 routing doubles it. This rough count also assumes every token leaves its GPU; tokens whose expert sits on the same GPU move nothing. If communication is the bottleneck, spreading experts over more GPUs or slower links can make the layer slower even though each token's expert computation is small.

Stragglers from routing skew

Let nen_e be the number of tokens routed to expert ee in a microbatch. If expert compute time is proportional to token count, then layer time is dominated by:

tlayer≈max⁡e  te∝max⁡e  ne.t_{\mathrm{layer}} \approx \max_e\; t_e \propto \max_e\; n_e.

Even if the average load is small, the maximum load can be much larger when routing is skewed. Every token in the layer waits for the busiest expert, so one overloaded expert slows the whole batch.

Disaggregation (separate pools)

One recent response is disaggregation: run attention on one pool of GPUs and the experts on another, and pipeline microbatches between them so that both pools stay busy (Zhu et al., 2025). Each pool can then be sized and parallelized for its own work, at the cost of extra communication between the pools.

Worked example: only served, remote assignments move

The count 2⋅T⋅k⋅dmodel⋅b2\cdot T\cdot k\cdot d_{\mathrm{model}}\cdot b assumes that every token's kk choices are served and that every one leaves its GPU. Neither need hold. Take T=4T=4 tokens on GPU D0, top-2 routing over three experts, and a capacity of two tokens per expert, filled in token order:

  • T0 and T1 choose E0 and E1, and both are served;
  • T2 chooses E0 and E2, but E0 is full, so only E2 serves it;
  • T3 chooses E1 and E2, but E1 is full, so only E2 serves it.

Six of the eight choices are served, two per expert; the two that overflow move nothing (the mixture-of-experts page works through capacity). Now place E1 on D0 and E0 and E2 on D1. A served assignment is remote when its expert's GPU differs from its token's GPU, and each remote assignment sends one activation out and receives one result back. Four are remote (T0→E0, T1→E0, T2→E2, T3→E2), so with dmodel=4096d_{\mathrm{model}}=4096 and b=2b=2,

Bytesremote=2⋅nremote⋅dmodel⋅b=2⋅4⋅4096⋅2=65,536 bytes=64 KiB,\mathrm{Bytes}_{\mathrm{remote}}=2\cdot n_{\mathrm{remote}}\cdot d_{\mathrm{model}}\cdot b=2\cdot 4\cdot 4096\cdot 2=65{,}536\ \text{bytes}=64\ \text{KiB},

half of the rough count, 2⋅4⋅2⋅4096⋅2=131,0722\cdot4\cdot2\cdot4096\cdot2=131{,}072 bytes. Move only E2 onto D0: the same six assignments are served and every expert still holds two tokens, but only T0→E0 and T1→E0 are remote, and the payload halves to 3232 KiB.

These are the bytes the dispatch and return must carry, not measured traffic. Real systems pad and pack buffers, add metadata, choose different collective operations, overlap communication with computation and pay a fixed cost per message, so neither the bytes nor their halving translate directly into time.

Study prompts for this section: Mathematics
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

Code

The same calculation as runnable code, in the notation of the derivation.

import numpy as np

rng = np.random.default_rng(0)
E = 16        # experts
T = 4096      # tokens in a microbatch

# A skewed routing distribution (one "popular" expert)
p = np.ones(E) * 0.9
p[0] = 6.0
p = p / p.sum()

choices = rng.choice(E, size=T, p=p)  # top-1 for simplicity
counts = np.bincount(choices, minlength=E)

print("avg tokens/expert:", round(float(counts.mean()), 2))
print("max tokens/expert:", int(counts.max()))
print("straggler factor max/mean:", round(float(counts.max() / counts.mean()), 2))
print("top-5 expert loads:", np.sort(counts)[-5:][::-1].tolist())

Count the remote bytes

This standard-library Python code serves the top-2 choices under the capacity limit, then counts the remote assignments and their bytes for both placements in the worked example.

TOP2 = {"T0": ("E0", "E1"), "T1": ("E0", "E1"), "T2": ("E0", "E2"), "T3": ("E1", "E2")}
CAPACITY, SOURCE, D_MODEL, BYTES = 2, "D0", 4096, 2

def serve(capacity=CAPACITY):
    load, served = {"E0": 0, "E1": 0, "E2": 0}, []
    for token, experts in TOP2.items():      # fill in token order
        for expert in experts:
            if load[expert] < capacity:
                load[expert] += 1
                served.append((token, expert))
    return served

def remote_bytes(served, placement):
    remote = [(t, e) for t, e in served if placement[e] != SOURCE]
    return remote, 2 * len(remote) * D_MODEL * BYTES   # out and back

served = serve()
placed = {"E0": "D1", "E1": "D0", "E2": "D1"}
moved = {**placed, "E2": "D0"}

assert len(served) == 6
for name, placement in (("E2 on D1", placed), ("E2 on D0", moved)):
    remote, size = remote_bytes(served, placement)
    print(name, "remote:", remote, "bytes:", size, "KiB:", size // 1024)
assert remote_bytes(served, placed)[1] == 65_536
assert remote_bytes(served, moved)[1] == 32_768
Study prompts for this section: Code
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

Demo

Change an input, predict the result, and see which quantities respond.

ExploreChange one control at a time and name what responds.An optional observation guide follows the demo.

Explore MoE Serving & Scheduling: Token Dispatch, All-to-All, Disaggregated Parallelism

Loading the interactive demo…

Observation guide

Optional and ungraded. Opening a guide saves nothing.

Choose what to inspect in MoE Serving & Scheduling: Token Dispatch, All-to-All, Disaggregated Parallelism, then open its guide.

The demo below asks you to predict the bottleneck before it shows the expert loads and the bytes sent to and from the experts. The point is that sparse computation does not guarantee low latency: uneven routing and dispatch-and-combine traffic can each limit the layer. The practice after the demo counts, by hand, which expert assignments leave their GPU and how many bytes they carry.

Study prompts for this section: Demo
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

Practice

Decide which served expert assignments leave the tokens' GPU, count their bytes out and back, then move one expert and count again.

Loading the exercise…
In focus

Concept: MoE Serving & Scheduling: Token Dispatch, All-to-All, Disaggregated Parallelism

What is the smallest example of MoE Serving & Scheduling you can work through by hand, and what does it show?

BeforeScaled Dot-Product Attention & Transformer LayersNextRLHF: Reward Modeling + KL-Regularized Policy Optimization
DetailsLLM Systems

After the first pass

Go deeper

Optional material for a second reading. Sources are always shown; the other panels open from their headings or from these links, and closing one keeps what you wrote or revealed.
What to look for in each sectionChoose a section and what you expect to see in it, then read short advice.

Section by section

Choose what to look for in each section

Serving a mixture-of-experts model turns sparse computation into a scheduling problem: uneven routing creates stragglers and sending tokens to experts costs communication, which motivates careful scheduling and, in systems such as MegaScale-Infer, separate GPU pools for attention and experts.

Choose what to look for (no demo yet)01 / Intuition
Illustration of sparse token routing across experts with all-to-all exchange and a straggler bottleneck.
What to look for

Start with the picture, metaphor, or geometric mechanism.

Choose first

Choose what you expect to see in this section of MoE Serving & Scheduling: Token Dispatch, All-to-All, Disaggregated Parallelism.

Questions to ask of the pictureChoose a part of the picture and what you expect, then read short advice.

Looking at the picture

Questions to ask of the picture

Serving a mixture-of-experts model turns sparse computation into a scheduling problem: uneven routing creates stragglers and sending tokens to experts costs communication, which motivates careful scheduling and, in systems such as MegaScale-Infer, separate GPU pools for attention and experts.

4 of 4 sections writtenNo live demo yet
Question

Which part of the picture should you look at first?

Choose first

Pick the part of the picture you expect to explain MoE Serving & Scheduling: Token Dispatch, All-to-All, Disaggregated Parallelism.

Sources

References for this page

A reference shows where an idea comes from; it does not vouch for every step on this page.
paper · 2017Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts LayerShazeer et al.
Why it is cited

Introduces sparse top-k gating over many experts, with auxiliary losses for uneven expert use, and discusses the batching and network costs of spreading experts across devices (ICLR 2017).

Open source
paper · 2022Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient SparsityFedus, Zoph, and Shazeer
Why it is cited

Uses top-1 routing, sets each expert's capacity with a capacity factor, and discusses the communication cost and training instability that come with sparse experts (Journal of Machine Learning Research 23, 2022).

Open source
paper · 2025MegaScale-Infer: Serving Mixture-of-Experts at Scale with Disaggregated Expert ParallelismZhu et al.
Why it is cited

Runs attention and experts on separate GPU pools, pipelines micro-batches between them and uses an M2N library for token dispatch; reports that sparse activation leaves expert computation memory-bound (arXiv preprint).

Open source
What each claim rests on1 claim, each with its sources, where it appears on this page, and its caveats.

Claims and sources

Serving a mixture-of-experts model turns sparse computation into a scheduling problem: uneven routing creates stragglers and sending tokens to experts costs communication, which motivates careful scheduling and, in systems such as MegaScale-Infer, separate GPU pools for attention and experts.

Checked against the cited passages

The checks were made by this site, not by an independent reviewer.

MoE inference and serving use sparse routing: a gate sends each token to a small subset of experts, so per-expert token counts can become uneven and require load-balancing, capacity buffers, or scheduling/parallelism choices.
What the sources support

Shazeer supports sparse top-k MoE routing plus importance/load-balancing losses for uneven expert use. Fedus supports top-1 routing, expert-capacity overflow, auxiliary load balancing, and communication-cost...

Caveat

This covers sparse routing, uneven expert load and the scheduling they force. Shazeer et al. and Fedus et al. describe the model and its training; MegaScale-Infer describes serving. The byte count, straggler...

StatusChecked against the cited passages.

Shazeer et al. (2017) support sparse top-k MoE routing and load- and importance-balancing losses for uneven expert use. Fedus et al. (2022) support top-1 routing, capacity overflow, auxiliary load balancing and communication-cost tradeoffs. MegaScale-Infer (2025) supports, for serving, MoE decoding, token dispatch, under-used expert computation caused by sparsity, separating attention from experts, M2N/N2M communication in that design, and uneven expert load in production.

Explain it without the pageWrite your own explanation before asking for feedback. Your draft and any hints stay while this page is open.

Practice · MoE Serving & Scheduling: Token Dispatch, All-to-All, Disaggregated Parallelism

Try the idea in your own words

Serving a mixture-of-experts model turns sparse computation into a scheduling problem: uneven routing creates stragglers and sending tokens to experts costs communication, which motivates careful scheduling and, in systems such as MegaScale-Infer, separate GPU pools for attention and experts.

Concept · Selected for practice

MoE Serving & Scheduling: Token Dispatch, All-to-All, Disaggregated Parallelism

What it rests on: Sources: Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer; Switch Transformers: Scaling to Trillion Parameter Models...

Context and links
Choose a task

Explain the mechanism

For MoE Serving & Scheduling: Token Dispatch, All-to-All, Disaggregated Parallelism: What is the smallest example of MoE Serving & Scheduling you can work through by hand, and what does it show? Explain your answer, including what changes, why, and which assumption matters.

No answer yet

A rough first thought is enough. Your draft stays when you change tasks.

Your draft stays on this page and is cleared when you leave or reload.

A little help · Explain

Open one hint at a time. These are suggestions, not your answer or a grade.

0 of 3 hints shown for this question.

    Clearing your answer keeps this help record. Outside help is your own report; this page cannot check it.

    Where am I stuck? (optional)
    Your own description, not an automatic diagnosis

    Choose one, or leave this unspecified. Select it again to clear it.

    Take your draft to a feedback conversation

    No AI feedback runs here. You can copy a prompt to use elsewhere; nothing is sent automatically. Review the text before sharing, and leave out private information.

    Write an attempt before copying a feedback prompt.

    A draft, or an AI reply to it, is not a test of what you have learned. To check that, try a different case later without help.

    Ask about this pagePick one item on this page and copy a prompt about it into an AI assistant you already use. Notes you write here stay in this browser.
    Ask about this pageClose
    ConceptMoE Serving & Scheduling: Token Dispatch, All-to-All, Disaggregated ParallelismSources: Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer; Switch Transformers: Scaling to Trillion Parameter Models...assert len(served) == 6

    Your question

    Choose what your question is about

    Pick the idea, equation, source, code, claim, misconception or demo state you want to ask about. The prompt you copy includes it, so the answer can stay on that item.
    Next local actionNo local draft saved yet

    Open the draft below to save one note and next action in this browser.

    conceptLLM Systems

    MoE Serving & Scheduling: Token Dispatch, All-to-All, Disaggregated Parallelism

    Starting question

    What is the smallest example of MoE Serving & Scheduling you can work through by hand, and what does it show?

    SourcesCheck the 3 cited sources listed under Sources.Notes can be saved for this item
    Points of view on this item

    Fixed prompts generated from this item. They are not comments from people or independent reviews.

    Learner’s first stepAsk what would make "MoE Serving & Scheduling: Token Dispatch, All-to-All, Disaggregated Parallelism" feel predictable rather than familiar.
    Assumption

    The 3 cited sources must support this exact item, not just the surrounding topic.

    Source-checking summary

    Connect the definition to one equation, piece of code or demo before widening the discussion.

    Proposed experiment

    Change one input, then check that the same relationship holds in the mathematics, the code and the demo.

    Next action

    You can state the mechanism in your own words

    Evidence4 checks
    ObservationChecking for a saved observation
    ActionReady for one action
    PromptLearner prompt ready to copy
    Go to this item
    01ObservationChecking what this browser has saved
    02EvidenceChecking for a saved observation
    03SourcesCheck the 3 cited sources listed under Sources.
    04Next stepSave one next action
    Local action draftNo local draft saved yetOpen when you are ready to write one next action
    Local action draft

    This draft stays in this browser and is attached to this item only.

    No local draft saved.
    Evidence to inspect
    • What the 3 cited sources say about this exact item
    • The definition, its prerequisites, and a contrasting concept
    • The equation or code that makes the concept concrete
    • One demo state that shows what stays the same as the inputs change
    What would resolve this
    • You can state the mechanism in your own words
    • You can name the prerequisite that would clear up the confusion
    • You can predict how the result changes when one input changes
    Reference idconcept/concept-notebook/llm-systems/moe-serving concept:llm-systems/moe-serving