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



efficiency, we adopt SVD to reduce these embeddings to               2017; Dauphin et al., 2017; Vaswani et al., 2017) has been

lower dimensions (Schmidt, 2020).                                    proposed and achieved great success in a variety of tasks.

                                                                     MoE has been widely explored to improve the training ef-

Oracle-MoE Routing at Pretraining Since the semantic                 ficiency of Large Language Models(LLMs), with various

group embedding varies only locally within a small region            routing strategies like (i) letting tokens select the top-k ex-

in the oracle space as tokens are generated, to ensure tokens        perts (Lepikhin et al., 2021; Fedus et al., 2022; Zuo et al.,

in the same semantic group to be dispatched to the same              2022; Chi et al., 2022; Dai et al., 2022; Chen et al., 2023),

expert, we run K-means (Jain, 2008) in the oracle space to           (ii) letting experts select the top-k tokens (Zhou et al., 2022),

get k oracle clusters. The parameter k here is equal to the          to (iii) globally decide expert assignment (Lewis et al., 2021;

expert number of the original token-level MoE, and Sec-              Clark et al., 2022).

tion 5 will show that our method yields persistently good

results with k ranging from 4 to 32. In the following training

process, we replace the routing of the original token-level          Memory-constrained Inference Solutions for Mixture

MoE with the routing mechanism shown in Figure 5. For                of Experts Huang et al. propose swapping experts from

each new incoming data, we first divide it into semantic             GPU memory to CPU memory to reduce memory usage,

groups according to the attention scores and get their seman-        though this approach introduces significant latency over-

tic group embeddings in the oracle space with the same SVD           head (Huang et al., 2023a). SE-MoE (Shen et al., 2022)

transform matrix computed in the previous stage. Then we             employs Ring Memory offloading to minimize GPU mem-

calculate which oracle cluster each semantic group belongs           ory consumption. EdgeMoE (Yi et al., 2023), the on-device

to as Equation 1, and dispatch tokens in the semantic group          inference engine tailored for MoE-based LLMs, reduces ex-

to the corresponding expert.                                         pert I/O overhead through expert-wise bitwidth adaptation

                                                                     and in-memory expert management, achieving low-latency

Oracle-MoE Routing at Inference The inference stage                  inference while maintaining task performance. While Swap-

can be divided into prefill and decode stages. The prefill           MoE (Kong et al., 2024), by dynamically managing a small

stage is the same as the training stage routing. In the decode       set of Virtual Experts based on activation locality and hard-

stage, Oracle-MoE first decides which semantic group the             ware profiling, reduces memory consumption and latency,

coming token belongs to, and updates the semantic group              but sacrifices accuracy. These works do not take into ac-

embedding with the coming token. Since KV cache is a                 count the characteristics of semantic space, especially the

widely adopted strategy (Yuan et al., 2024), this does not           cluster characteristics of high-level semantics and in-depth

introduce memory overhead. Then we dispatch it to the                investigations.

expert corresponding to the oracle cluster of its semantic

group. In our experiments, there are often fewer than 5

                                                                     5. Experiments

semantic groups in an input session within a length of 1024,

and semantic groups from the same session are likely to              5.1. Settings

belong to the same oracle cluster. So, the oracle space

routing preserves the semantic locality of input tokens and          Hardware Platform Since mainstream mobile

yields a low expert variation, contributing to low expert            phones(like Android and Apple ) and NPU manufac-

swapping latency.                                                    turers (e.g., Apple, Hisilicon, Qualcomm, Samsung) do

                                                                     not provide commercial APIs for low-level GPU memory

                                                                     operations, we adopt NVIDIA Jetson Xavier NX as our

4. Related Works                                                     experimental platform. The NVIDIA Jetson Xavier NX is

Mixture of Experts The Mixture of Experts (MoE) is a                 equipped with a 384-core NVIDIA Volta architecture GPU

fundamental model in machine learning (Jacobs et al., 1991;          with 8 GiB of GPU memory and an estimated 21 TOPS AI

Jordan & Jacobs, 1994) and an instance of the conditional            computing power.

computation framework where different experts are respon-

sible for different inputs. To increase the model’s capacity

to deal with complex data, (Eigen et al., 2013) extended             Models We mainly compare Oracle-MoE with Switch

the MoE structure to deep neural networks and proposed               Transformer (Fedus et al., 2022), a representative token-

a deep MoE model composed of multiple layers of routers              level MoE architecture. Experts are loaded on demand under

and experts. (Shazeer et al., 2017) simplified the MoE layer         our experiment settings. We use models containing m MoE

by making the output of the gating function sparse for each          layers with n experts each and with a total parameter of p,

example, which greatly improves the training stability and           denoted as n ∗ m(p). In our experiments, we use models

reduces the computational cost. Since then, the MoE layer            of 2*4(192M), 4*8(295M), 8*16(729M) and 9*24(2.06B).

with different base neural network structures (Shazeer et al.,       Detailed model configurations are in Appendix B.



                                                                 6

