Elamur Research

Accelerating MoE Model Inference with Expert Sharding

Paper · 2025 · Oana Balmau, Anne-Marie Kermarrec, Rafael Pires et al.

Summary

A mixture-of-experts network saves computation by sending each input token to a small subset of its available experts. That economy creates a problem when inference runs across several graphics processing units, or GPUs. If each GPU owns a different group of experts, a popular expert can leave its host with a long queue while other devices finish early. The next layer still has to wait for the results. The paper develops MoEShard to make the amount of expert computation on each GPU independent of which experts the router selects.

MoEShard gives every GPU a slice of every expert. Each expert has an input weight matrix that maps tokens into an intermediate representation and an output weight matrix that maps that representation back. The system assigns the columns of the input matrix and the corresponding rows of the output matrix to the same device. Every GPU receives the routed tokens and computes its share of their expert outputs. The devices then return these partial results to the GPUs that supplied the tokens, where the contributions are added. A surge in demand for an expert now increases the workload on all devices together, and the system processes the full set of routed tokens. To keep the many small calculations from dominating runtime, MoEShard groups tokens by expert across source GPUs and can combine the expert calculations using the block-sparse operations of MegaBlocks.

The authors test the Switch-Base encoder on BookCorpus using four NVIDIA A100 GPUs connected by NVLink. With the original Switch router, mean layer latencies range from 41.5 ms to 43.5 ms for MoEShard and from 177 ms to 180 ms for DeepSpeed-MoE. In separate experiments, the authors use a randomized router to control how unevenly tokens are assigned. The reported speedup peaks at 6.45× when they vary the expert count at a fixed batch size. In the batch-size sweep, MoEShard is slower at 10 and reaches approximately 6.24× at 450. The authors call their full encoder timing time to first token, or TTFT. Here it covers the encoder forward pass.

The gains come with two costs that matter for interpreting the results. Broadcasting the expert inputs increases the activation data each device receives and stores. Combining expert operations also incurs setup work, which the ablation shows can outweigh its benefit at smaller expert counts. The evaluation establishes the latency gain for an encoder on a fast single-server interconnect. The results at larger expert counts also compare systems with different token retention, because DeepSpeed can drop assignments under its capacity limit while MoEShard keeps processing them.

Deep dive: Accelerating MoE Model Inference with Expert Sharding

MoEShard splits each mixture-of-experts network across GPUs to balance inference work, retain routed tokens, and reduce encoder latency. · about 36 minutes to read

The problem and its context

Sparse computation still needs memory

A transformer processes a sequence through a succession of blocks. In the architecture the paper discusses, self-attention lets each position draw on other positions in the sequence. A feed-forward network then updates the representation at each position. In a mixture-of-experts block, the feed-forward stage offers several networks, called experts. A router chooses which expert or small set of experts receives the representation of each token. The full collection adds parameters that are available for use, while each token activates only part of that collection.

The paper situates this design in the effort to scale large language models while controlling the computation required at inference. It cites earlier work on conditional computation, where the execution path depends on the input. Under this arrangement, adding experts increases the range of available parameters without requiring each token to pass through every expert. The set of active weights depends on the incoming tokens. An inference system must still have access to the weights that might be selected, which makes storage a separate concern from how much computation a token triggers.

The authors illustrate this distinction with a Switch-Base encoder-decoder configuration with 256 experts. They report that the full network requires 54.63 GiB of memory, while the parameters activated for a single token require 1.11 GiB. Those figures refer to parameter memory in the example. The first helps explain why the weights can exceed the capacity of a single GPU, while the second illustrates how much smaller the active path can be. The serving measurements later in the paper use the encoder. The memory example concerns the larger encoder-decoder architecture from which that encoder comes.

A common way to fit the weights is expert parallelism. Each GPU stores some of the complete experts. The devices have copies of the attention and router components, so each can start with its own portion of the input and run those components locally. Once the routers make their decisions, some of the resulting token representations have to travel to other GPUs. A device that owns a given expert receives the representations assigned to it, including those that originated elsewhere. Expert parallelism distributes the weight storage and makes it possible to execute different experts concurrently.

This puts communication directly on the path of a forward pass. The paper describes a scatter, where the devices exchange tokens to get them to the right experts, and a gather, where they return the processed representations to their original sources. In this setting, an all-to-all exchange means that any GPU can send data to, and receive data from, the others. The destinations and the amounts sent depend on the router's choices. Once the outputs are back, the devices can continue processing their portions of the sequences.

An even distribution of weight storage gives only partial information about how long that procedure will take. Expert calculations scale with the work assigned to the experts. A GPU can own the same number of experts as its peers and still have far more token representations to process. It can also have a small workload in one batch and a large one in the next. The complication is the interaction between the distribution of assignments and the distribution of experts over devices. A router can produce skew at the expert level, and expert placement can concentrate that skew on a device.

Why the busiest device sets the pace

The router is trained with an interest in spreading assignments across experts, but the paper observes substantial concentration in practice. Its illustration uses the first and last layers of a Switch encoder with 128 experts. The authors plot the empirical cumulative distribution of token counts per expert. To read such a plot, choose a count and ask what fraction of experts received that many tokens or fewer. The plot preserves the spread in demand that an average over all experts would conceal. In the last layer, 14 experts receive no tokens and the busiest receives 3105.

Those figures describe assignments to experts. The workload on a GPU depends on which experts it holds, because their assignments accumulate on the same device. A placement can distribute some heavily used experts across different GPUs. It can also concentrate them, and its effectiveness can change as later batches or layers make different demands. A device finishes its local work when its experts have processed their queues. Completing the layer for the entire batch depends on the return of the expert results, including those from the busiest device. Finishing early on another GPU leaves that device with time in which it cannot advance the same layer.

The paper frames this as an inference problem as well as a concern for training. Inference must carry out the routing choices that the trained network makes on incoming input, and its latency includes the wait for those choices to be serviced. The authors describe a literature that had devoted substantial effort to training and to decoder architectures. They focus on the encoder in a multi-GPU setting, where a forward pass presents a body of expert work large enough to study the consequences of unbalanced placement and the overhead of implementing an alternative.

One response is to place a limit on the number of tokens an expert can accept. A capacity factor sets the allowance. This controls the work and storage associated with an expert when requests exceed that allowance. It can also leave assignments unprocessed. The paper identifies this as a possible cost to accuracy. Lower latency achieved under a limit can therefore reflect a change in the amount of expert work completed, a distinction that becomes important in the evaluation.

A second response is to make popular experts available on several devices. The paper describes Lazarus as placing copies of often used experts where they can help spread demand. The copies take additional GPU memory. Prophet uses a placement model for balancing load and a greedy search to improve the arrangement. Lina uses profiles and predictions about expert selection to schedule resources dynamically. In the authors’ account, changes in expert popularity complicate placement and scheduling based on past demand. These approaches try to make different deployment decisions as the distribution of work changes. Lina

The paper also discusses systems that optimize communication and adapt the way parallel execution proceeds. DeepSpeed-MoE provides optimized kernels, hierarchical all-to-all communication, and several parallelism strategies. Under the expert-parallel placement discussed here, a fixed assignment of complete experts to devices can still make uneven demand expensive. Tutel can adjust its parallelism strategy from one iteration to another, though the authors identify static expert placement as a remaining source of imbalance. ExFlow places experts using patterns of affinity across layers to reduce token transfers. The authors note that changes in the inputs can alter those patterns. DeepSpeed-MoE and Tutel

MoEShard intervenes at the point where placement translates routing into physical work. With whole experts placed on separate devices, choosing an expert can also select the device that performs its computation. With a slice of every expert on every device, the choice specifies which weights each device uses for its share of the same calculation. The selected expert can still have a long queue, but every GPU works on that queue. A device can contribute to the output of a popular expert using its assigned slice, without needing a complete copy of that expert. The design makes the distribution of the calculation across devices a property of how the weights are partitioned.

The method, step by step

Follow a token through an expert

MoEShard changes the execution of the expert stage. Attention, the router, and the other components outside the experts are replicated across the GPUs. Each device starts with the portion of the input it is responsible for and runs the earlier components locally. Once routing is complete, there are two identities to keep track of for every token representation. The expert identity tells the system what computation to perform. The source GPU tells it where the finished representation belongs.

Consider a representation assigned to a busy expert. In MoEShard, it travels to all GPUs participating in the expert stage. Each device already holds part of that expert's weights. Using those weights, it calculates a contribution to the output for the representation. The contributions have the same output coordinates, so the source GPU can add corresponding elements after receiving them. Its result is the completed output of the selected expert for that representation. Other tokens follow the same procedure, using the local weights of whichever experts they were assigned.

Here a shard is a contiguous slice of a weight matrix. For the input matrix, a shard consists of columns. A column determines one coordinate of the intermediate representation, using the full input representation. For the output matrix, a shard consists of rows chosen to match exactly those intermediate coordinates. Each GPU can therefore move from raw expert input through its part of the intermediate representation to a contribution in the final output space. The choice to match columns with rows is what lets devices do the local expert calculation without having to exchange intermediate results.

This organization leaves two jobs for communication. Before computation, every GPU needs the expert input representations and enough information to find the group for each expert. After computation, the GPU that supplied a representation needs all the contributions to its output. Grouping tokens for transmission and later regrouping the results make these exchanges practical. The router itself can keep assigning unequal numbers of tokens to the experts, because each device processes the same set of assignments using its portion of the weights.

MoEShard’s forward pass through an expert layer

The steps in order.

MoEShard’s forward pass through an expert layerStep 1: Route each local token to an expert1. Route each local token to an expertStep 2: Group tokens by expert and exchange counts2. Group tokens by expert and exchange countsStep 3: Send grouped inputs to the participating GPUs3. Send grouped inputs to the participating GPUsStep 4: Process each expert group with local shards4. Process each expert group with local shardsStep 5: Return partial outputs to each source GPU5. Return partial outputs to each source GPUStep 6: Add matching contributions to form expert outputs6. Add matching contributions to form expert outputs

Routing, counts, and token exchange

The pseudocode describes the forward pass from the point of view of a participating GPU. The input at this point consists of representations already processed by self-attention. The paper describes their dimensions as follows.

shape(x) = [b, s, h]

Here x is the device's input tensor, and shape gives its axis lengths in order. The batch size b counts the sequences in that input, s is the sequence length, and h is the hidden dimension of each token representation. The brackets enclose the ordered dimensions. Each token position has a representation of length h.

The router turns these positions into expert assignments. In the algorithm, G denotes the set of GPUs and E the set of experts. The tensor m_expert records the selected expert for each input token. Using those assignments, the device constructs I_exp, the inputs grouped by expert. It also builds m_sizes, a list with one count for every expert. A count can be empty in the sense that the corresponding expert group contains no tokens from that source. The assignment tensor holds identities at token level, while the count list describes the lengths of the groups that will be sent.

The grouped representations travel as a concatenated tensor. To interpret it, each recipient needs to know where the groups begin and end. For that reason, the GPUs exchange the count lists before exchanging the representations. The paper denotes the received counts by m′_sizes, indexed by the source GPU. The devices can then use the expert order and the lengths in a particular sender's list to recover the corresponding segments of its tensor. This also tells a recipient when a sender has no representations for a given expert.

The scatter sends a device's grouped inputs to the other devices. At each destination, the paper's working collection W organizes the received inputs first by source GPU and then by expert. The notation W[g][e] denotes the group of representations that came from GPU g and were routed to expert e, where g belongs to G and e belongs to E. This W is temporary token storage. The paper separately uses Wᵢ and Wₒ for the expert weight matrices.

After the scatter, all the devices have the representations for every expert assignment in the batch. This is a deliberate cost of splitting the input matrix by columns. A GPU holding some columns still needs all the coordinates of each incoming representation to calculate those columns' outputs. The input weights are divided across the devices, but the inputs to those weights are copied. The metadata exchange specifies how the copies are organized so local expert calculations can operate on the appropriate groups.

The next stage loads the shard for the relevant expert on the GPU running the computation. The source index in W specifies the origin of a group and its return destination. A separate identity, the executing device's rank, specifies which weight shard to use. Every device processes the groups from all sources. For each group it writes back the partial output from its own weight slice. This leaves results arranged by the sources that will receive them. The optimized implementation can combine groups for computation and restore that organization afterwards.

During the gather, each GPU sends its contributions to the GPU that originally supplied the corresponding representations. Each source then aggregates the partial outputs for each token, coordinate by coordinate. It has the completed expert outputs for its portion of the batch and can continue with the subsequent processing. This placement of the aggregation preserves local responsibility for the input sequences, even though the expert work for those sequences has been shared across the devices.

How the weight split works

The paper represents an expert through an input matrix and an output matrix. For the matrix analysis it writes the tokens as rows, with the sequence and batch organization represented by a count of rows. Its matrix dimensions can be written as follows.

x ∈ ℝ^(c × hᵢ)

Here x is the matrix of input representations under this view of the calculation, c counts the token rows, and hᵢ is the width of an input representation. The symbol ℝ denotes real numbers, ∈ means membership, and × separates the row and column dimensions in the exponent.

Wᵢ ∈ ℝ^(hᵢ × hₒ)

Here Wᵢ is the input weight matrix, with hᵢ rows and hₒ columns. The subscript ᵢ identifies the input side of the expert. The width hₒ describes the intermediate representation. The expression says that Wᵢ is a real matrix of the indicated shape.

Wₒ ∈ ℝ^(hₒ × hᵢ)

Here Wₒ is the output weight matrix, with hₒ rows and hᵢ columns. The subscript ₒ identifies the output side. In this matrix the intermediate coordinates index rows, and the final output coordinates index columns. The expert's output has the input representation's width.

The split follows the intermediate dimension. A device holds a block of columns of Wᵢ, which produce a subset of the intermediate coordinates, along with the matching block of rows of Wₒ, which describes how that same subset contributes to the output. The paper illustrates a case with four input-matrix columns and four output-matrix rows. GPU 0 gets the first two columns and the first two rows. GPU 1 gets the remaining columns and rows. The indices have to match because a coordinate produced by a column of the input matrix feeds the row at the corresponding position in the output matrix.

For an even split, the paper gives the divisibility condition in terms of the width of the intermediate representation.

hₒ ≡ 0 (mod |G|)

Here hₒ is the intermediate width and |G| is the number of participating GPUs, written as the size of the set G. The modular congruence means that dividing hₒ by |G| leaves remainder 0. The condition gives all participating devices equal-sized pieces along the dimension being divided.

entries in each Wᵢ shard = hᵢ · (hₒ / |G|)

Here Wᵢ is the input weight matrix, hᵢ counts its rows, and hₒ / |G| counts the columns assigned to a device. The dot means multiplication and / denotes division. The left side counts the stored matrix entries for a single expert's input shard on one GPU.

entries in each Wₒ shard = (hₒ / |G|) · hᵢ

Here Wₒ is the output weight matrix, hₒ / |G| counts its rows on the device, and hᵢ counts the columns kept in each row. The operations have the same meanings as in the input-shard expression. The equality of the entry counts reflects that the matrices use the same widths in opposite order.

The matrix expression in the paper isolates the calculation each device can perform by itself.

yᵍ = x · Wᵢᵍ · Wₒᵍ

Here g is the executing GPU's identity, marked by the superscript ᵍ. The input x contains the rows of token representations routed to the expert under discussion. The matrices Wᵢᵍ and Wₒᵍ are the corresponding input and output shards on g. The dots denote matrix multiplication, and yᵍ is that GPU's partial expert output. Its number of rows is the number of input token representations in x, and its row width is hᵢ. This notation describes the matrix decomposition of the expert computation.

y = ∑_{g ∈ G} yᵍ

Here y is the completed expert output and yᵍ is the partial output from GPU g. The symbol ∑ directs the source GPU to add the contributions across all g in the device set G. The addition operates element by element, with each term corresponding to the same tokens and output coordinates. Every intermediate coordinate contributes through the device that owns its matching column and row.

The reason a sum works is that an output coordinate receives contributions from the intermediate coordinates. Grouping those coordinates into disjoint blocks also groups their contributions. Each GPU can finish the sum over the coordinates it holds using its local output rows. The gather brings those partial sums together. In the algebra described by the paper, the result is the same expert output as when the matrices are kept together. This equivalence concerns the contribution of the shards to an assigned expert computation. The experimental router used later changes the assignments themselves.

That distinction helps explain the balancing claim. The sharding leaves the distribution of token counts across experts free to vary. Suppose an expert attracts most of the work in a layer. All the GPUs receive the tokens assigned to it, and each sees an equal-sized shard for those tokens. The increase in matrix work is shared, even though many other experts may be idle. The authors call this perfect load balancing. In the design, it describes the amount of expert computation assigned to comparable devices. It follows from holding the input groups in common and dividing the matrices evenly.

The cost of sending the inputs

There are other ways to partition the same matrices. The authors examine input rows as well as input columns because they have different communication costs. Splitting the input matrix by rows would divide the original input coordinates across devices. Each device could then work with a segment of every token row. This lowers the amount of input data sent in the scatter. It also creates intermediate values that have to be combined across devices before the next multiplication. The paper favors the arrangement that lets a device perform both multiplications using the input data received in the initial exchange.

For the column split, each device needs all the input coordinates.

input entries processed per GPU with a column split = c · hᵢ

Here c is the number of input token rows under consideration and hᵢ is their full width. The product counts the entries available as input for the local multiplication. GPU refers to a single participating device. The count is about input entries, separate from the number of stored weight entries.

input entries processed per GPU with a row split = (hᵢ · c) / |G|

Here hᵢ and c count the input width and rows, respectively, and |G| counts GPUs. The expression gives the size of an equally divided slice of the input. Multiplication accounts for all the token rows before the division divides the input coordinates evenly across devices.

The paper uses the same quantities to describe the first data transfer from each source GPU under the two splits. A sender already has its local input. The communication counts only what it sends to peers.

entries sent per GPU with a column split = c · hᵢ · (|G| − 1)

Here c · hᵢ counts the entries in the sender's full input matrix. The term |G| − 1 counts the other GPUs, excluding the sender itself. The 1 represents that device, − denotes subtraction, and multiplication by the peer count accounts for sending the complete input to each recipient.

entries sent per GPU with a row split = c · hᵢ · ((|G| − 1) / |G|)

Here c counts token rows, hᵢ is the width of each row, and |G| is the GPU count. The expression in parentheses measures the fraction of the input sent to the other devices when each receives its own slice. The 1 again excludes the sender, which keeps its slice locally. The expression counts entries in this round of data movement.

For a row split of the input weights, a device sees only some of the input coordinates. Its local first multiplication therefore contributes only part of each intermediate value. Reconstructing those intermediate values requires a pointwise sum across GPUs. A further alternative is to divide both weight matrices by columns. In that layout, the first multiplication produces distinct blocks of the intermediate representation, but a column of the output matrix uses that representation across its rows. The devices would need to concatenate their intermediate blocks before the output multiplication. Matching output rows with input columns lets the output multiplication use precisely the intermediate block already on the device.

The paper gives a concrete estimate for the input traffic. Its example uses 4 GPUs, batch size 250, sequence length 120, and hidden width 768. With 4 B per tensor entry, it describes a local input of roughly 88 MiB to send to the peers. It associates the exchange with NVLink 3.0, for which it gives an upper bidirectional bandwidth of 600 GiB/s, and estimates around 0.15 ms to send the 88 MiB quantity. The timing is a bandwidth illustration for that quantity. The measured latency of the whole system includes the actual exchange, the return of partial outputs, and the other stages of inference.

The design assumes comparable device computation and memory, sufficient collective memory for the network, and fast links among GPUs on the same server. These conditions serve different purposes. Equal-sized shards give similar work to devices with similar capabilities. Collective memory makes it possible to keep the weight slices available for inference, including the replicated components. The interconnect carries the copied inputs and returned contributions. Weight sharding and input replication thus solve different parts of the layout problem, and both influence the memory and communication requirements.

Making small expert calculations efficient

The direct implementation would work through the inputs grouped by source and expert. On each GPU, it could take one source's tokens for a given expert, load the local shard of that expert, and perform the corresponding calculation. Then it could move to the next group. The groups can be small and uneven because each sender sees its own assignments. Each separate GPU operation can require a kernel launch, the act of dispatching a calculation to the device. If a launch accompanies each small group, the fixed cost of launching can matter alongside the arithmetic.

The first optimization groups by expert across sources. On a device, inputs routed to the same expert all use the same local weight shard, regardless of where they originated. The system can concatenate them into a bigger input tensor for that expert. It processes the combined tensor and then splits the results back into their source groups for the return exchange. The counts and grouping already available to the device provide the information needed to do this.

maximum separate expert-shard computations per GPU before grouping = |E| × |G|

Here |E| counts experts and |G| counts source GPUs. The multiplication sign combines the number of possible experts and sources. The count is a maximum because a source can have an empty group for a given expert. It counts possible computation groups on each executing GPU.

maximum separate expert-shard computations per GPU after grouping = |E|

Here |E| is again the number of experts. Once each expert's inputs from different sources are combined, each expert has at most one group on the device. The amount of work in a group still depends on the assignments, but the maximum group count now depends on the expert count alone.

The second optimization addresses the remaining dependence on the number of experts. MoEShard uses the block-sparse matrix multiplication approach from MegaBlocks. After grouping by expert, the input rows for a group use that expert's weight shard. The other experts' shards are irrelevant to those rows. A sparse representation uses that structure to combine the expert work into a larger operation while retaining the different group sizes. In particular, a heavily used expert can contribute a large group and a lightly used expert a small one. The operation preserves which weights act on which inputs.

The authors describe the fused approach as making the kernel-launch count for the expert calculation independent of the expert count. This is a claim about how the work is dispatched. The arithmetic and the size of the groups still depend on which tokens go to which experts. Sparse execution has setup costs of its own. The ablation compares those costs with the benefit of combining work, using the same weight-sharding scheme in both variants.

The workloads and the routers

MoEShard is a forward-pass implementation, written in Python 3 with PyTorch. The authors make the source code available in the sacs-epfl/moe-inference repository. The paper describes no new training procedure for the expert weights. Its key intervention is to lay out the weights across the devices and change how the expert stage communicates and executes. The Switch-Base encoder supplies the architecture, and BookCorpus supplies the input text.

The layer timing uses the original Switch router. For the experiments that sweep the expert count and batch size, the authors replace it with a custom, randomized router. They use this device to fix a degree of imbalance as they vary other parts of the workload. It selects an expert for each token from a multinomial distribution, using weights that favor a specified group of experts. The assignment is synthetic. The authors explain that the router can send a token to an expert without regard to whether that expert is appropriate for its content, which makes the mechanism useful as an experimental control.

The probability rule is given up to proportionality. For the favored group the paper writes the following relationship.

pᵢ ∝ (1 + αᵣ) / |E|    for i ≤ kᵣ

Here pᵢ is the selection probability of expert i, where i is an expert index. The parameter αᵣ controls the skew and kᵣ is the count of favored experts. The symbol ≤ includes indices up to and including kᵣ. The 1 is the base weight in the numerator, + adds the skew adjustment, and |E| is the total expert count. The symbol ∝ means that the fraction specifies a relative weight, which is normalized with the weights of the other experts to obtain a probability.

pᵢ ∝ 1 / |E|    for i > kᵣ

Here pᵢ is again the selection probability, i > kᵣ places the expert outside the favored group, and |E| is the same total expert count. The base numerator 1 applies without the skew adjustment. The proportionality uses the same normalization across experts as in the favored group. The rule sets a distribution over assignments. Random draws can still produce different realized token counts across batches.

The authors use this router to generate assignments without dropping tokens at the assignment stage. The MoEShard execution path can process the full set of assignments. DeepSpeed's expert capacity still matters in the comparative measurements, where its configuration caps the work an expert can accept. It is therefore possible to control the distribution from which work is requested while the actual amount of work completed by the two engines differs. The distinction between requested and serviced assignments matters when interpreting the higher-expert-count runs.

Experiments and results

Hardware, input, and baseline

The authors evaluate the encoder of Google Switch-Base, from the family that replaces feed-forward layers in T5 with expert layers. The encoder scope serves the paper's purpose of measuring the system when it processes a body of tokens through its layers. The authors describe autoregressive decoding as a phase whose performance depends more heavily on fine-grained optimizations. Their timing follows the calculation through the encoder. T5

The text inputs come from BookCorpus, which the paper describes as containing up to 7185 unique books. The experiments time forward passes on batches from that corpus, with the same sequence length of 120 in the reported layer comparison and encoder sweeps. The corpus supplies text to tokenize and process. The main outcomes are timing measurements. The paper's analyses of routing concern how the resulting work is distributed, and it does not report a language-understanding or generation score for these runs. BookCorpus

The devices are four NVIDIA A100 GPUs on one node, each with 80 GB of memory. They communicate over NVLink and connect to a shared CPU through PCIe bridges. The CPU is an AMD EPYC 7543 32-core Processor with a maximum clock speed of 3.7 GHz, and the authors use CUDA 12.6. The GPU topology is central to the comparison because both approaches exchange activations and MoEShard explicitly sends input representations to all participants. The reported timings include the cost of operating on this hardware as a system.

DeepSpeed-MoE runs with expert parallelism enabled. Both engines replicate the non-expert components across devices. DeepSpeed also has an expert-sharding capability, which the paper characterizes as a mechanism for scaling out. The comparative baseline is the expert-parallel deployment described in the evaluation. For its router configuration, the authors set a capacity factor that increases with expert count up to a fixed ceiling.

CF = min(|E|, 50)

Here CF is the capacity factor configured for DeepSpeed, |E| is the number of experts, and min selects the smaller of the expert count and the ceiling 50. The equality describes the setting used in the comparison. The authors chose it to reduce token loss within the GPU memory available to their setup. They report memory problems when increasing it further.

The capacity choice affects what the comparison answers. With that configuration, the baseline represents a system working under a practical memory limit in the authors' environment. When the limit causes omissions, its time also reflects the reduced amount of expert work. The experiments report the latency of each engine in its configured mode. Since processing all assigned tokens is part of MoEShard's design, timing and token retention both matter when considering the significance of a speedup.

Layer latency with the original Switch router

The first timing comparison runs the original router with 128 experts, batch size 250, and sequence length 120. The authors collect forward-pass timings over 100 iterations and average them for each encoder layer they measure. The router therefore supplies assignments from the Switch computation itself. This experiment tests whether MoEShard's execution strategy is effective with the original assignments in the selected layers and configuration.

DeepSpeed's layer averages are between 177 ms and 180 ms. MoEShard's are between 41.5 ms and 43.5 ms. The authors report a speedup of up to 4.25× at layer level. The chart shows the lowest reported layer average for each engine, the lower endpoint of each range. The reported ranges do not identify whether those two minima came from the same layer.

Lowest reported mean encoder-layer latency on BookCorpus with the original Switch router

MoEShard has the lower minimum of the reported layer means under the same workload settings.

Lowest reported mean encoder-layer latency on BookCorpus with the original Switch routerDeepSpeed-MoE: 177DeepSpeed-MoE177MoEShard (this paper): 41.5MoEShard (this paper)41.5
The numbers
System or settingms
DeepSpeed-MoE177
MoEShard (this paper)41.5

The narrow ranges describe the measured layer means across this experiment. They do not describe how much latency varied from request to request, since the paper averages over iterations. The result nevertheless shows that the improvement applies across the measured layers: even the high end of the MoEShard range is below the low end of the DeepSpeed range. Because the test retains the original Switch router, it gives evidence that the latency benefit extends to assignments generated by that router in the selected setting.

Full encoder latency as expert count changes

For the full encoder measurements, TTFT means the time taken to run the encoder forward pass. In the sweep over expert counts, the batch size is fixed at 250 and the sequence length at 120. The experiment changes the number of experts from 8 to 256. The custom router favors 10% of the experts and sets its skew parameter to 0.6. These parameters describe the assignment distribution for the run. They are held in the same form as the size of the expert collection changes.

The reported speedup of MoEShard over DeepSpeed grows initially, reaches 6.45×, and then declines while staying above 2.39×. These are speedups for encoder TTFT in the sweep, and the values describe the peak and the reported lower bound on the later part of the curve. The trend illustrates how changing the number of available experts affects the two engines under the chosen assignment rule. More experts can change the sizes and number of expert groups to process, even with the number and length of input sequences held fixed. The measured speedup is a relation between the engines' times, so a change on either side can move the curve.

The authors attribute the decline after the peak to DeepSpeed's capacity policy. When the expert count exceeds 50 in this experiment, the paper reports that DeepSpeed drops tokens. This reduces the baseline's computation, while MoEShard continues to process all the assignments. The speedup remains substantial under that configuration. Its size also reflects that the systems can do different amounts of work. The paper does not give an equal-retention DeepSpeed comparison for those points that would isolate how the two engines perform when required to service the same full set of assignments.

The sweep also combines effects that matter at different levels. Which expert receives a representation determines the group that will process it. How those groups are placed determines which device bears the work in expert parallelism. With MoEShard, each equal-size shard is responsible for its part of all the groups. At the same time, expert count can change the efficiency of launching, grouping, and performing those calculations. The curve measures the combined outcome in the two implementations. The sparse-kernel ablation examines one contributor to it more directly.

Full encoder latency as batch size changes

The companion sweep holds the expert count at 128 and varies the batch size from 10 to 450. Sequence length remains 120, and the favored share and skew parameter remain 10% and 0.6. A larger batch supplies more representations to route and process together. Because the assignment probabilities retain the same skew, the absolute size of the imbalance can grow as more tokens are assigned. The authors use the sweep to see how the relative costs of the engines evolve under that change.

At batch size 10, DeepSpeed has the lower TTFT. MoEShard is faster at batch size 100. The paper describes the subsequent rise in the speedup as close to linear and reports approximately 6.24× at 450. These values are tied to the encoder timing and the synthetic routing setup. The points at 10 and 100 establish a reversal within the tested settings. They leave the precise threshold between the two outcomes unspecified.

The authors offer different explanations for the beginning and later part of the curve. At the smallest batch size, they suggest that fine-grained optimizations available in DeepSpeed could account for its advantage over the MoEShard implementation. This is their interpretation of the timing, with no experiment isolating a particular optimization. At larger batch sizes, they relate the growing advantage to the absolute gap in assignments between popular and less popular experts. That gap can give some expert-parallel devices longer queues while others wait. Spreading every expert across the devices gives MoEShard a way to distribute that larger workload.

The batch experiment makes the scope of the speedup claim concrete. A service that sends a small encoder batch through the tested systems could see a different ordering from one that can assemble a large batch. A speedup at 450 says how the full encoder pass compares in that run. The smaller-batch result shows that costs such as communication and GPU dispatch remain relevant when there is little work for the balancing scheme to distribute. The study reports forward-pass latency, so the rising speedup with batch size describes how the engines compare for each batch. It does not imply that an individual MoEShard forward pass gets shorter as the batch grows.

What the ablations show

When block-sparse execution pays for itself

The ablation takes MoEShard with MegaBlocks and compares it with a version that omits MegaBlocks. Both variants shard the experts across devices. The change under study is the block-sparse calculation that combines expert work. The authors use the same conditions as in the full encoder comparisons, so they can examine it both while changing expert count at a fixed batch size and while changing batch size at a fixed expert count. The outcome reflects the contribution of this optimization to running the sharded experts.

For the expert-count sweep, the authors find it beneficial to leave MegaBlocks out at counts below 64. Past that region, the version with MegaBlocks has an increasing advantage as the number of experts grows. The paper attributes the low-count result to the overhead of creating the kernels used by MegaBlocks. When there are fewer expert operations to combine, that overhead can cost more than the fusion saves. When there are more operations, the larger sparse calculation can replace more separate work submissions, giving the optimization a greater opportunity to help.

This observation sharpens the explanation of why MoEShard groups expert operations. The underlying partition of the matrices makes the expert computation balanced across the GPUs. The efficient execution of each device's share still depends on the shape of its work. With more experts, the device may face more distinct groups and smaller calculations. The sparse implementation gives it a way to schedule those groups together. At a smaller expert count, doing the grouped computations directly can already be efficient enough that making the sparse operation is an added cost.

In the batch-size sweep, MegaBlocks is faster throughout the reported comparison. That sweep uses 128 experts, a setting with many expert groups to handle. The paper ties the consistent advantage to that fixed count. The comparison shows what happens when batch size changes with the expert count held at a value for which the sparse implementation is useful. A low batch size in this sweep and a low expert count in the other sweep pose different problems for the kernels. The former changes how many rows are routed through the experts. The latter changes how many distinct expert groups the device may need to service.

This also explains how the two small-batch observations can coexist. DeepSpeed can be faster than MoEShard at the smallest batch in the baseline comparison. MegaBlocks can still improve MoEShard relative to its own version without that optimization at the same expert count. One comparison changes the whole inference implementation and its execution layout. The other holds the layout within MoEShard fixed and changes the kernel strategy for the expert groups. The effect of an optimization within one engine can coexist with a different ordering between engines.

What the other comparisons isolate

The paper describes two distinct changes to how the expert groups are executed. Grouping all sources' tokens for an expert removes the source GPU as a reason to launch a separate expert calculation. The MegaBlocks step then combines calculations across experts. The ablation toggles MegaBlocks and measures the resulting encoder times. The paper motivates the first grouping step by counting the maximum number of groups, without giving a separate latency ablation that removes only that step. This leaves its individual contribution to the observed timing unquantified.

The layer comparison gives another kind of evidence. Its original router produces a workload with the actual routing behavior of the tested Switch configuration. Its result establishes that the combined implementation can outperform the baseline at layer level under that router. The custom-router sweeps answer a different question by fixing the favored share and skew parameter while changing batch size or expert count. Their measurements help locate conditions in which the combined system gains or loses an advantage over DeepSpeed. Neither comparison is designed to divide the measured latency among token exchange, scheduling overhead, and matrix arithmetic.

The paper's distribution plot supports the premise that expert demand can be unequal, including substantial imbalance in a late encoder layer. The matrix decomposition explains why unequal demand across experts can coexist with equal amounts of expert computation across GPUs. The timings then show the observed performance of the implementations, including the costs of realizing that decomposition. The MegaBlocks ablation adds evidence about one of those costs by demonstrating that a balanced layout can benefit from different ways of launching the work at different expert counts.

The ablation's threshold belongs to its specific hardware, switch encoder, and routing setup. The reported comparison around 64 experts gives a boundary for the behavior that the authors observed. Its mechanism is a tradeoff between the cost of constructing the sparse operation and the work saved by combining expert computations. The experiment shows that the tradeoff changes sign over the tested range. It does not measure how that point shifts with a different interconnect, different expert dimensions, or an alternative kernel implementation.

Limitations

Limits the authors state

The authors assume that the GPUs have equivalent computational capacity and memory, that their combined memory can accommodate the network, and that they are connected by fast links on a single server. Those assumptions are part of the design setting. Giving equal slices to devices with equivalent capabilities keeps their assigned expert arithmetic in proportion to their resources. A slower device given the same share could still delay the gather. The single-server topology also makes it feasible for each device to receive the inputs from its peers. The evaluation establishes performance on the NVLink-connected node described in the paper.

The formulation assumes that the shards can be divided evenly among devices, with the illustrated matrix layout dividing the intermediate width equally. The authors say that leftover shards can be handled and leave that case outside their treatment. The presented argument for equal expert work thus uses equal shard sizes. An uneven split would require a placement or sizing choice and a corresponding analysis of the residual imbalance.

The authors restrict the measurements to the Switch-Base encoder on BookCorpus. In particular, their TTFT definition covers an encoder forward pass. The paper gives no timing for autoregressive generation, which the authors describe as a phase where other kinds of optimization become important. Encoder timing establishes how quickly the tested engine completes that part of the inference computation. A first generated token would additionally depend on work beyond that encoder pass.

The authors explicitly characterize their custom router as unsuitable for production. It assigns experts by sampling the chosen distribution, so the expert decisions need not fit the input. Its value in the experiment is that it creates a chosen form of skew and allows the timing study to hold that form fixed. The original-router run provides evidence for one configuration that uses Switch's own assignments. Most of the sweep evidence and the MegaBlocks comparison concern the synthetic assignment policy.

The paper also acknowledges the memory and communication overhead from making the input representations available on all GPUs. The bandwidth example gives an idea of the size of the scatter cost in the intended hardware setting. It is an estimate from an input quantity and a stated bandwidth. The end-to-end experiment measures the implementation on one server topology, leaving the behavior on slower links or across servers untested.

Limits of the evidence

The work balance claim has a narrower meaning than an end-to-end latency guarantee. Every device receives all expert groups and has the same dimensions of weights to apply to them. This supports equal expert arithmetic under the equal-shard assumptions. The complete forward pass also involves local attention, routing, communication, kernel setup, and aggregation. Timings may vary for reasons in any of those stages. The results show a net latency gain in many settings and a loss at the smallest tested batch. Equal division of the expert calculation is compatible with both outcomes.

DeepSpeed's capacity setting also qualifies the comparisons. The authors chose a setting that reduces dropping while avoiding the memory problems they encountered with higher values. That is a defensible way to compare feasible configurations on their hardware, but it makes expert workload a moving part of the interpretation. At higher expert counts, the paper explains part of the timing trend through tokens dropped by DeepSpeed. Without per-setting token retention and an equal-retention counterfactual, the reported latency ratios give limited information about how the systems would compare at an identical amount of completed expert work.

The argument for numerical and task behavior has different parts. The matrix analysis shows why adding a complete set of partial results gives the expert output for its input. Dropless execution means that every assigned representation can contribute an expert result. The results do not include a task score or a measurement of output agreement between inference implementations. In particular, the custom router supplies assignments for performance testing. Processing them all demonstrates retention and allows the timing experiment to proceed, while their usefulness for language work is outside what the sweep measures.

The chosen router parameters also constrain the relationship between the mechanism and the measured effect. The authors' reasoning about sharding applies to arbitrary skew in the token counts as long as devices receive the same groups and operate on equal slices. The full-encoder sweeps hold the skew degree and favored share fixed while varying expert count or batch size. The resulting speedups quantify performance for those sweeps. They do not map the transition from nearly even expert demand to strong concentration, or measure how performance changes as the identities of popular experts shift over a live workload.

There is a similar distinction between the ability to distribute memory and the evidence about scaling. Each device holds a fraction of each expert's weights, and the forward pass copies token representations across devices. Adding devices could shrink the weight slice per device while increasing the number of peers receiving tokens from each source. The reported experiments use four GPUs throughout. A device-count sweep would be needed to characterize where the storage and arithmetic benefits outweigh the communication cost as the deployment grows. The paper supplies a mechanism for the single-server setting and data at the device count it tested.

Finally, the reported measures emphasize means and forward-pass speedups. The layer timings are averages over the stated iterations. The full encoder results describe the sweep trends and important points on those curves. These measures support an account of how the tested configurations compare under the workload, with limited evidence about variability, the slowest requests, or a serving system's latency once requests must wait to form a batch. The experiment also supplies no energy measurement. Any claim about energy or serving behavior would need an outcome beyond the forward-pass timings reported here.

What came after

There are no documented follow-up studies to discuss. The evidence about this design therefore comes from MoEShard's own encoder experiments and ablation. Those establish how sharding all experts across the same devices affected latency in the tested single-server setting, including where the sparse implementation helped and where the baseline remained faster.

Cite

Cite as Oana Balmau, Anne-Marie Kermarrec, Rafael Pires, Andre Loureiro Espirito Santo, Martijn de Vos and Milos Vujasinovic. 2025. Accelerating MoE Model Inference with Expert Sharding. arXiv:2503.08467.

The paper itself, not this page. BibTeX from the library's record of the work. DOI 10.1145/3721146.3721938 · arXiv 2503.08467

@misc{balmau2025accelerating,
  title = {{Accelerating MoE Model Inference with Expert Sharding}},
  author = {Oana Balmau, Anne-Marie Kermarrec, Rafael Pires, Andre Loureiro Espirito Santo, Martijn {de Vos} and Milos Vujasinovic},
  year = {2025},
  doi = {10.1145/3721146.3721938},
  eprint = {2503.08467},
  archivePrefix = {arXiv},
  url = {https://doi.org/10.1145/3721146.3721938}
}

↑ back to top

This page in Markdown https://md.research.elamur.ai/free/en/papers/balmau-2025-accelerating-moe-model-inference-expert/