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



       Size      Model      TrivialQA(F1)      GLUE(Acc.)        MAG(Acc.)         Sci-Cite(Acc.)      Xsum(Rouge-1)         Avg.

                 Switch          27.00              62.25              20.00            30.83                13.55          30.73

      195M

                  Ours           26.72              62.86              18.33            32.50                13.36          30.75

                 Switch          30.10              64.76              22.67            31.25                14.62          32.68

      295M

                  Ours           30.31              64.66              22.17            33.75                15.53          33.28

                 Switch          35.08              68.33              25.29            35.00                15.62          35.86

      729M

                  Ours           35.56              68.00              25.50            36.67                16.05          36.35

                 Switch          46.06              77.75              31.33            46.75                16.77          43.73

      2.06B

                  Ours           46.96              78.00              30.67            47.50                17.35          44.09



Table 1. The zero-shot performance of models of different sizes on different tasks. Metrics reported depend on specific tasks. Our method

does not pose a drawback to model performance on downstream tasks.





                                                                                  Model(Strategy)        First token latency(s)

                                                                                  Switch(FIFO)                   22.395

                                                                                  Switch(LRU)                    23.428

                                                                                Switch(SwapMoE)                  12.767

                                                                                   Oracle-MoE                     4.910



                                                                        Table 2. First token latency of 765M models on different archi-

                                                                        tectures(strategies) under 50% of full-size memory. The memory

                                                                        budget only influences SwapMoE since it uses offline statistics to

                                                                        determine which expert to load first.





Figure 8. Latency composition of our proposed Oracle-MoE and            5.3. Overhead Analysis

Switch Transformer equipped with different swapping strategies.

Our model reduces the percentage of expert swapping latency and         Performance on Downstream Tasks Although designed

thus reduces the overall latency.                                       for edge-oriented scenarios, our model does not sacrifice

                                                                        performance on downstream tasks for edge-deploy inference

                                                                        latency. As is shown in Table 1, our proposed semantic

The latency composition breakdown in Figure 8 gives a                   group gating method shows a similar task performance,

detailed visualization of the above results. It can be observed         in some tasks even surpasses, the widely accepted token-

that even with the most limited memory budget, the latency              level gating MoE models. We believe this is attributable to

introduced by expert swapping in our model only contributes             our proposed semantic group-level routing strategy. This

to 50% of the overall latency. In token-level routing, such             setup allows each expert to focus on a subset of high-level

as the switch transformer, expert swapping contributes to               semantics rather than requiring every expert to learn all

more than 99% of latency.                                               possible high-level semantics present in their target tokens,

                                                                        thereby reducing redundancy among experts.

First token latency Our model activates fewer experts for

a single input, so that only 1 or 2 experts are needed for the          Training Stage Overhead Our approach differs from ex-

prefilling stage. So, our model requires only one-time expert           isting token-level MoE in that it includes a one-time cluster

loading during the prefilling stage. However, existing token-           analysis after the warm-up phase and cluster routing in each

level MoE methods still need to swap experts during the                 forward pass. In our experiments, with a sample size of

prefilling stage, leading to worse first token latency. Among           8192, the wall clock time for clustering analysis per layer

the three expert swapping strategies, FIFO does not help                is approximately 4 min, which is negligible compared with

at the prefilling stage, and the LRU strategy needs a warm-             tens of hours of pretraining. For routing in each pass, token-

up stage to decide on frequently used tokens. SwapMoE,                  level MoE is equivalent to performing a matrix multiplica-

however, uses off-line statistical information to decide the            tion. It requires 1e-4 seconds, whereas our low-dimensional

loaded expert at the beginning of inference, thus resulting             cluster Euclidean distance computation requires three matrix

in a lower first token latency than baselines, but still not as         multiplications and a square root operation. Thanks to the

good as ours.                                                           low-dimensional semantic space, the final wall-clock time



                                                                   8

