Introducing Model Factory. Read the announcement

Blog / Research

Fusing Distributed Load Balancing Inside Mega MoE Kernel

DEC 1ST, 2026
Xuan-Phi Nguyen
Fusing Distributed Load Balancing Inside Mega MoE Kernel

Fusing Distributed Load Balancing Inside Mega MoE Kernel

Introduction

In our previous post, we made MoE training fast by fusing routing, communication, expert compute, and the return trip into one overlapping kernel. That kernel inherits a problem every expert-parallel system has: GPUs wait for the busiest GPU. Real routers don't spread tokens evenly. A few popular experts pull in far more tokens than average, and whichever GPU hosts them becomes the straggler that sets the pace for the entire layer.

So we went one step further and put load balancing inside the fused kernel. The Prime Mega MoE kernel now plans the balancing on the GPU, copies the weights of overloaded experts to idle GPUs while it computes, and gives every GPU an equal share of the work, without changing a single bit of the result.

  • Up to 6× faster MoE layers under heavy expert skew, on top of Mega MoE.
  • 1.2-1.6× faster MoE layers on real DeepSeek-V4 routing.
  • Up to 3.4× less communication memory: 64K tokens per GPU fit in 14 GiB, where Mega MoE would need about 170 GiB.
  • Scales past one node: EP 16 and EP 32 over GPU-initiated InfiniBand, where balancing is worth 1.4-1.5×.
  • Exact: outputs and input gradients are bit-for-bit identical to Mega MoE.
  • Runs on Hopper (BF16, FP8) and Blackwell (MXFP8, NVFP4) GPUs.

The Straggler Problem

In expert parallelism, each GPU owns a fixed slice of the experts. When the router sends 3× the average traffic to one GPU's experts, that GPU computes 3× longer, and the seven other GPUs sit idle until it finishes. Faster kernels make every GPU faster, but they don't remove the wait.

Where the time goes: one hot expert, eight GPUs. Schematic of one MoE layer inside the fused kernel

This isn't a corner case. In a DeepSeek-V4-Flash training run, the busiest GPU of a layer carries 1.3-1.6× the average load on typical steps, and up to 1.9× on the most skewed layers. The imbalance grows with the expert-parallel size, and every data-parallel replica waits for its slowest group.

NVLinkGPU 0hot expert E0planningGPU 1planningGPU 2planningGPU 3planningGPU 0comm warpstensor coresGPU 1comm warpstensor coresGPU 2comm warpstensor coresGPU 3comm warpstensor corespush E0pull tokensown expertssendpull tokensown expertssendpull tokensown expertsE0 sharesendpull tokensown expertsE0 sharesenddispatchcombineMega MoE done
token rowsE0 weightsresults

Dynamically Replicating Hot Experts on Idle Ranks

With fused load balancing, when a GPU is overloaded, we divert some of its hot experts' tokens to the least-loaded GPUs instead, using a copy of the expert's weights. The idea follows the least-loaded principle of LLEP [1]. Our version runs entirely on the GPUs, inside the fused kernel.

Step 1: Constructing the Routing Plan on the GPU

Step 1: count routes, assign the least-loaded GPUs, and turn the plan into ordinary expert ids (about 50 µs, no CPU)

The planning stage starts with every GPU counting how many of its tokens go to each expert. The counts are written straight into every other GPU's memory over NVLink, without a collective call or a trip to the CPU. Each GPU then runs the same small greedy least-loaded assignment [1] on that table.

def plan(load):                         # load[e]: tokens routed to expert e, from all GPUs
    capacity = a little above the average load per GPU
    for e in experts, hottest first:
        home = owner(e)
        keep = min(load[e], room left on home)   # leaving space for home's other experts
        assign(e, home, keep)
        rest = load[e] - keep
        while rest > 0:
            if rest is too small to justify copying weights:
                assign(e, home, rest)
                break
            helper = least-loaded GPU with a free foreign slot
            chunk = min(rest, room left on helper)
            assign(e, helper, chunk)    # helper receives a copy of e's weights
            rest -= chunk
    return assignment                   # per expert: token ranges -> GPU slots

When no GPU is meaningfully overloaded, nothing spills and every expert stays home, so the layer runs exactly like plain Mega MoE.

The assignment is applied by relabeling routes. Besides its own experts, every GPU has a few foreign slots that can hold borrowed experts. The slots are shared across all MoE layers of the model rather than owned by each layer, which saves memory. Tokens routed to an expert are assigned routes to a GPU rank, which is not necessarily where the routed expert resides. All-to-all operations move the tokens according to this routing plan. The whole planning step takes tens of microseconds, and because tensor shapes stay static it works with torch.compile and CUDA graphs.

Step 2: Stream Weights Inside the Kernel

Step 2: one fused forward call on two of the eight GPUs; time runs left to right

A helper rank needs a borrowed expert's weights before it can compute it. Copying them sequentially would put the copy on the critical path, so the kernel overlaps it with computation.

The copy is done by the warps that pull tokens. In Mega MoE, every SM runs its own dispatch warps next to the warps that compute the GEMMs. Once a GPU has pulled all of its token rows, computation begins. During this time, instead of sitting idle, those warps write the GPU's lent experts directly into the helpers' foreign slots over NVLink, spread across every SM. When a slot is complete, the writer sets a ready flag on the helper with a release store.

On the helper rank, the scheduler performs computation through the GPU's own native experts first. When it gets to a borrowed expert, the warp reads its weights from the foreign slot through a second set of TMA descriptors. Native weights are read where they already are, so nothing is ever concatenated. By the time the helper reaches the borrowed expert the weights have almost always arrived, thus hiding expert transfer behind computation.

Step 3: An Exact Backward

Step 3: weight gradients of a shared expert are summed once, in FP32, in a fixed order

In the backward pass, each helper computes the weight gradient for its share of a borrowed expert and writes it in FP32 to a gradient slot. The home GPU writes its own share to a local FP32 buffer. A gather kernel then adds up each expert's partial gradients in FP32, always in the same order. Splitting an expert therefore adds no rounding: weight gradients are as accurate as Mega MoE's.

Smaller Buffers

Mega MoE has to size its receive buffers for the worst case, in which every GPU sends all of its tokens to the same GPU, so the buffers grow with both the batch and the number of GPUs. With balancing, no GPU receives much more than its fair share, so the buffers only need room for a small multiple of the average, and the kernel checks that bound on the device. This cuts the communication buffers by more than 3×.

Across Nodes

Beyond one node, tokens travel over InfiniBand through a GPU-initiated rail transport. Each GPU exchanges tokens with the GPUs that have the same local index on the other nodes, in fixed-size chunks issued by the GPU itself, and each chunk signals its arrival directly in the receiver's memory, so no host synchronization is involved. Each node then runs the balanced kernel over its own experts for the tokens of every node. Helpers are always on the same node, so weight copies stay on NVLink, and partial results go back over the same rails. On real routing at EP 16, this brings the busiest GPU from 1.56× to 1.10× the average.

Benchmarks

Under Routing Skew

Setup: 1 node, EP 8, one DeepSeek-V4-Flash MoE layer (256 experts, top-6, hidden 4096, expert FFN 2048), forward + backward. The routings are standard synthetic skews: balanced, Zipf-distributed expert popularity, and hot experts, where a fixed share of every GPU's tokens goes to a few experts that all live on one GPU. The chart uses 16,384 tokens per GPU.

One MoE layer under routing skew

Without balancing, layer compute time grows with the busiest GPU's load. With fused balancing it barely moves: from balanced to the extreme case it rises 40% on H200 and 38% on B300, against 7.4× and 6.1× for Mega MoE, a speedup of up to 5.3× on H200 and 4.4× on B300.

Across all the standard skew scenarios, the speedup grows with how overloaded the busiest GPU is.

Speedup grows with skew

In the labels, "80% → 16" means 80% of every GPU's tokens go to 16 hot experts.

On Real DeepSeek-V4 Routing

Setup: the exact per-expert loads of 12 micro-steps × 43 layers, recorded from a DeepSeek-V4-Flash SFT run and replayed through the kernels. 8×H200, BF16, 32,768 tokens per GPU, forward + backward.

Real DeepSeek-V4 routing: the straggler tax disappears

With real routing, Mega MoE's layer time follows the busiest GPU's load, while the balanced kernel holds flat at its balanced speed. The average speedup is 1.20×, and the most skewed layers run 1.64× faster. B300 with MXFP8 shows the same picture, with 1.22× on average at 64K tokens per GPU. Because every data-parallel replica waits for its slowest group, the gain grows with scale. Replayed at the skew we measured in a production RL run on 112 B300s, the MoE layers are 1.32× faster.

Memory

Up to 3.4× less communication memory, and 64K tokens per GPU fit

Because the plan bounds what any GPU receives, the buffers shrink 3-3.4×. That frees tens of GiB per GPU for larger micro-batches, and it makes long-context training possible: at 64K tokens per GPU, the balanced kernel runs in 4 chunks over 14.4 GiB, a size Mega MoE cannot allocate at all.

To InfiniBand and Beyond

Setup: one MoE layer with real DeepSeek-V4-Flash routing, H200 BF16, 65,536 tokens per GPU, forward + backward. EP 16 and EP 32 span 2 and 4 nodes connected by 400 Gb/s InfiniBand. The baseline is the same kernels and transport, without balancing.

Beyond one node: balancing pays more as EP grows

Spreading the experts over more GPUs makes the busiest GPU more overloaded (2× the average at EP 32), so balancing matters more: 1.41× at EP 16 and 1.48× at EP 32. The rail transport sustains 47.5 GB/s per GPU, 96% of InfiniBand line rate. Because its InfiniBand traffic is fixed regardless of routing, skew no longer turns into network hotspots.

Supported Configurations

GPUPrecisionExpert parallelism
H200 (Hopper)BF16, blockwise FP8EP 8 over NVLink; EP 16 / 32 over InfiniBand
B200 / B300 (Blackwell)MXFP8, NVFP4EP 8 over NVLink; EP 16+ over InfiniBand

Conclusion

Fusing communication and compute removed the waiting between operations; fusing load balancing removes the waiting between GPUs. The kernel plans on the GPU in microseconds, moves expert weights while it computes, and gives every GPU the same amount of work, so MoE layers run at their balanced speed whatever the router does. The result is up to 6× faster MoE layers under skew, 1.2-1.6× on real routing, up to 3.4× less communication memory, and expert parallelism that scales beyond a single node.

Special thanks to Garrett Goon, Mario Sieg, and Sami Jaghouar for their feedback!

Citation

@article{nguyen2026fusing,
author = {Xuan-Phi Nguyen},
title = {Fusing Distributed Load Balancing Inside Mega MoE Kernel},
journal = {Prime Intellect Blog},
year = {2026},
month = {December},
note = {https://www.primeintellect.ai/blog/fused-load-balancing-mega-moe}
}