Klotski: Efficient Mixture-of-Expert Inference via Expert-Aware Multi-Batch Pipeline
Paper · 2025 · Zhiyuan Fang, Yuegui Huang, Zicong Hong et al.
Summary
A mixture-of-experts network can use only a fraction of its weights for each token and still be too large to fit on a single GPU. The weights that sit idle for one token may be needed for the next. Keeping those weights in host memory or on disk makes inference possible on a smaller machine, but it can leave the GPU waiting for transfers. Klotski addresses that wait. It changes when weights are moved and in what order the GPU runs work that is ready to execute.
The authors start from a technique used for dense networks. Keep a layer’s weights on the GPU long enough to process several batches, and use that time to load what the next layer needs. In a mixture of experts, bringing more batches together can also bring more experts into use. Klotski therefore loads the routing gate and a small set of predicted high-demand experts ahead of time. Once the gate has made its actual selections, the engine brings in any further experts that are needed. It groups work by expert across batches and runs the prefetched, heavily used experts first, giving the remaining weights more time to arrive.
A planner measures computation and transfer times on the machine where the engine will run. It uses those measurements to choose how many batches to process together, within the available memory. A separate predictor estimates expert demand from the routes tokens took through preceding layers. Its estimates affect which transfers start early. The gate still determines which experts process each token. The engine can also place different kinds of data in GPU memory, host memory, or on disk, including the attention state that grows as more sequences are processed together.
On text sampled from WikiText-103, the authors compare Klotski with offloading systems using Mixtral-8×7B and Mixtral-8×22B. The largest throughput gain they report is 85.12× over Hugging Face Accelerate. The maximum gain over the more closely related FlexGen comparison is 2.23×. On a single NVIDIA 3090, the paper reports over 1.3 token/s for Mixtral-8×22B. In the ablations, sharing weights across batches accounts for the largest increase, while selective prefetching and reordering expert work improve throughput further. A detailed timing trace also shows where waiting persists. Larger groups can hide more expert transfers, but the additional attention state can create stalls of its own.
Deep dive: Klotski: Efficient Mixture-of-Expert Inference via Expert-Aware Multi-Batch Pipeline
Klotski speeds up mixture-of-experts inference on memory-limited GPUs by sharing weights across batches and scheduling expert transfers around computation. · about 36 minutes to read
The problem and its context
Sparse computation still requires access to the weights
A feed-forward network applies learned transformations to a token’s representation. In a dense Transformer block, tokens passing through the same feed-forward layer can all use the same set of weights. A mixture-of-experts block gives that part of the network several feed-forward networks, called experts, and uses a gate to select which ones each token will use. The block still includes attention and normalization. The scheduling issue arises because the attention operation has a known set of weights, whereas the required expert weights depend on the gate’s decisions. The paper traces the introduction of this arrangement into Transformers to GShard.
The gate scores the experts for each token. A softmax turns those scores into routing weights, and the gate activates the top-ranked subset. A token’s output from the expert layer is a weighted combination of the selected experts’ outputs. That arrangement lets a network have a large pool of parameters while using a smaller portion of it for any given token. In the paper’s account, this is one reason the architecture is attractive for scaling. The whole pool still needs a place to live, and a token that takes an uncommon route still needs its chosen weights.
The paper uses Switch Transformers to illustrate how concentrated this storage requirement can be. It cites an estimate that experts can account for up to 99% of the parameters in that architecture. That figure describes where parameters are stored, rather than the fraction used for a particular token. The authors also give DeepSeek-V2 as an example of the hardware demands of a large network. Their example places its 236 billion parameters against the capacity of H100 GPUs with 80GB each and cites a requirement of at least seven such GPUs for inference. DeepSeek-V2
The inference procedure repeats this problem over the course of generating text. During prefill, the network processes a prompt together and establishes the state it will use to continue the sequence. That prompt can send many tokens down different expert routes. During decoding, the network generates successive tokens from what came before. A single sequence presents less new work at a decoding step, but a group of sequences can still activate a broad set of experts. In either phase, the memory system must supply the weights for the routes the gate actually chooses.
Offloading trades memory capacity for transfer time
Offloading makes a network fit by keeping some tensors outside GPU memory. A tensor is an array of values, such as a set of weights or an intermediate result. The paper describes a storage hierarchy with GPU memory, or VRAM, at the compute device, host memory, or DRAM, on the CPU side, and disk as a further source of capacity. With enough space in that hierarchy, only the tensors for current or upcoming work need to occupy VRAM. A transfer into VRAM then becomes part of the time needed to execute the affected operation.
The paper locates inference offloading in a line of work that used swapping to reduce GPU memory requirements during training. ZeRO-Offload applied offloading to Transformer training, and ZeRO-Infinity added disk to the available storage. The ZeRO-Inference component of DeepSpeed-Inference brought this approach to running a trained network. The concern in Klotski is the runtime consequence of that choice. Moving a large tensor across the hierarchy can take longer than the work the GPU performs with it. ZeRO-Offload · DeepSpeed-Inference
Earlier inference systems looked for ways to make both the GPU and the storage links do useful work at the same time. FlexGen planned offloaded execution with weight reuse across batches. HeteGen used CPU and GPU computation together to reduce the need for some parameter transfers. STI used sharding and pipeline planning to make better use of computation and transfer resources. The paper presents these as designs whose scheduling assumptions are easier to satisfy when each layer’s weight requirements are known in advance. FlexGen
Several earlier systems explicitly addressed routed experts. Mixtral-offloading used quantization and a cache that could replace the least recently used weights. MoE-Infinity used traces of expert activation to guide caching and prefetching. SiDA trained a predictor for expert demand before inference, with a prefetch accuracy reported in the paper’s discussion as over 90%. Fiddler made another choice possible by using the CPU for some expert computations, avoiding the trip to the GPU for the affected weights. These approaches target how often transfers occur, how early they can start, or where the corresponding computation happens.
The paper also distinguishes its objective from earlier work on improving mixture-of-experts training and inference more broadly. DeepSpeed-MoE introduced Pyramid-Residual MoE and used staged distillation to produce a Mixture-of-Students. Lina scheduled communication during training and used the popularity of experts to balance inference workloads. Klotski draws on the observation that experts differ in popularity and uses it to address waiting in an offloaded execution schedule on memory-constrained hardware. DeepSpeed-MoE
The GPU can wait at two different points
The authors call idle gaps in the execution timeline bubbles. An inter-layer bubble can occur when attention finishes and the next part of the block is still loading. In the paper’s motivating example, Mixtral-8×7B on an NVIDIA 3090 with a batch size of 16 takes about 2.6 ms on average for an attention computation, while the transfer of a single expert takes about 21 ms. Starting the transfer as attention begins gives it a head start. The difference in durations explains why that head start may be insufficient even for an expert that was correctly predicted.
An intra-layer bubble occurs after work in the expert layer has already begun. The GPU can finish one expert’s work while another required expert is still in transit. In the same architecture, the paper says processing a token with a single expert takes less than 1 ms. The two motivating timings describe different amounts of work, one an attention operation for a batch and the other an expert operation for a token. Their purpose is to show why the schedule can run out of useful computation at both the boundary of the expert layer and within it.
A dense layer offers a straightforward way to extend the overlap. Load its weights once, use them on several successive batches, and start moving the next layer’s weights during that longer stretch of computation. For experts, the corresponding stretch of work is harder to arrange. Putting more requests together can give an already loaded expert more tokens to process. It can also introduce tokens routed to weights that none of the earlier batches would have needed. The useful quantity is how much additional computation the schedule can obtain for each additional transfer it puts on the critical path.
A predictor answers which weights are likely to matter. The pipeline must also answer when those weights can arrive and what can run while they are on the way. A prediction can be accurate while the GPU still waits, since an accurately predicted transfer can last longer than the work available to cover it. Conversely, completing a transfer early can be valuable even when the predicted expert turns out to be only moderately busy. Klotski’s design addresses these timing and demand questions together.
The method, step by step
Form a group and share its weights
A batch holds sequences the engine processes together. Klotski introduces another unit, the batch group, by scheduling several such batches through the same layer before advancing. Batch size controls how many sequences are in each constituent batch. Group size controls how many batches get to reuse the weights while they are resident. During decoding, the dependency between successive tokens of each sequence remains in place. The engine changes the order in which work from different batches reaches a given layer.
The scheduling idea comes from the zig-zag block ordering used by FlexGen. Imagine a grid with a row for each batch and successive layer operations laid out across the columns. Completing everything in a row before beginning another gives the weights little opportunity to serve a second batch while still in memory. Visiting several rows at a column gives the current weights more work to do before eviction. While the GPU is busy with those rows, the transfer stream can make progress on the next column. Klotski keeps that reuse for non-expert work and changes the layout of expert work within the group. FlexGen
The first version of the schedule described in the paper simply overlaps next-layer loading with one batch’s current computation. The next version extends that computation across batches. The difficulty with that second version is the size and composition of the mixture-of-experts layer. Loading it as a unit can delay the gate, even though the gate needs only its own weights to determine which experts will take part. It can also transfer feed-forward weights that no token in the group will use.
Klotski therefore treats the gate and the experts as separate scheduling operations. While attention is running for the group, it starts loading the gate and selected expert weights. The gate then runs for the constituent batches. Its outputs tell the engine which further experts are required, so the engine can start transfers for missing weights as it learns about them. Once expert computation begins, work is grouped by expert across the batch group. The result is a schedule in which the units of expert computation correspond to the units in which expert weights arrive.
How Klotski schedules an offloaded MoE block
The steps in order.
Start with experts that have both weights and work
The paper calls experts with relatively heavy token demand hot. Cold experts receive less work or are selected less frequently. The distinction applies to demand at a particular layer and can change with the input. The authors examine activation heatmaps for Mixtral-8×7B and the decoder portions of Switch Transformers. In Mixtral-8×7B, which selects experts with a top-2 gate, experts 1 and 3 together account for 53.7% of the selections reported for layer 14. The example is evidence that some layers offer substantial work on a small set of weights. It also explains why the authors examine popularity by layer.
The two scheduling benefits of a hot expert are related. Prefetching it makes its weights available early. Grouping all its routed tokens gives the GPU a longer stretch of useful work once those weights are available. If expert work remained in the original order of the batches, a batch could encounter an expert that was still loading even though the GPU had ready work for a prefetched expert from another batch. The paper illustrates this with expert 2 ready to run and expert 1 still in transit. Two pieces of work for expert 2 can run together before the GPU needs the weights for expert 1.
After the prefetched experts run, the remaining experts execute in transfer order. An expert can leave VRAM when its work for the group is finished, even while other experts from the same layer are still running. This shortens the time its weights occupy GPU memory. It matters because running the pipeline also requires room for intermediate states and for data arriving for subsequent work. The memory demand depends on which tensors are alive together, as well as on which tensors are stored somewhere in the hierarchy.
Actual routing is preserved throughout the schedule. The prediction says which weights to stage. The gate says which expert receives each token and how its result contributes to the token’s output. A prediction error can therefore make a transfer unnecessary or make useful weights arrive later. It does not substitute a different expert for the one chosen by the gate. That distinction lets the engine use a relatively small prediction table while still executing the network’s routing decisions.
Decide which transfers to start during attention
The paper first compares two idealized timing conditions. The first asks how long the group would have to spend in attention to hide loading the entire next mixture-of-experts layer.
n × t_c,A ≥ t_I/O,MoE
Here n is the number of batches in the group. The t terms are durations. The subscript c,A identifies attention computation for a single batch, and I/O,MoE identifies transfer of the entire mixture-of-experts layer. The multiplication gives the time spent computing attention across the group. The inequality says that the available computation window must be at least as long as the transfer it is meant to conceal.
This condition can call for a large group. Every additional batch also needs a share of the key-value cache, or KV cache, which stores attention state for use in subsequent generation steps. In addition, a transfer of the complete expert layer includes all experts, even if some see no tokens. The authors next express the timing condition for prefetching the gate and a limited set of experts.
n × t_c,A ≥ t_I/O,G + K × t_I/O,E
Here n and t_c,A again give the group’s attention computation time. The term t_I/O,G is the transfer duration for the gate, and t_I/O,E is the transfer duration for a single expert. K counts the experts selected for prefetching. The right side adds the gate’s transfer time to the time budgeted for those expert transfers. In the default policy, K equals k, the number of experts that the top-k gate selects for each token, usually 1 or 2 in the account given by the authors. K applies to the prefetch decision for the group, while k applies to the actual routing decision for each token.
This second condition describes completing the whole prefetch set during attention. The more detailed planner gives the gate and the experts separate deadlines. The gate needs to be ready as soon as its computations begin, while a prefetched expert needs to be ready when its own work is due. During gate computation, Klotski uses the gate’s results to initiate transfers for selected experts whose weights are missing. Those transfers respond to observed demand. The earlier ones, launched during attention, respond to a forecast.
Use the routes that tokens have already taken
The forecast depends on the token’s previous expert selections. On a first run, the engine can build an expert correlation table during warm-up. It records how often a given earlier activation path was followed by each expert selection at the layer being predicted. The path length determines how much preceding routing history the lookup incorporates. This is a statistical data collection step on an already trained network. The procedure records what the gate does during inference and leaves its parameters in place.
At runtime, Klotski looks up the current tendency for each token from the path that token has taken. It aggregates those tendencies across the group and prefetches the experts with the largest combined demand estimates. Aggregation matters because a transfer is shared. The engine is looking for a set of weights likely to do useful work for the group, even when individual tokens route differently. The actual choices observed during inference are also used to update the table. The updates stay in memory rather than being written back to the file, so an adaptation to one task does not become the persisted starting point for another.
To populate the starting table, the implementation draws random samples from WikiText-2 and logs the routing decisions made during inference using batches of 8 and sequences of length 512. The authors store the counts in JSON. They use a small batch for this run to keep the initial counts from overwhelming updates made later. They also set the activation path length to 1. The figure illustrating the lookup uses a gate that selects the top-1 expert, with four experts per layer and a path length of 1. Once an earlier expert is known, the table gives the observed tendencies for the next layer. Pointer Sentinel Mixture Models
A longer path distinguishes more histories. It also requires a larger table and more complex lookups. The authors judge a short history sufficient for the role assigned to the predictor, because group computation offers another way to cover transfers when the forecast falls short. For non-expert tensors whose use follows the layer order, Klotski prefetches from that known order. Their transfers have no need for a routing forecast.
Place tensors according to when they may be needed
At deployment, the engine determines how much GPU memory, host memory, and disk space is available. It uses VRAM for current operations and prefetched tensors. If space remains, tensors that would otherwise be repeatedly transferred can stay there. Placement can vary both by tensor type and by layer. This means the engine can make one choice for expert weights, another for attention weights, and others for activations or the KV cache. It can also store different portions of the same kind of tensor at different levels of the hierarchy.
Host memory is valuable for expert weights because the gate can issue a request with little advance notice. An expert needed unexpectedly can generally be supplied more promptly from DRAM than from disk in the hierarchy the authors describe. Klotski therefore gives experts priority when assigning host memory. When there is sufficient host memory, the implementation can use pinned memory to speed communication between the CPU and GPU. Pinning is a transfer-related choice about the host memory used to hold tensors.
Where disk is required, the paper describes a moving window of layers staged in DRAM. Its two look-ahead positions are as follows.
i + 1
Here i is the layer currently being processed and 1 is the advance to the next layer. The GPU prefetches tensors for that next layer from host memory.
i + L
Here i again identifies the layer in progress and L is the fixed number of layers managed in the host-memory window. The CPU stages tensors for the indicated future layer from disk while removing tensors for the current layer. The host can refill its window while the GPU receives the tensors it will need sooner, making disk access less likely to sit directly in front of a GPU operation.
These placement decisions change the timing problem the planner sees. Weights already resident on the GPU need no corresponding copy from host memory. Weights staged in the host are closer to the GPU than tensors that have yet to come off disk. The cache and activation placement also determines how much space remains to run additional batches. A schedule that is feasible on one machine may therefore run out of room or encounter a different transfer delay on another.
Choose a group size from measured timings
The planner’s objective is to finish the workload with as little exposed waiting as possible. The paper describes the objective as a sum of time spent computing and time spent in bubbles.
minimize T = T_c + T_b
T is total completion time, T_c is total computation time, and T_b is aggregate time spent in bubbles. The plus sign adds the two parts of the paper’s accounting. Minimizing T involves reducing the transfer time that remains visible as waiting, since the computation time is heavily influenced by the workload and hardware.
The objective is subject to capacity constraints. The paper writes one for the overall storage budget and another for peak GPU occupancy.
M_usage < M_GPU + M_CPU + M_disk
M_usage is the total storage demand considered in the plan. M_GPU, M_CPU, and M_disk are capacities available in GPU memory, CPU memory, and disk storage. The inequality requires the demand to be below their combined capacity.
M_peak,GPU < M_GPU
M_peak,GPU is peak GPU memory use during the schedule, and M_GPU is GPU memory capacity. This constraint covers the moment when GPU memory is most heavily occupied. The total storage budget alone cannot guarantee that weights, state, and prefetched data will fit where the GPU needs them.
The authors consider the size of each batch and how many batches go into the group to be separate decisions. Batch sizes are usually multiples of 4 in their description. Group size is the quantity solved for using overlap constraints. With a small group, there may be too little computation to hide the next transfer. Increasing the group gives resident weights more work, but also brings more attention state into the schedule. The planner aims to find the first group size at which the major weight transfers have enough time to finish.
The paper identifies successive deadlines through a mixture-of-experts block. At each one, the time available on the computation side must cover the cumulative transfers due by that point. The first deadline is the beginning of gate computation.
n × t_c,A ≥ t_I/O,G
n is the group size in batches, t_c,A is attention computation time per batch, and t_I/O,G is gate transfer time. The gate’s weights must arrive in time for routing. At this deadline, the planner compares only the gate transfer with the group’s attention window.
The second deadline is the start of hot-expert computation.
n × (t_c,A + t_c,G) ≥ t_I/O,G + K × t_I/O,E
n is the number of batches. t_c,A and t_c,G are the attention and gate computation times per batch. t_I/O,G and t_I/O,E are the times to transfer the gate and a single expert. K is the number of hot experts prefetched for the group. The addition on the left includes the gate work in the time budget. On the right, the budget includes the gate and the chosen experts’ weights. This is why the planner can give the expert transfers a later deadline than the gate transfer itself.
The third deadline is the beginning of cold-expert work.
n × (t_c,A + t_c,G) + t_c,hot-E ≥ t_I/O,G + (K + 1) × t_I/O,E
Here n is the number of batches, and t_c,A and t_c,G are the attention and gate durations per batch. t_c,hot-E is the time to compute the hot experts’ work across the group. t_I/O,G is the gate transfer time, t_I/O,E is the single-expert transfer time, and K is the number of experts selected for prefetching. The added 1 counts the first cold expert. This deadline captures the benefit of running the hot experts first. Their computation gives the initial cold transfer another interval in which to finish.
The final deadline is the start of the next attention computation.
n × (t_c,A + t_c,G) + t_c,hot-E + ∑ᵢ∈Q t_c,Eᵢ
≥ t_I/O,G + (K + len(Q)) × t_I/O,E + t_I/O,A
n again counts batches, and t_c,A and t_c,G denote per-batch attention and gate computation. t_c,hot-E is aggregate hot-expert computation for the group. Q is the queue of activated experts remaining after the prefetched set, i identifies an expert in that queue, and t_c,Eᵢ is its computation time. The sum, indicated by ∑, adds those times for every i belonging to Q, as indicated by ∈. On the transfer side, t_I/O,G, t_I/O,E, and t_I/O,A are the gate, single-expert, and attention-weight transfer times. K counts the prefetched hot experts, and len(Q) counts the remaining experts. The inequality includes delivery of the following attention weights before the schedule advances to that operation.
Klotski first measures the relevant computation and transfer durations using the tensor shapes, data types, and hardware at hand. It caches the measurements locally. The authors obtain estimates for the queue lengths from statistics because the gate’s actual selections vary by layer and input. The constraints then supply a lower bound for group size.
n ≥ x
n is the number of batches in the group, and x is the lower bound obtained from the timing constraints. The solve can return a bound between admissible integer group sizes.
n = ⌈x⌉
n is the planner’s chosen group size, x is the computed bound, and the ceiling brackets indicate the smallest integer at least as large as x. The paper favors the smallest group that meets the timing requirements. Once most transfer waiting has been covered, later increases offer a smaller throughput benefit while continuing to enlarge the cache. An excessive calculated group size can require a manual adjustment.
These rules describe a schedule built from measurements and estimated expert demand. If all tokens select prefetched experts, the queue of additional expert transfers disappears and the problem is easier. If the tokens all miss the forecast and require cold experts, the hot-expert computation interval can disappear, leaving less work to cover those transfers. The timing trace later in the paper illustrates why a group size derived this way is a practical planning value, with room for adjustment when actual memory or timing is different.
Execute transfers and computation asynchronously
The scheduler traverses generation positions and successive layer operations. The paper’s algorithm uses i for the token position, j for the layer, and k for the batch index. Its state includes the hidden representations and the attention cache. Non-expert operations visit the batches in sequence and can arrange to bring in the next batch’s state while the current batch runs. The expert operation instead assembles the tokens routed to each expert across the group. This allows its weights to serve all of that expert’s work before the execution moves on.
The implementation separates transfer work into CUDA streams. One stream prefetches weights, another loads expert weights in response to gate results, another fetches the KV cache, and the last stores the updated cache. These streams operate asynchronously. When a computation needs particular data, the engine synchronizes with the corresponding stream so the data are ready. Splitting the work this way lets a transfer begin before the operation that consumes it reaches that synchronization point.
Klotski is implemented in Python on PyTorch and Hugging Face Transformers. The authors build the multi-batch pipeline on top of FlexGen. The implementation therefore inherits a way of organizing weight reuse and adds the separation of gate and expert transfers, the grouping of expert work, and the prediction and placement logic needed for routed layers. PyTorch · Hugging Face Transformers
Optionally reduce the amount of data moved
Quantization represents weights with fewer bits for storage and transfer. Klotski includes Half-Quadratic Quantization, or HQQ, as an option. According to earlier work cited in the paper, expert weights can be reduced to 3-bit precision without further training or any calibration data. The paper’s preset assigns 4-bit precision to expert and attention tensors alike, setting the group size to 64 and the zero scale group size to 128. Grouping here refers to quantization parameters for weights. It is separate from the batch grouping used to schedule inference.
The paper gives the quantization operation as a scale, offset, and rounding step.
Q_z,s(W) = W_q = round(W / s + z)
W denotes the original weights, and W_q denotes the resulting quantized values. Q_z,s is quantization using zero point z and scale s. Dividing by s expresses the weight in scale units, adding z applies the zero point, and round maps the result to a discrete value. The equalities give two names for the result of that operation.
The engine dequantizes the tensor before computation.
Q⁻¹_z,s(W_q) = s × (W_q − z)
Q⁻¹_z,s denotes the reconstruction operation with zero point z and scale s. W_q is the stored quantized value. Subtraction removes the zero-point offset and multiplication restores the original scale. The reconstructed value can be represented in the original computation precision. Rounding during quantization means its value can still differ from the original weight.
The paper motivates the choice of scale and zero point with a reconstruction objective. Its expression minimizes the discrepancy between the original weights and the weights obtained after both operations.
argmin over z, s of discrepancy(W, Q⁻¹_z,s(Q_z,s(W)))
argmin denotes the parameter choices that minimize the objective. The variables being chosen are the zero point z and the scale s. W is the original weight tensor. Q_z,s(W) is the quantized tensor, and applying Q⁻¹_z,s to it gives the reconstruction. discrepancy denotes the reconstruction error the expression seeks to reduce. The paper gives the objective in terms of the difference between the two tensors, without specifying a norm in that expression.
The other optional compression technique reduces the attention state itself. It adopts the StreamingLLM attention scheme, which keeps early sink tokens and nearby tokens in the attention window. With less retained state, a group needs less cache space, and the engine has less cache data to transfer when that state is offloaded. Weight quantization and sparse attention thus address different parts of the schedule. One shortens some parameter transfers. The other changes the size and movement of data that accumulate as the engine runs several batches. StreamingLLM
Experiments and results
Hardware, workload, and measures
The experiments use two hardware environments. Environment 1 has an NVIDIA RTX 3090 with 24 GB of GPU memory and an Intel Xeon Gold 5318Y host with 256 GB of memory. It has a 2T SSD, a PCIe connection listed as 4.0 x 16, and disk reads listed at 1 GB/s. Environment 2 has an NVIDIA H800 with 80 GB of GPU memory and an Intel Xeon Platinum 8470 host with 800GB of memory. Its SSD is listed as 1T and its PCIe connection as 5.0 x 16. The authors omit a disk read measurement for that environment because there is enough host memory for their evaluation there.
The checkpoints are Mixtral-8×7B, with 46.7B parameters, and Mixtral-8×22B, with 141B parameters, both in bfloat16 for the study’s unquantized configurations. Environment 1 tests both. Environment 2 tests Mixtral-8×22B because the authors do not regard that environment as memory-constrained for Mixtral-8×7B. The evaluation therefore contains cases where offloading is necessary for the paper’s target setting, with different capacity and transfer conditions across the two machines.
The evaluation inputs are sampled at random from WikiText-103. This is a separate dataset from WikiText-2, which the implementation uses to initialize expert correlations. The main workload uses batch sizes from 4 to 64, an input length of 512, and an output length of 32. The paper reports averages across multiple trials. It defines throughput as the generated tokens divided by combined prefill and decoding time, so the cost of processing the original prompt enters the denominator.
The end-to-end throughput measure describes how fast a configuration finishes the workload in aggregate. The paper also compares throughput with elapsed completion time, measures GPU memory during prefill, and examines the timing of individual transfers and computations. Those measurements operate at different scales. The throughput curves show the effect the user of the engine would see on the sampled workload. A trace of one block can then identify whether a particular gain came from ready weights at the layer boundary or from a better order within the expert layer.
The baseline comparison
Hugging Face Accelerate provides a device map that assigns layers to different devices and allows weights to be offloaded. DeepSpeed-FastGen is the version of the DeepSpeed inference line the authors use because it supports Mixtral. Those systems give comparisons with broadly applicable inference and offloading facilities. FlexGen provides the closest comparison to the basic multi-batch scheduling idea. Its original implementation supports the OPT-style dense architecture, so the authors adapt it to Mixtral while retaining its principal strategies. OPT
The expert-oriented baselines are Fiddler and MoE-Infinity. Fiddler can run selected work on the CPU, using host computation to avoid moving the corresponding weights. MoE-Infinity uses activation-aware prefetching and caching. Compared with these baselines, Klotski’s additional lever is the amount and ordering of GPU work available while a transfer proceeds. The paper uses the comparison to test the combined engine. It does not attribute the full difference against either baseline to a single feature.
The configuration for the main end-to-end comparison uses a group size of n = 15 from the authors’ group-size sweep where applicable. This is a choice made to show a stronger result than the default calculated group size. For Mixtral-8×22B in Environment 1, the authors set n = 10 because the calculated value leads to an out-of-memory error. FlexGen uses the same group size as Klotski in the comparison. These settings matter when interpreting the reported maxima. They show the throughput of the configurations used for the benchmark, including a manual adjustment on the machine with the tighter memory limit.
Throughput and latency
Across the tested scenarios, the authors report maximum throughput gains of 85.12× over Accelerate and 15.45× over FastGen. The maximum over FlexGen is 2.23×. For MoE-Infinity and Fiddler, the maxima are 19.06× and 9.53×, respectively. These are separate maxima from comparisons on the WikiText-103 evaluation. Each is a statement about the largest observed gain against the named baseline across the scenarios, instead of a common speedup expected at every batch size or on both machines.
On Mixtral-8×7B, the paper describes Accelerate and FastGen becoming more competitive as the batch size grows. More computation for each transfer reduces the mismatch that dominates at smaller settings. On Mixtral-8×22B, heavier weight transfers leave a wider gap, and the systems that share weights across batches have a larger advantage. FlexGen already exploits that reuse, but the authors’ adaptation prefetches the whole expert layer. Klotski schedules fewer weights in advance and uses the order of the expert workloads to give later transfers time to finish.
The paper also reports a comparison beyond its main batch-size range. At a batch size of 128, it gives Klotski a 15% throughput improvement over FlexGen. The authors regard this as evidence that the advantage can remain even once the individual batches become large. The result does not imply that the gap will keep growing with batch size. A larger batch gives several systems more computation to amortize a weight transfer, and the paper’s own group-size curves show the gains eventually leveling out.
Fiddler and MoE-Infinity obtain strong throughput in Environment 1, where avoiding a GPU transfer or making better use of a prefetched expert can save a substantial wait. The authors explain that the larger GPU memory and faster I/O of Environment 2 reduce the relative value of these advantages. On the single 3090 with Mixtral-8×22B, the paper reports a maximum batch size of 16 for both systems. Their offloading support covers experts, leaving the growing KV cache as a constraint. Klotski can offload additional categories of tensors. In the same hardware setting, the paper reports throughput of over 1.3 token/s for Mixtral-8×22B with Klotski.
The throughput–latency plots ask how much throughput the systems can deliver under a common time budget. On the right-hand comparison in the paper’s figure, Klotski delivers more than three times the throughput of FlexGen at the latency point the authors discuss. This is a point on the tradeoff curve. The benefit they attribute to quantization is that shorter transfers can be covered with fewer grouped batches, which can move the curve even when the best observed throughput changes only slightly.
The throughput values below come from the paper’s configuration comparison for the larger checkpoint on Environment 2. They show how close the full pipeline and its quantized variant are in that comparison.
Full Klotski with and without quantization on WikiText-103, Mixtral-8×22B end-to-end throughput in Environment 2
The quantized configuration is slightly ahead of the unquantized pipeline.
The numbers
| System or setting | token/s |
|---|---|
| Klotski | 52.85 |
| Klotski with quantization (this paper) | 53.125 |
GPU memory during prefill
The memory experiment contrasts the memory needed for inference with the capacity available on the GPU and with the occupancy under different placements. When all tensors eligible for the illustrated offloading configuration are moved out of VRAM, the authors report a reduction in GPU memory use of over 94.1%. This shows how little needs to remain resident to make progress through the schedule. The low occupancy also leaves spare capacity that could hold often needed tensors.
The more performance-oriented placement in the same discussion uses some of that capacity to reduce transfers. For Mixtral-8×22B on a single H800, the authors report a memory reduction of 74.5% and throughput of roughly 40 tokens/s. This result pairs a memory reduction with a throughput observation for that placement. It describes a different use of the hardware from the placement intended to demonstrate the smallest footprint. The paper plots prefill memory over successive computation steps and describes the decoding pattern as similar.
Taken together, the memory and throughput results show why the engine exposes placement choices. Filling less VRAM can let the workload fit, while retaining some tensors there can improve speed. A placement that minimizes occupancy has a different transfer schedule from one that spends more VRAM to keep weights or state close to computation. That difference is part of the experimental result because the proposed engine manages both the scheduling and the storage decisions that affect it.
What the ablations show
Weight reuse accounts for the first large gain
The authors construct the pipeline in stages. The starting point is a single-batch schedule that uses current-layer computation to prefetch the entire expert layer. The next configuration introduces multi-batch execution. The subsequent configuration prefetches only the hot experts ahead of routing, with additional needed experts transferred once the gate identifies them. The last scheduling change groups and reorders expert computation. The table then reports a quantized variant of the full schedule.
Pipeline ablation on WikiText-103, Mixtral-8×7B end-to-end throughput in Environment 1
Multi-batch execution gives the largest gain in this sequence, and selective prefetching and expert ordering raise throughput further.
The numbers
| System or setting | token/s |
|---|---|
| Simple pipeline | 5.721 |
| Add multi-batch execution | 18.24 |
| Prefetch only hot experts | 19.074 |
| Klotski with expert reordering | 22.414 |
| Klotski with quantization (this paper) | 22.604 |
For Mixtral-8×7B on Environment 1, the multi-batch step produces the largest increase in the ablation sequence. It keeps resident weights busy for useful work across batches. A transfer that would be followed by a short computation with one batch can support a much longer computation interval with the group. Selective prefetching further increases throughput, and the move to expert ordering produces a larger increase than the selective-prefetch step in this setting.
The heavier checkpoint shows the same ordering of improvements on the single 3090. The simple pipeline reports 0.01 token/s for Mixtral-8×22B in Environment 1, and multi-batch execution reaches 0.97 token/s. Prefetching only hot experts reaches 1.127 token/s, and reordering expert work reaches 1.325 token/s. The quantized variant reports 1.366 token/s. The low starting throughput makes the absolute values important. They show what the pipeline could generate on that machine even after the initial bottleneck had been substantially reduced.
On Mixtral-8×22B in Environment 2, the simple pipeline reports 1.149 token/s. Multi-batch execution raises throughput to 34.07 token/s, and restricting advance expert prefetching raises it to 44.17 token/s. The full pipeline and its quantized configuration are the settings shown in the throughput chart above. On this machine, the selective-prefetch step yields a larger visible gain than it does for Mixtral-8×7B on the 3090. Across the columns, the value of an individual change depends on which waits the preceding configuration still exposes.
These are cumulative comparisons. Each stage inherits the preceding changes, so the gain from reordering measures what reordering adds after batch grouping and selective prefetching are in place. The result is consistent with the scheduling explanation. To prioritize an expert’s work, the engine needs both ready weights and tokens from several batches to put behind those weights. The ablation does not independently measure the contribution of the correlation table, every storage placement decision, or the sparse attention option.
A useful prefetch can miss the busiest expert
The paper reports two accuracy measures for its expert predictor. The first asks whether a prefetched expert actually participates in computation at the layer. The second asks whether the prefetched expert was among the experts that turned out to be hot. Participation is easier to satisfy. An expert that receives work from a small fraction of tokens can justify transferring its weights even if another expert would have offered more computation sooner.
For the grouped run shown in the prefetch analysis, the participation measure is consistently 100% across the layers. For a single sequence, the paper reports an average prefetch accuracy of 42.24%. The comparison shows how a forecast can become more useful when several batches share the transfer. More tokens provide more opportunities for the prefetched weights to be used. The result describes observed participation in the analyzed run and leaves room for unnecessary transfers on other inputs.
For the stricter question, the average reported accuracy is 58.89%. The gap between the two measures explains why a high participation figure alone would give an incomplete picture of the scheduler. An expert can be used without providing the large block of computation that the planner would most like to put first. The schedule can still benefit from that prefetch. It can use the work that is ready, start transfers for the actual missing experts as soon as routing reveals them, and process those experts as their weights arrive.
The accuracy analysis therefore connects to both boundaries of the pipeline. At the gate boundary, prefetch participation indicates whether early movement supplied weights that were eventually needed. Inside the layer, identifying genuinely busy experts increases the amount of useful computation available to cover the next transfers. The measurements show strong participation for the grouped workload alongside a substantially lower match to the busiest experts, which is exactly the distinction the scheduling design relies on.
Increasing the group size changes what limits throughput
The authors vary both the number of batches in a group and the batch size. With a small group, the curves rise as more batches provide more computation to run alongside transfers. A larger constituent batch can make this increase faster because each added batch contributes more sequences. In this part of the sweep, much of the gain comes from turning idle time into useful overlap.
Once the group is large enough, the throughput curves flatten. Further grouping can still reduce how frequently weights are loaded by sharing them more broadly, but fewer exposed waits remain for the change to eliminate. Meanwhile, the KV cache continues to grow with the amount of sequence work in flight. This is the reason the planner stops at a timing threshold and the reason a benchmark configuration might go past that threshold only as far as memory allows.
The sweep omits Mixtral-8×22B in Environment 1. The authors point to the GPU hours required to test the combinations there. The omission matters because this is also the setting in which their computed group size exceeds memory in the main comparison. The paper establishes the practical need for adjustment in that case, while leaving its throughput surface across group and batch sizes less fully characterized.
The timing trace locates the remaining stalls
The paper profiles an expert block of Mixtral-8×7B on the 3090. The simple overlap example uses a batch size of 64. It transfers all 8 expert weights, even though the profile labels the range of active experts as 5~8. The illustrated timeline has a wait of about 223.96 ms. The GPU’s attention work ends with much of the expert transfer window still exposed.
In the Klotski trace, the batch size stays at 64 and the group size is n = 10. After routing, the GPU starts the hot experts immediately. Some waits remain inside the expert layer because the ready expert computations still cannot cover all the later transfers. For the identical workload of 10 batches at batch size 64, the authors give about 215 ms with Klotski and roughly 2367 ms with the simple overlap method. These are timings from the profiled pipeline comparison. The end-to-end throughput results also include the rest of generation.
The paper discusses n = 15 as a setting at which the extra work can remove the illustrated intra-expert waits. The larger group also leaves more cache state to load during multi-batch attention, and the authors observe new gaps there. The trace thus shows how the bottleneck can move. A successful expert schedule can reveal costs elsewhere that were less visible when the expert layer accounted for most of the idle time.
Limitations
Limits identified by the authors
The authors identify a tension between covering expert transfers and keeping the attention cache manageable. Larger groups extend the computation interval available to hide I/O, but need more cache state. At the group size where the illustrated expert stalls can disappear, the paper still reports attention stalls associated with cache loads. The authors propose a more general sparse KV cache strategy as future work. The optional StreamingLLM technique shows that the engine can incorporate a sparse attention mechanism, while the future-work discussion leaves general cache management open.
The planner also depends on forecasts and statistical estimates. If little or none of the actual work falls to prefetched hot experts, the schedule loses the useful computation interval on which the later expert arrivals depend. The authors consider the extreme case unlikely and explain how remaining bubbles can arise when the group is too small to compensate. Their prefetch analysis measures participation and hot-expert accuracy on the runs they analyze. It supplies no frequency estimate for extreme routing patterns across other workloads.
A feasible group size can require manual intervention. The paper explicitly allows for adjustment when the computed value becomes too large. Its Mixtral-8×22B comparison on Environment 1 applies that adjustment after the calculated size causes an out-of-memory error. This example separates a timing solution from the practical choice under a tight memory budget. A larger group can satisfy the estimated deadlines and still create too much state to fit in the planned GPU placement.
The authors also limit the largest group-size sweep for practical reasons. They do not cover the full set of combinations on the more constrained machine for the larger checkpoint. That leaves less evidence about where its throughput levels off as group size and batch size vary together. The main benchmark supplies a working configuration for that hardware, along with a measurable throughput, instead of a complete map of the available settings.
Limits visible in the evaluation
The benchmark tests two Mixtral checkpoints and two hardware environments, and the larger environment only evaluates the larger checkpoint. This is enough to observe how the design responds to changes in network size and hardware capacity. It leaves the size of the gain uncertain for different routing architectures, different CPU-to-GPU transfer conditions, or systems with a greater dependence on disk. The Switch Transformers comparisons and routing heatmaps broaden the motivation. They do not amount to a full Klotski evaluation across other expert architectures.
The prompt and output lengths in the main evaluation are fixed at 512 and 32. That establishes a common workload for comparing the systems and makes the combined prefill-and-decoding denominator interpretable. It leaves other balances of prompt processing and generation unmeasured. The pipeline’s opportunities depend on how much work is available at once and how much cache state is active. Longer sequences, different output lengths, or inputs that activate a different distribution of experts can change both quantities.
The latency comparison concerns completing a workload under a time budget. A reader interested in an interactive service would also want per-request measurements, including the delay until a first token and how completion time varies across requests. The paper does not report those distributions. Its reported throughput and completion-time tradeoff applies to the batches it constructs. It cannot determine the experience of individual requests arriving over time and waiting for enough other work to form a group.
The benchmark settings also limit what can be inferred about the planner itself. The main comparison uses a group chosen from the sweep where applicable and a manually reduced group in the constrained case. The results demonstrate what the scheduling design can attain with those settings. They give less direct evidence about how frequently the automatically calculated group alone reaches the best measured throughput or what penalty an initial deployment might incur before adjustment.
Finally, the paper primarily evaluates system behavior. The optional quantization and sparse attention mechanisms affect the values used in computation or the attention state that remains available. The study reports their place in the transfer and memory tradeoff, but it gives no separate task-quality comparison for those options on the evaluated workloads. The gate-preserving nature of expert reordering explains why the scheduler can use the same expert assignments. That property does not establish output quality under optional changes to numerical precision or attention coverage.
What came after
The paper ends with an open problem in cache management. Once batching and expert order have hidden the larger weight transfers, loading attention state can become the next source of GPU idle time. The authors identify a general sparse KV cache strategy for the multi-batch pipeline as future work. No subsequent study is identified that demonstrates such an extension or measures how Klotski’s approach transfers to another inference engine.
Cite
Cite as Zhiyuan Fang, Yuegui Huang, Zicong Hong, Yufeng Lyu, Wuhui Chen, Yue Yu, Fan Yu and Zibin Zheng. 2025. Klotski: Efficient Mixture-of-Expert Inference via Expert-Aware Multi-Batch Pipeline. arXiv:2502.06888.
@misc{fang2025klotski,
title = {{Klotski: Efficient Mixture-of-Expert Inference via Expert-Aware Multi-Batch Pipeline}},
author = {Zhiyuan Fang, Yuegui Huang, Zicong Hong, Yufeng Lyu, Wuhui Chen, Yue Yu, Fan Yu and Zibin Zheng},
year = {2025},
doi = {10.48550/arxiv.2502.06888},
eprint = {2502.06888},
archivePrefix = {arXiv},
url = {https://doi.org/10.48550/arxiv.2502.06888}
}This page in Markdown https://md.research.elamur.ai/free/en/papers/fang-2025-klotski-efficient-mixture-expert-inference/