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



where att′ is the attention score between tokens tt and tt′ .                  Next, we highlight the low-variation gains of oracle-space-

When the model generates consecutive tokens, it retains the                    based routing compared to token-level routing, which re-

KV cache of previous tokens, so that att′ can be obtained                      duces unnecessary routing changes for semantically similar

by adding a new row to Aglobal .                                               tokens. This leads to the following theorem:

This provides a way to compute semantic groups with a                          Theorem 1. With a high probability, ∀t                   ∈

streaming input, which is the case for auto-regressive gen-                    N, tt , tt−1 , att−1 > ϵ with a sufficiently high dimen-

eration. As is shown in Figure 4, in an auto-regressive                        sion of token identity information:

generation process, the token’s semantic embedding varies                              C(Wg , k)∥tt − tt−1 ∥ > zS(t) − zS(t−1)

smoothly and slowly in the oracle space, preserving high-

level semantic information.

                                                                               Through the CSD estimation framework established in Sec-

                                                                               tion 2.1, this induces the relationship:

                                                                                                  CSDtoken > CSDoracle ,



                                                                               This indicates that oracle-space-based routing provides

                                                                               lower variation by reducing routing changes for semanti-

                                                                               cally similar tokens. The detailed proof is provided in the

                                                                               Appendix A.4.



                                                                               3. Oracle-MoE

              (a)                                     (b)

                                                                               Based on the above analysis, we propose Oracle-MoE, re-

Figure 4. UMAP visualization of sampled semantic group embed-                  placing the token-level MoE routing mechanism with a bet-

dings (token’s semantic embeddings) in different model layers.                 ter semantic locality in the oracle space and expert activation

Each color represents a sequence(user interaction). As token gen-              consistencies for edge-side devices to generate text scenar-

eration goes on, the embeddings based on semantic groups vary                  ios.

slowly and smoothly.





2.3. Oracle-Space-Based Routing Yields Lower CSD

Based on the above analysis, routing tokens with similar se-

mantic embedding in the oracle space to the same expert is

highly likely to yield a low expert variation. Since semantic

group embeddings evolve locally in the oracle space (Fig-

ure 4), we employ clustering algorithms to allocate tokens

that belong to the same cluster in the oracle space to the

same expert, or:



   et = arg min ∥ztt − ck ∥ = arg min ∥zS(t) − ck ∥                  (1)

               k                               k





where ck denotes the cluster center in oracle space, which

will be detailed in Section 3. So, the change in expert                        Figure 5. Overview of an Oracle-MoE layer. Residual connections

assignments can be approximated by the change of semantic                      are omitted.

group of ztt . We provide a detailed analysis of this trend in

the AppendixA.3, and the following form:                                       Oracle Space Initialization We obtain the initial oracle

Definition 4 (CSD for oracle-space-based routing). Let                         space after a short warm-up training phase of the token-

S(t − 1) and S(t) denote the semantic groups of token                          level MoE model. After the warm-up stage, we randomly

tt , tt−1 at consecutive time steps. Without loss of generality,               sample N data, and get the semantic group embeddings of

based on semantic variations on semantic groups, we have                       each data as is mentioned in Section 2, Definition 2, and

CSD of oracle-space-based routing:                                             3. These semantic group embeddings form an initial ora-

                    T                    T

                                                                               cle space. Routing in the oracle space does not necessitate

                                                                               complete information; only distinguishing high-level se-

                    X                    X

    CSDoracle =           ∆et,oracle ≈             zS(t) − zS(t−1)

                    t=2                  t=2

                                                                               mantics is required. Therefore, to improve computational



                                                                           5

