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



that they share similar high-level semantics. So, we propose            semantics. Among tokens with the same identity, the em-

to model this through a causal graph perspective, where                 beddings of those that share the same high-level semantic

semantic groups emerge from connectivity in the attention               meaning tend to be more similar. This pattern is consis-

score matrix.                                                           tently observed in various models, including widely used

                                                                        large models like DeepSeek-16B-2.8B (Dai et al., 2024)

Consider a directed acyclic graph Gglobal = (Vglobal , Eglobal ),

                                                                        and Qwen1.5-MoE-A2.7B (Team, 2024), which are illus-

where Vglobal contains all tokens and Eglobal consists of edges

                                                                        trated in Figure 2, Figure 10 and Figure 11 in Appendix B.2.

ti → tj weighted by aij from the lower-triangular attention

                                                                        Theoretical insights into how attention mechanisms com-

score matrix Aglobal = [aij ] (i.e., aij exists only for i >

                                                                        pute correlations between tokens using the inner product

j). We define semantic groups as maximally connected

                                                                        of query (Q) and key (K) vectors are also supported by ex-

components that only tokens with an attention score larger

                                                                        isting studies (Raffel et al., 2020; Vig & Belinkov, 2019).

than a predefined threshold ϵ are considered connected:

                                                                        The computation of attention scores involves first assessing

Definition 2 (Semantic Group). A subset containing tokens               token correlations through inner products of query (Q) and

S = {tk1 , ..., tkm } (indices k1 < ... < km ) is called a              key (K) vectors, followed by normalization of these correla-

semantic group if:                                                      tions via softmax, and finally allocating contextual informa-

(                                                                       tion through value (V) vectors weighted by the normalized

  ∀i, j ∈ {k1 , . . . , km }, (i > j) =⇒ aij > ϵ

                                                                        scores. Among which, the Q-K inner product effectively

  No proper superset of S satisfies the condition above                 captures token similarity and reflects high-level semantic

                                                                        alignment, as visualized in Appendix B.2.

This can be regarded as a reformulation of the Minimum

Clique Cover Problem (Gavril, 1972) for DAGs. The defini-               Oracle Space Following sentence meta-embedding tech-

tion leverages the block structure of attention score matrices          niques (Poerner et al., 2019; Takahashi & Bollegala, 2022),

as is shown in Figure 3, which is also observed in previous             we compute semantic group embeddings as the average

works((Liu et al., 2024)). So, although the Minimum Clique              token embeddings in it. Formally:

Cover is NP-hard, we claim that it can be computation-

ally tractable on attention score matrix via polynomial-time            Definition 3 (Semantic Group Embedding). For a Semantic

greedy algorithms (Farjas, 2018). We first initialize each              Group Si , its semantic group embedding zSi is defined as:

token as a singleton group, then for the token xi from left                                          1 X

to right, we find the maximal j < i with aij > ϵ and merge                                  zSi =         tj

                                                                                                    |Si |

xi into xj ’s group if ∀xk in the group, aik > ϵ.                                                       tj ∈Si





                                                                        As proven in (Xu et al., 2018; Soltanolkotabi et al., 2013)

                                                                        and demonstrated in Appendix A.2, this aggregation reduces

                                                                        token-identity noise while preserving essential high-level

                                                                        semantics. Thus, we can efficiently extract various high-

                                                                        level semantic information from the embedding space using

                                                                        semantic group embeddings. We collect semantic group em-

                                                                        beddings from different data and name the space consisting

                                                                        of these embeddings as Oracle Space, efficiently describing

                                                                        various high-level semantics.



              (a)                             (b)                       In inference task, new tokens arrive sequentially over time.

                                                                        To model the evolution of semantic groups and derive token

Figure 3. Visualization of attention score matrix. There are two        embeddings based on these groups, we propose the semantic

semantic groups where tokens in each group show high attention          embedding of each token as its semantic group embedding.

scores with each other.                                                 Given a token tt at time step t, let S(t) denote the semantic

                                                                        group corresponding to tt . We use the embedding of S(t)

Discussion: Previous studies (Kamath et al., 2019) on repre-            as the token’s semantic embedding:

sentation space analysis have shown that semantically sim-

ilar samples exhibit higher similarity in their embeddings                                              1    X

                                                                                      ztt = zS(t) =            t,

compared to semantically dissimilar ones, which is also                                               |S(t)|

                                                                                                             t∈S(t)

widely validated in experiments with general-purpose large

models. We corroborate this observation and further identify            The S(t) includes all tokens from previous time steps t′ < t

a more fine-grained similarity pattern: token representations           such that:

encapsulate both high-level semantics and token identity                                 ∀tt′ ∈ S(t), att′ > ϵ,



                                                                    4

