   Oracle-MoE: Locality-preserving Routing in the Oracle Space for Memory-constrained Large Language Model Inference









                (a)                             (b)                             (c)                             (d)



Figure 6. Expert activation results of (8*16)729M models. In Switch Transformer, almost every 2 consecutive tokens activate different

experts, and nearly all experts are activated, demanding frequent expert swapping. Whereas Oracle-MoE requires only a few expert

swappings as the token generation continues.









              (a)                               (b)                              (c)                              (d)



Figure 7. Memory-Latency curve of models of different sizes, where n ∗ m(p) denotes a model consisting of n MoE Layers with m

experts each, and in total p parameters. Full model refers to a model with the same number of activated parameters.





Swapping Strategies As introduced in Section 1, swap-                for a given memory size. A larger memory provides models

ping strategies assign a certain priority to each expert so          with redundancy to store temporarily unused experts and

that lower-priority experts can be swapped out first. We             mitigate the penalty of expert activation variation. c) First

evaluate both our model and the Switch Transformer with              token Latency measures the time before the first token is

First-In-First-Out (FIFO), Least Recently Used (LRU), and            generated after the users provide the input. This is also an

the strategy in SwapMoE (Kong et al., 2024). FIFO swaps              important metric for user experience.

out the expert that is loaded first, and LRU swaps out the

experts that have not been used for the longest time. In             5.2. Results

SwapMoE(Kong et al., 2024), experts are weighted by their

frequency, magnitude, and input tokens. However, since               Expert Activation Figure 6 illustrates the expert activa-

our model eliminates the requirement of expert swapping,             tion of two models. During consecutive auto-regressive

different strategies don’t make a big difference in our model.       generation passes, our method shows a lower expert activa-

So, we report the average of 3 strategies on our model.              tion variation, where expert swapping is only triggered after

                                                                     hundreds of tokens are generated. In Switch Transformer,

                                                                     expert activation changes frequently.

Data & Workload Models are pretrained on Openweb-

Text (Komatsuzaki, 2019), which is one of the pretraining            Memory-Latency Figure 7 illustrates the memory-latency

datasets of GPT2 (Radford et al., 2019). We primarily use            curve for methods of different sizes. The result of our model

downstream tasks of 3 types: question answering, clas-               is reported as the average of different strategies. As is shown

sification, and summarization. For QA tasks, we adopt                in the figure, while with a small-sized model, the latency is

Trivia QA (Joshi et al., 2017). For classification, we adopt         acceptable, the case becomes worse rapidly as the model

GLUE (Wang et al., 2019), MAG (Sinha et al., 2015) and               size gets larger. For the 8*16(729M) model, even though

Sci-Cite (Beltagy et al., 2019). We also use XSum (Narayan           only 1 expert is allowed for each layer (which is about only

et al., 2018) for summarization tasks. In experiments, we            25% of the full-size memory), our method introduces only

always kept the batch size equal to 1, which is the real sit-        3s additional latency compared with the full-size inference.

uation when running on edge devices like mobile phones,              Whereas Switch Transformer with FIFO, LRU, or Swap-

processing one user request at a time.                               MoE load-on-demand strategy introduces inevitable latency,

                                                                     increasing latency by up to 2000% compared to a full-size

Metrics We adopt mainly 3 evaluation metrics. a) Expert              memory inference. When the memory budget increases by

Activation, to evaluate the variation in expert activation of        up to 50% of the full-size model, the latency of the Switch

different models. b) Memory-latency curve measures the               Transformer with different strategies is still unacceptably

average time the model takes to process a single data point          high, whereas our model does not introduce latency.



                                                                 7

