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



following of this section. The total latency Ltotal can be           where C(Wg , k)is a constant dependent on Wg , k.

written as:

                                                                     However, since there is a large variance between token em-

                   T

                   X                                                 beddings, as is shown in Figure 2 left, the CSD is hard to

        Ltotal =         Lcompute (t) + Lswap (et , et−1 ),          optimize for existing token-level MoE. Xue et al. (2024)

                   t=1                                               also mentioned that token-level MoEs tend to dispatch to-

                                                                     kens according to token ID. But the linguistic meaning of

where Lcompute (tt ) denotes computation latency for token

                                                                     consecutive user interactions on edge devices is notably

embedding tt , and et denotes the set of activated expert

                                                                     similar, which we term as semantic locality. This inspires

indices for token tt . Lswap (et , et−1 ) captures swapping

                                                                     us to minimize swapping latency by extracting high-level

latency caused by loading experts that are activated by tt

                                                                     semantics and designing a new gating mechanism.

but not activated by tt−1 . Specifically:



            Lswap (et , et−1 ) = lswap · |et \ et−1 |,               2.2. Semantic Groups and Oracle Space

                                                                     Token Embeddings In token-level MoEs, tokens in the

where |et \ et−1 | is a set minus operation. In practice, MoE-       same sequence do share some similar high-level semantics,

based LLMs on edge devices generate continuous semantics,            with their high-level semantics’ locality and tendency to

the large variance in the token-level MoE routing mecha-             cluster logically, as shown in Figure 2. But their embed-

nism is essentially due to the high inter-token semantic vari-       dings are still influenced primarily by the token-identity fea-

ance, resulting in frequent changes in routing results. We           tures, leading us to explore semantic spaces. These tokens

define Consecutive Semantic Difference (CSD) to measure              simultaneously contain two types of semantic information.

the variation in expert selection over consecutive tokens:           Definition 1 (Token Embedding). For each token embed-

                                  T

                                                                     ding ti ,

                                                                                          ti = si + ui ,

                                  X

                         CSD =          ∆et ,

                                  t=2                                where si represents shared high-level semantic information

                                                                     between consecutive tokens and ui represents unique token-

Given fixed hardware and swapping algorithms, Lcompute               identity information.

and lswap are fixed, thus CSD determines Ltotal . The final

optimization goal is:

                                 T

                                 X

                           min         ∆et .

                                 t=2



Remark: Setting ∆et = 0 leads to a dense model that

would trivially minimize CSD, which is not considered

in our work as it negates the fundamental advantage of

MoE models—leveraging multiple experts for specialized

processing.

                                                                     Figure 2. UMAP visualization of embedding space in existing

In existing token-level MoE models, experts are usually

                                                                     token-level MoE models. Left: Tokens tend to cluster accord-

selected through a linear gate Wg ∈ RN ×d (Cai et al., 2024),        ing to token-identity semantics. Right: Tokens from the same

which projects the token embedding tt ∈ Rd into expert               sequence are colored the same. They share similar semantics and

scores g(tt ) = Wg tt ∈ RN . The experts are then chosen             stay closer to each other in each token cluster.

as:

           et = Top-ki∈{1,...N } (softmax(Wg tt )i )

                                                                     Semantic Groups Studies ((Vaswani et al., 2017; Koval-

where Top-k denotes the indices of top k largest elements.           eva et al., 2019; Clark et al., 2019)) indicate that attention

Inspired by previous work (Xue et al., 2024), current token-         captures high-level semantic correlations between tokens.

level MoEs tend to dispatch on token-identity semantics.             Therefore, we intuitively claim that the mapping of the Q/K

So, we approximate the change in Top-k expert selection              matrices and the calculation of the attention scores will

between consecutive tokens by the difference in their trans-         group consecutive tokens with similar high-level semantics

formed embeddings:                                                   together through significant attention score distribution dif-

                   T              T

                                                                     ferences. Our analysis in Appendix A.1 demonstrates that

                                                                     under our definition of token embedding and analysis of the

                   X              X

    CSDtoken =           ∆et ≈          C(Wg , k)∥tt − tt−1 ∥

                   t=2            t=2

                                                                     Q/K matrix, a high attention score between tokens indicates



                                                                 3

