In expert parallelism every rank waits for the slowest rank, so a single over-subscribed expert sets the step time. The fix used in production is redundant experts: each rank gets a few spare slots that hold replicas of hot experts, and a hot expert's tokens are split evenly across its replicas. Implement the placement.
moe_lb(rank_loads)
1.0 if the mean is zero.eplb_assign(loads, n_ranks, redundant_per_rank)
loads[i] is the token count routed to expert i over the statistics window. E = len(loads) is divisible by n_ranks. Each rank has E // n_ranks + redundant_per_rank slots, so there are n_ranks * redundant_per_rank replica slots to hand out.loads[i] / copies[i]), ties to the lower index, and an expert never gets more copies than there are ranks.copies[i] distinct ranks with a free slot that currently have the lowest load (ties by lower rank index); each copy adds loads[i] / copies[i] to its rank. If fewer ranks have a free slot than the expert has copies, reduce its copies to that number before placing."replicas" (copies per expert), "placement" (per rank, the sorted list of expert ids it holds), "rank_loads" (floats rounded to 4 decimals) and "moe_lb".(load, index) and taking the first copies[i] with a free slot gives both the lowest-load rule and the tie-break in one step.