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



                                                                           is typically consistent, and successive queries from a user

                                                                           usually share similar knowledge grounds. In other words, a

                                                                           token sequence represents notable semantic locality across

                                                                           nearby tokens. Inspired by this observation, Oracle-MoE

                                                                           conducts routing in a highly compact space, termed the

                                                                           oracle space to assign tokens instead of the usual token

                                                                           embeddings.

                                                                           Particularly, our analysis revealed that tokens with higher

               (a)                               (b)                       mutual attention scores share similar high-level semantics,

                                                                           which we call semantic groups. To efficiently extract high-

Figure 1. a). Top: compared with a full model residing in the              level semantics, we use average token embeddings in each

memory, memory-constrained inference of LLMs suffers from                  group as semantic group embeddings and denote the set of

severe latency issues; Bottom: 50%-85% latencies are incurred              these embeddings as oracle space. Empirical evidence and

by the I/O overheads from expert swapping. An edge device with             theoretical analysis demonstrate that this concise calculation

8GiB GPU memory is adopted. b). Visualization of 60 expert                 of oracle space captures semantic locality and routing in the

activations of layer 7 in Qwen (Yang et al., 2024) across a sequence

                                                                           oracle space could preserve semantic locality better when

of 300 tokens.

                                                                           selecting experts, considerably decreasing the swapping fre-

                                                                           quencies. On GPT-2-based networks (Radford et al., 2019)

                                                                           of different capacities (200M, 350M, 790M, and 2.06B) and

mately 15 to 30 times higher than the same model entirely                  the downstream tasks including classification, QA and sum-

residing in the memory. 50%-85% of those latencies, as                     marization, our Oracle-MoE has attained state-of-the-art

portrayed in Figure 1(a) (Bottom), were incurred by the I/O                inference speeds than those baseline strategies across vary-

overheads from expert swappings. Despite several prior                     ing memory budges without comprising the performance.

attempts (Kong et al., 2024; Yi et al., 2023; Huang et al.,

2023b; Zhang et al., 2024; Rajbhandari et al., 2022) to op-

timize those latencies, they followed an engineering-based

                                                                           2. Analysis

perspective to develop comparatively naive and empirical                   In this section, we begin with defining the latency opti-

strategies, such as quantization (Zhu et al., 2023), expert                mization problem in semantic space with introducing the

pruning (Cheng et al., 2023; Rajbhandari et al., 2022), re-                Consecutive Semantic Difference (CSD). Given that con-

taining frequently-used experts (Kong et al., 2024; Yi et al.,             secutive tokens show semantic localities, we aim to find a

2023; Huang et al., 2023b; Artetxe et al., 2022), which lack               low-variance semantic embedding for each token. We first

systematic, in-depth investigations.                                       model the token embeddings as the combination of high-

This work thoroughly examines the underlying mechanism                     level semantics and token-identity semantics. Then, we use

behind the high latencies of memory-constrained MoE-                       attention scores to discover high-level semantics similar-

based LLM inference. Figure 1(b) depicts the inter-token                   ity and obtain semantic groups, and construct the Oracle

activations of 60 experts of one layer across a sequence of                Space with semantic group embeddings. Finally, we show

300 tokens, which exhibit a highly spare and temporally                    that oracle-space-based routing yields significantly lower

inconsistent pattern. Such a pattern will inevitably create a              CSD compared to token-level routing, both theoretically

plethora of expert-swapping demands to be resolved, and                    and empirically.

it is challenging to develop an effective empirical strategy

due to the complexity, sparsity, and inconsistency of activa-              2.1. Latency Problem Formalization

tions. The essential cause for this pattern can arguably be                Deploying Mixture of Expert (MoE) models on edge devices

attributed to that current MoE routings are predominantly                  faces the challenge of expert swapping latency. Meanwhile,

influenced by token embeddings, which tend to be domi-                     we do not want latency optimization to degrade the model’s

nated by token-specific information with high inter-token                  performance. So, we introduced a constraint that the la-

variations.                                                                tency optimization must ensure that the measurement of

To this end, we devise Oracle-MoE, a novel MoE architec-                   performance M that the user is interested in is better than a

ture to generate routing decisions that naturally activate iden-           threshold γ:

tical experts across consecutive tokes to reduce inter-token                                 min Ltotal   s.t. M > γ

variations, eliminating massive expert-swapping needs and

accelerating memory-constrained inference. Oracle-MoE is                   Our experiments in Section 5 will show that latency opti-

bridged on a characteristic of edge scenarios such that the                mization does not necessarily lead to performance degra-

linguistic meaning between consecutively generated tokens                  dation. For simplicity, we omit the subject to item in the



                                                                       2

