Skip to content
hoonki2002Public

About

Official code for CECAR [NeurIPS 2026]

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

CECAR: Cache & Expert Co-Aware Routing Accelerates On-Device Inference of MoE LLMs

Official code for the NeurIPS 2026 paper "CECAR: Cache & Expert Co-Aware Routing Accelerates On-Device Inference of MoE LLMs".

[Paper] [NeurIPS Poster]

Note on collaboration. This codebase was developed jointly by Byeongju Kim and Hoonki Lee. Please see the paper for the full author list and contributions.

Overview

Large MoE models cannot keep all experts in the memory of an on-device system, so non-resident experts have to be fetched from SSD, and this loading latency dominates decoding time. Our analysis shows that

  1. cache hit rates are fundamentally bounded, even under Belady's optimal replacement policy;
  2. these bounds are insufficient for low-latency on-device inference;
  3. cache-aware approximate expert routing can substantially improve cache locality with minimal semantic distortion, whereas routing based on binary cache presence alone can induce routing instability.

CECAR (Cache & Expert Co-Aware Routing) is a MoE inference system that jointly optimizes expert routing and cache management. An ML-based cache policy predicts how soon each expert will be reused, and routing is biased toward cached experts according to this prediction.

On Qwen3-30B-A3B with a 16 GB consumer GPU and ~1 GB of host DRAM (experts fetched from SSD), CECAR reaches 12.5 tokens/s, a 4.5x speedup over conventional MoE inference, with a cache hit rate of 96.6%.

CECAR Demo on a personal laptop

Set up (once, on your laptop):

git clone https://github.com/hoonki2002/CECAR && cd CECAR && chmod +x build
conda create --name CECAR python=3.11 -y && conda activate CECAR
pip install torch --index-url https://download.pytorch.org/whl/cu128    # pick the CUDA version that matches your driver
pip install -r requirements.txt
./build --model_name Qwen3_30B_A3B                                      # downloads Qwen3-30B-A3B (57 GB) and splits it into expert files (another 57 GB)

The demo runs Qwen3-30B-A3B with real expert offloading (a VRAM cache of 24 experts per layer, all other experts are read from the SSD) and lets you switch CECAR on and off yourself:

  • CECAR on: the learned ML_CECAR cache policy and cache-aware routing.
  • CECAR off: the conventional way, exact top-k routing with an LRU cache.

The VRAM cache size is 24 experts per layer by default. You can change it with the slider at any time, also while a reply is being written (from 8 up to what your GPU holds, at most 64 of the 128): the cached experts stay and the new size is applied before the next token. The Hardware tab shows the resulting VRAM budget.

It has to run on your own PC. What you feel is the SSD, so the result depends on the machine. Do not lock memory on a shared server.

❗❗ Limit the host DRAM first (otherwise the demo hides the effect) ❗❗

Important

Do this before you start the demo.

The expert files are 54 GB. If your machine has more free RAM than that, the OS keeps them in its page cache and "loading from SSD" is served from RAM. The paper leaves only about 1 GB of DRAM to the OS; lock_dram.py locks most of your DRAM to do the same.

Open a separate terminal, go to the repository root and run (it asks for confirmation):

sudo python3 Src/Demo/lock_dram.py --keep-free-gb 1
  • --keep-free-gb N is the memory that stays free for the system and for the demo itself. The paper used about 1. If 1 does not work on your machine (it freezes or the demo cannot start), increase it to 4.
  • Keep that terminal open while you use the demo. Ctrl-C releases the memory.

Start the demo

python Src/Demo/app.py          # then open http://127.0.0.1:7860

The model is loaded once (a few seconds on a fast SSD). The page has three tabs:

  • Chat: a normal conversation; switch CECAR on or off at any time. Every reply shows the decoding speed, cache hit rate and SSD reads.
  • Single question (ON vs OFF): one question (pick an example or type your own), answered with CECAR on and then off with greedy decoding, compared side by side.
  • Hardware: what your machine has (VRAM, DRAM, SSD), the VRAM budget of the expert cache, how much DRAM is locked, and where the experts end up (VRAM cache / DRAM / SSD).

Chat (first reply with CECAR on, follow-up with CECAR off):

Chat tab

Single question (Test (1), greedy):

Single question tab

Cache size (slider set to 16; the Hardware tab shows the VRAM budget):

Cache size

Hardware (before and after limiting the DRAM):

DRAM not limited DRAM limited with lock_dram.py
Hardware tab, DRAM not limited Hardware tab, DRAM limited

1. Setup

Do the set-up of the demo section above (installation and ./build).

  • ./evaluation (simulation mode) keeps all experts in GPU memory (about 57 GB for Qwen3-30B-A3B in BF16), so it needs a large GPU. We ran it on an A100 80GB.
  • ./inference (offloading engine) is meant for small GPUs: the paper's measurements use a 16 GB GPU, host DRAM limited to ~1 GB, and a fast NVMe SSD.

To evaluate gpqa or math500 (section 5), also install OpenCompass:

pip install -e Src/Evaluation/opencompass

2. Record the routing histories

The training data of the ML cache policy. Run the real model on TriviaQA prompts and save the router logits of every decode step:

./collect --model_name Qwen3_30B_A3B --datasets triviaqa

3. Train the ML cache policy

Every layer is trained on its own; the training reads only the TriviaQA history from section 2:

./train --model_name Qwen3_30B_A3B --mode train_only --train_ffn_model ML_CECAR

One checkpoint per layer should have been written:

ls Src/Train/Trained_FFN/Qwen3_30B_A3B/ML_CECAR/    # base_layer0.pt ... base_layer47.pt

./evaluation and ./inference use these files instead of the shipped ones.

4. Run inference on one problem

./inference \
  --model Qwen3_30B_A3B \
  --test-task humaneval \
  --task-num 0 \
  --cache-policy ML_CECAR \
  --mode none \
  --bonus-strategy cecar \
  --temperature 0

This runs the real MoE model with CECAR routing and the ML-based cache policy (ML_CECAR, the shipped models in Src/Demo/Pretrained_FFN/Qwen3_30B_A3B/ML_CECAR/ are loaded unless you trained your own) on the first HumanEval problem. It prints the generated text followed by a summary:

Average alpha: 0.63
prefill_time: ..., decode_time: ..., hit_rate: 0.9655, prefill speed: ..., decode speed: ...
hit_rate by layer
	layer_0: ...
	...
	layer_47: ...
Saved results to: Results/run_results.json
  • Speeds are in tokens/s. They depend on your SSD and GPU; the 12.5 tokens/s in the paper was measured on the testbed described in Hardware.
  • The generated text is saved to Src/Inference/Qwen3_30B_A3B/Results/generated_tokens.txt and the statistics to Results/run_results.json in the same folder.

--temperature 0 makes the decoding greedy. Without it, generation uses sampling with temperature 0.7 and top-p 0.95, as in the paper.

To try your own prompt, replace --test-task/--task-num with --input:

./inference --model Qwen3_30B_A3B --cache-policy ML_CECAR --mode none --bonus-strategy cecar \
  --input "Write a Python function that checks whether a string is a palindrome."

Compare routing methods

The same command with different flags runs the methods compared in the paper:

Method --cache-policy --mode --bonus-strategy
Baseline (exact top-k, LRU cache) lru none none
MoCCE lru none mocce
DES lru des none
ODP lru odp none
CECAR-LRU (ablation, no ML policy) lru none cecar
CECAR ML_CECAR none cecar

DES and ODP are routing-only methods, so their bonus strategy is always none. --bonus-strategy cecar requires --cache-policy ML_CECAR or lru.

5. Evaluate on a benchmark (simulation mode)

./evaluation measures accuracy, cache hit rate and the average number of routed experts per layer on the benchmark datasets. It replaces the SSD with a virtual cache: the cache state is tracked exactly as in the offloading engine (same routing, pruning, admission and eviction rules), but all expert weights stay in GPU memory, which makes it much faster than real offloading. Decoding speed is therefore not measured here.

Start with the first 5 MATH-500 problems, decoded greedily:

./evaluation \
  --simulation_model Qwen3_30B_A3B \
  --tasks math500 \
  --cache_policy ML_CECAR \
  --mode none \
  --bonus_strategy cecar \
  --temperature 0 \
  --limit 5 \
  --limit_start 0

Results are written to Src/Evaluation/results/opencompass/simulation-qwen3moe-cecar-ML_CECAR_math500_seed0/<timestamp>/:

File Content
summary/summary_<timestamp>.txt the accuracy
predictions/simulation-qwen3moe-cecar-ML_CECAR/ the generated answers, and the cache hit rate in cache_stats.json

Option reference

./build --model_name <model>: Qwen3_30B_A3B | DeepSeek_v2_Lite_Chat | OLMoE_1B_7B_0125_Instruct

./inference

--model          : Qwen3_30B_A3B | DeepSeek_v2_Lite_Chat | OLMoE_1B_7B_0125_Instruct
--test-task      : humaneval | mbpp | gpqa | math500      (or --input "<your prompt>")
--task-num       : 0 | 1 | 2 | 3 | 4
--cache-policy   : lru | lfu | lifo | ML_CECAR | ML_FlashMoE
--mode           : none | des | odp
--bonus-strategy : none | mocce | cecar
--temperature    : sampling temperature, default 0.7 (0 = greedy)

./evaluation

--simulation_model : Qwen3_30B_A3B | DeepSeek_v2_Lite_Chat | OLMoE_1B_7B_0125_Instruct
--tasks            : humaneval | mbpp | gpqa | math500
--cache_policy     : lru | lfu | lifo | ML_CECAR | ML_FlashMoE
--mode             : none | des | odp
--bonus_strategy   : none | mocce | cecar   (random, constant, lfu, lru, const are other experimental variants)
--limit_start      : index of the first evaluated problem (default 0)
--limit            : number of evaluated problems (omit to evaluate the whole dataset)
--temperature      : sampling temperature, default 0.7 (0 = greedy)
--top_p            : nucleus sampling threshold, default 0.95
--seed             : random seed, default 0

./train

--model_name       : Qwen3_30B_A3B | DeepSeek_v2_Lite_Chat | OLMoE_1B_7B_0125_Instruct
--mode             : train_eval | train_only | eval_only
--train_ffn_model  : ML_CECAR | ML_FlashMoE        (not used with eval_only)
--eval_model       : both | ML_CECAR | ML_FlashMoE
--CECAR_ckpt_dir / --FlashMoE_ckpt_dir : checkpoint directories (required with eval_only)

Cache policies. ML_CECAR is the cache policy proposed in the paper: a pair of expert-independent FFNs for short-term and long-term reuse. ML_FlashMoE is a reference implementation of the learned eviction model of FlashMoE, provided for comparison and not part of CECAR. The FlashMoE numbers reported in the paper follow the figures reported in the FlashMoE paper; the hyperparameters of this reference implementation may differ from the original. lru, lfu and lifo are the classical heuristics.

Baselines. DES and ODP (paper) are routing-only methods (--mode des|odp). MoCCE (paper) is a bonus-based cache-aware routing strategy that promotes experts already resident in the cache without changing eviction decisions (--bonus-strategy mocce, with lambda 0.2 and J 2).

Hardware

The paper's measurements were taken on a desktop with an AMD Ryzen 5 9600X, an NVIDIA RTX 5070 Ti (16 GB), 64 GB DDR5 (host DRAM limited to ~1 GB during inference) and a PCIe 5.0 NVMe SSD, running Ubuntu 24.04 with Python 3.11, PyTorch 2.7 and CUDA 12.9.

License

The CECAR code is released under the MIT License (see LICENSE). The third-party code below keeps its own license.

Third-party code and licenses

  • Src/Evaluation/opencompass/ is OpenCompass (Apache License 2.0, see Src/Evaluation/opencompass/LICENSE).
  • Src/Evaluation/bigcode_eval/ is derived from the BigCode Evaluation Harness (Apache License 2.0, see Src/Evaluation/bigcode_eval/bigcode_LICENSE).
  • Src/Evaluation/fiddler_model/MCMOE/ contains DES / ODP calibration thresholds computed following MC-MoE.

Citation

@inproceedings{kim2026cecar,
  title     = {{CECAR}: Cache \& Expert Co-Aware Routing Accelerates On-Device Inference of {MoE} {LLMs}},
  author    = {Kim, Byeongju and Lee, Hoonki and Kim, Byungjun and Ra, Inyul and Kim, Yongjin and Lee, Yongseong and Kim, Sangyeob},
  booktitle = {Advances in Neural Information Processing Systems},
  year      = {2026}
}

About

Official code for CECAR [NeurIPS 2026]

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages