Summary of RoutePack: Expert Placement and Attention-Aware Data Packing for MoE Reinforcement Learning

Summary (Overview)

  • RoutePack is a hierarchical planner that jointly coordinates layer-wise expert placement and attention-aware data packing for Mixture-of-Experts (MoE) reinforcement learning (RL) training, addressing two coupled load-balancing problems: dense attention work in data-parallel (DP) microbatches and sparse expert work in expert-parallel (EP) ranks.

  • The system leverages routing replay from the rollout phase—which reveals each sample's sequence length and layer-wise expert demand before training—to convert data layout from a routing-blind preprocessing step into a load-balancing control.

  • The formulation uses a lexicographic objective that prioritizes (1) the slowest EDP shard over the optimizer-step window, (2) total projected work, and (3) the worst row-local tail, while preserving capacity-efficient row counts.

  • Across Ling-3.0-Tiny (7.9B params) and Ling-3.0-Flash (124B params), RoutePack improves trainer-measured token throughput by 8.85% and 14.89% respectively over baseline, with expert rerouting contributing 3.80%/10.50% and routing-aware packing adding 4.86%/3.98%.

  • The implementation uses layer-wise Longest Processing Time (LPT) placement, state-consistent expert materialization, diverse fixed-row seeding, and parallel population annealing, with a sufficient runtime condition derived for CPU packing to not extend the training-admission critical path.

Introduction and Theoretical Foundation

The Two Coupled Load-Balancing Problems

MoE RL training exposes two distinct sources of load imbalance:

  1. Dense attention imbalance: Variable-length RL responses mean that equal sample counts (or even equal packed-token counts) do not imply equal attention work, especially for attention operators with sequence-pair (quadratic) components.

  2. Sparse expert imbalance: Token routing determines expert work per EP rank, and the busiest physical rank at each MoE layer paces dispatch and grouped GEMM execution.

The Key Insight: Routing Replay

The rollout and training phases process the same generated token sequence, so routing replay exposes each sample's token length and layer-wise expert demand before the optimizer step is scheduled. For an optimizer-step batch of NN samples, the planner receives:

{(ti,Ai)}i=1N,Ai=[ai,l,e]lLMoE,eEl\{(t_i, A_i)\}_{i=1}^N, \qquad A_i = [a_{i,l,e}]_{l \in \mathcal{L}_{\mathrm{MoE}}, e \in \mathcal{E}_l}

where tit_i is the sequence length and ai,l,ea_{i,l,e} is the replayed routing count for logical expert ee at MoE layer ll.

Why Coordination is Necessary

The paper establishes two critical invariants:

Packing cannot remove optimizer-window expert skew: For a fixed placement πl\pi_l, the aggregate demand on physical rank pp is:

Ll,pagg(πl)=ie:owner(πl(e))=pai,l,eL_{l,p}^{\mathrm{agg}}(\pi_l) = \sum_i \sum_{e: \mathrm{owner}(\pi_l(e)) = p} a_{i,l,e}

and for any capacity-feasible packing xx:

rgmaxpWr,g,l,p(x;πl)maxpLl,pagg(πl)\sum_r \sum_g \max_p W_{r,g,l,p}(x; \pi_l) \geq \max_p L_{l,p}^{\mathrm{agg}}(\pi_l)

Expert placement does not guarantee row-local balance: A placement can make step-wide totals nearly equal while individual rows remain imbalanced due to correlated routing vectors being packed together.

Attention Work Proxy

For attention operator AA and DP cell Br,dB_{r,d}, the two-term execution proxy is:

FA(Br,d)=αAiBr,dti+βAiBr,dti2,βA0F_A(B_{r,d}) = \alpha_A \sum_{i \in B_{r,d}} t_i + \beta_A \sum_{i \in B_{r,d}} t_i^2, \qquad \beta_A \geq 0

The linear term captures projections and recurrent/linear-attention work; the quadratic term captures token-pair interactions in full attention. KDA and Gated DeltaNet use βA=0\beta_A = 0, while MLA and Gated Attention use βA>0\beta_A > 0.

Methodology

Problem Formulation

Decision variables: Layer-local permutation πl\pi_l maps logical experts to physical slots; binary variable xi,r,dx_{i,r,d} indicates sample ii is assigned to cell at row rr and DP slot dd.

Feasibility constraints (rectangular fixed-row):

r=1Rd=1Dxi,r,d=1,i\sum_{r=1}^{R}\sum_{d=1}^{D} x_{i,r,d} = 1, \quad \forall i itixi,r,dC\sum_i t_i x_{i,r,d} \leq C

The minimum feasible row count is Rmin=min{R:XR}R_{\min} = \min\{R: \mathcal{X}_R \neq \varnothing\}.

Hierarchical Planning

Stage 1: Layer-wise expert placement using LPT scheduling. For candidate placement, aggregate physical-rank load is:

Gl,p(πl)=e:owner(πl(e))=pLl,eG_{l,p}(\pi_l) = \sum_{e: \mathrm{owner}(\pi_l(e)) = p} L_{l,e}

where Ll,e=iai,l,eL_{l,e} = \sum_i a_{i,l,e}. LPT greedily assigns experts in descending load order to the currently least-loaded physical rank.

Stage 2: Fixed-row data packing with the lexicographic objective:

Score(x;π)=(maxgUg,gUg,maxr,gJr,g)\mathrm{Score}(x; \pi) = \left(\max_g U_g, \sum_g U_g, \max_{r,g} J_{r,g}\right)

where Ug=rJr,gU_g = \sum_r J_{r,g} is the projected work accumulated by EDP shard gg, and Jr,g=Ar,g+Er,gJ_{r,g} = A_{r,g} + E_{r,g} combines attention and expert costs.

The attention cost per row-shard is:

Ar,g=sAmaxdDg(αsTˉr,d+βsQˉr,d)A_{r,g} = \sum_{s \in \mathcal{A}} \max_{d \in \mathcal{D}_g} \left(\alpha_s \bar{T}_{r,d} + \beta_s \bar{Q}_{r,d}\right)

with normalized statistics Tˉr,d=1Citixi,r,d\bar{T}_{r,d} = \frac{1}{C}\sum_i t_i x_{i,r,d} and Qˉr,d=i(ti/C)2xi,r,d\bar{Q}_{r,d} = \sum_i (t_i/C)^2 x_{i,r,d}.

The expert cost is:

Er,g=1ClLMoEmaxpWr,g,l,p(π,x)E_{r,g} = \frac{1}{C} \sum_{l \in \mathcal{L}_{\mathrm{MoE}}} \max_p W_{r,g,l,p}(\pi, x)

where Wr,g,l,pW_{r,g,l,p} is the routed-token load on physical EP rank pp at layer ll.

Population Annealing Solver

The solver combines:

  • Diverse fixed-row seeding: Window Shuffle, RandomizedBestFit, and EDPAwarePair operators generate structurally diverse feasible seeds
  • Fixed-temperature population annealing: Parallel chains with Metropolis acceptance based on scalar energy E(x)=s0(x)+106s1(x)+109s2(x)\mathcal{E}(x) = s_0(x) + 10^{-6}s_1(x) + 10^{-9}s_2(x)
  • Systematic resampling between temperature levels with Boltzmann weights
  • Trajectory-best archive for non-regressing global incumbent

Empirical Validation / Results

Trainer-Measured Throughput

ModelT/A paramsBaselineReorderRoutePack
Tiny7.9B/1.3B42.86±3.0542.86 \pm 3.0544.49±1.9244.49 \pm 1.9246.65±2.1246.65 \pm 2.12
Flash124B/5.1B68.50±5.0268.50 \pm 5.0275.69±4.5975.69 \pm 4.5978.70±3.8278.70 \pm 3.82
  • Tiny: Expert reordering improves throughput by 3.80%; packing adds 4.86% → total 8.85% over baseline
  • Flash: Reordering improves 10.50%; packing adds 3.98% → total 14.89% over baseline
  • All pairwise comparisons significant after Bonferroni correction (largest adjusted p-value: 0.0110)

Load-Balance Decomposition

Global EP-rank CV: LPT reduces mean global EP-rank coefficient of variation by more than 99% on both models.

Online load metrics from length-only FFD to guided packing:

ModelEP peak sumTail peakEP balance eff.AttentionJoint
Tiny-3.13%-11.04%0.891 → 0.920+0.09%-1.53%
Flash-3.24%-11.62%0.844 → 0.869+0.77%-1.35%

Key finding: Guided packing accepts a small increase in projected attention work (+0.09% to +0.77%) in exchange for larger reductions in EP peaks (3.13–3.24%) and the joint bottleneck (1.35–1.53%).

Theoretical and Practical Implications

Design Requirements Established

  1. Capacity efficiency must precede load-balance optimization — otherwise, lower peaks from extra microbatches increase total work
  2. Correct parallel scope matters: attention is per DP cell, expert work is per EDP shard (as induced by the deployed communicator)
  3. Complete-step optimization: independent EDP shards accumulate work at different rates; the primary tail objective must consider the slowest shard over the window

Framework Parallel Schedule

The modeled makespan from routing readiness is:

Ttarget=max{TLPT+Tpack,max(TLPT,Taux)+Tactor}+TadmitT_{\text{target}} = \max\left\{T_{\mathrm{LPT}} + T_{\mathrm{pack}}, \max(T_{\mathrm{LPT}}, T_{\mathrm{aux}}) + T_{\mathrm{actor}}\right\} + T_{\mathrm{admit}}

CPU packing introduces no additional admission straggler if:

TLPT+Tpackmax(TLPT,Taux)+TactorT_{\mathrm{LPT}} + T_{\mathrm{pack}} \leq \max(T_{\mathrm{LPT}}, T_{\mathrm{aux}}) + T_{\mathrm{actor}}

Complexity Bounds

With saturated workers (Wmax{M,Ppop}W \geq \max\{M, P_{\mathrm{pop}}\}), total host-side wall complexity is polynomial:

TCPUsat=O(Aroute+L(ElogE+EP)+nBlogB+B2GLP+qR(F+logR)+Ppop(n+qR)+NTK(RGLP+RD))T_{\mathrm{CPU}}^{\mathrm{sat}} = O\left(A_{\mathrm{route}} + L(E\log E + EP) + nB\log B + B^2 GLP + qR^*(F + \log R^*) + P_{\mathrm{pop}}(n + qR^*) + N_T K(R^*GLP + R^*D)\right)

Conclusion

RoutePack demonstrates that routing replay can serve as both an expert-side and a data-placement signal in sparse RL systems. The key contributions are:

  1. Joint control: State-consistent, layer-wise expert rerouting coordinated with whole-sample data packing
  2. Joint objective: Linear-quadratic attention work combined with per-layer physical EP-rank tails within each projected EDP shard
  3. Practical implementation: Layer-wise LPT, state-consistent materialization, diverse seeding, and parallel population annealing with exact lexicographic scoring

Future directions identified by the authors:

  • Scaling studies across datasets, larger EDP shards, multiple nodes, and nontrivial PP/CP degrees
  • End-to-end instrumentation to quantify planning overhead in real deployments
  • Communication-heavy deployments requiring calibrated topology-aware cost terms
  • Kernel microbenchmark suites for shape-aware latency surfaces
  • Extending evaluation to coding, STEM, instruction-following, and mixed-domain workloads

Related papers