ZongfangLiu/EvoESAP

EvoESAP: Non-Uniform Expert Pruning for Sparse MoE

5

stars

3

commits

Python

primary language

Mar 31, 2026

updated

README

EvoESAP: Non-Uniform Expert Pruning for Sparse MoE

Python PyTorch Transformers License


Contents

Overview

At a high level, EvoESAP runs:

  1. Observer data collection on calibration prompts.
  2. Evolutionary search over layer-wise pruning plans.
  3. Best-plan materialization (structural non-uniform or mask-based).
  4. Optional final evaluation on selected benchmarks.
flowchart LR
  A[Calibration Dataset] --> B[Observer Statistics]
  B --> C[Evolutionary Search]
  C --> D[Best Layer-wise Pruning Plan]
  D --> E[Pruned MoE Checkpoint]
  E --> F[Evaluation and Reports]

Environment Setup

Minimal setup

# 1) Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# 2) Build environment from repo root
bash scripts/build.sh

# 3) Activate
source .venv/bin/activate

For Docker installation, refer to the original REAP repository:
CerebrasResearch/reap

For using free gpt-oss-120b api to evaluate on wildbench, acquire from here.

vLLM Integration

Upstream vLLM does not natively support checkpoints with a non-uniform number of experts per layer.
You can either:

  1. Evaluate with mask-based pruning (no structural expert removal), or
  2. Patch vLLM to support structurally pruned checkpoints.

To enable structural expert removal in vLLM:

  1. Place the vllm source under third-party/.
  2. Install vllm in editable mode.
  3. Apply the model implementations from src/reap/models/non_uniform/ for your target model family.

Usage Example

bash experiments/search-pruning-cli.sh 0 allenai/OLMoE-1B-7B-0125-Instruct reap 42 \
16 \
theblackcat102/evol-codealpaca-v1 \
allenai/tulu-3-sft-personas-math \
32 50 4 4 3 32 64 \
esp-dataset \
true true true true true \
false false \
false 0 false \
true true \
true true "" 64 0

Parameter Guide

The script experiments/search-pruning-cli.sh uses positional arguments.

Quick grouping

GroupPositionsPurpose
Runtime1-4GPU, model, pruning metric, random seed
Search budget/data5-15sparsity budget, calibration/search datasets, EA hyperparameters, fitness
Evaluation toggles16-20turn benchmark suites on/off
Routing/eval behavior21-27singleton control, lm-eval formatting, server mode, structural mode
Control flow28-33run search/eval, override dir, expert count for naming, resume/checkpoint
Full positional argument table
PosValue in exampleName in scriptMeaning
10CUDA_VISIBLE_DEVICESGPU device(s) to use. 0 means GPU 0.
2allenai/OLMoE-1B-7B-0125-Instructmodel_nameBase model checkpoint name.
3reappruning_methodExpert saliency/pruning metric used by search.
442seedRandom seed for reproducibility.
516int_sparsityInteger sparsity budget (experts pruned per layer baseline).
6theblackcat102/evol-codealpaca-v1dataset_nameCalibration/observer dataset used to collect pruning statistics.
7allenai/tulu-3-sft-personas-mathsearch_dataset_nameDataset used to score candidate plans in search.
832population_sizeNumber of candidate plans per generation.
950generationsNumber of evolutionary generations.
104topkNumber of top candidates kept each generation.
114mutation_max_deltaMax experts shifted in one mutation step.
123mutation_timesMutation attempts per offspring plan.
1332mutation_max_attemptsMax retries to create a valid mutation.
1464search_samples_per_categorySearch scoring sample count.
15esp-datasetfitnessFitness objective used by search.
16truerun_lm_evalRun lm-eval tasks after search.
17truerun_evalplusRun EvalPlus coding benchmarks.
18truerun_livecodebenchRun LiveCodeBench benchmarks.
19truerun_mathRun math evaluation tasks.
20truerun_wildbenchRun WildBench evaluation.
21falsesingleton_super_expertsKeep detected super-experts as singleton.
22falsesingleton_outlier_expertsKeep detected outlier experts as singleton.
23falselm_eval_apply_chat_templateApply tokenizer chat template in lm-eval.
240lm_eval_num_fewshotFew-shot count for lm-eval.
25falselm_eval_fewshot_as_multiturnFormat few-shot examples as multi-turn chat.
26trueuse_serverUse vLLM server backend for evaluation.
27truestructural_nonuniformUse structural non-uniform checkpoint output when supported.
28truerun_searchExecute search stage.
29truerun_final_evalExecute final evaluation stage.
30""pruned_dir_overrideOptional explicit pruned model directory to evaluate.
3164num_expertsExperts per layer used for ratio naming (int_sparsity / num_experts).
320search_resume_fromResume generation target (0 means from scratch).
33(not provided)search_checkpoint_everyCheckpoint interval during search (defaults to 10).

Outputs

Typical run artifacts are written under:

artifacts/<model_name>/<dataset_name>/pruned_models_searched/<run_name>/

Important files:

  • pruned_experts.json: pruned expert indices by layer
  • search_history.json: generation-by-generation search trace
  • search_metadata.json: run config and bookkeeping
  • nonuniform_plan.json: final selected layer-wise plan
  • eval_*: evaluation outputs

Acknowledgement

Built on top of the excellent REAP codebase:
REAP (Router-weighted Expert Activation Pruning) by Cerebras Research.

Contributors

ZongfangLiu

3 commits

ZongfangLiu/EvoESAP

EvoESAP: Non-Uniform Expert Pruning for Sparse MoE

5

stars

3

commits

Python

primary language

Mar 31, 2026

updated

README

EvoESAP: Non-Uniform Expert Pruning for Sparse MoE

Python PyTorch Transformers License


Contents

Overview

At a high level, EvoESAP runs:

  1. Observer data collection on calibration prompts.
  2. Evolutionary search over layer-wise pruning plans.
  3. Best-plan materialization (structural non-uniform or mask-based).
  4. Optional final evaluation on selected benchmarks.
flowchart LR
  A[Calibration Dataset] --> B[Observer Statistics]
  B --> C[Evolutionary Search]
  C --> D[Best Layer-wise Pruning Plan]
  D --> E[Pruned MoE Checkpoint]
  E --> F[Evaluation and Reports]

Environment Setup

Minimal setup

# 1) Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# 2) Build environment from repo root
bash scripts/build.sh

# 3) Activate
source .venv/bin/activate

For Docker installation, refer to the original REAP repository:
CerebrasResearch/reap

For using free gpt-oss-120b api to evaluate on wildbench, acquire from here.

vLLM Integration

Upstream vLLM does not natively support checkpoints with a non-uniform number of experts per layer.
You can either:

  1. Evaluate with mask-based pruning (no structural expert removal), or
  2. Patch vLLM to support structurally pruned checkpoints.

To enable structural expert removal in vLLM:

  1. Place the vllm source under third-party/.
  2. Install vllm in editable mode.
  3. Apply the model implementations from src/reap/models/non_uniform/ for your target model family.

Usage Example

bash experiments/search-pruning-cli.sh 0 allenai/OLMoE-1B-7B-0125-Instruct reap 42 \
16 \
theblackcat102/evol-codealpaca-v1 \
allenai/tulu-3-sft-personas-math \
32 50 4 4 3 32 64 \
esp-dataset \
true true true true true \
false false \
false 0 false \
true true \
true true "" 64 0

Parameter Guide

The script experiments/search-pruning-cli.sh uses positional arguments.

Quick grouping

GroupPositionsPurpose
Runtime1-4GPU, model, pruning metric, random seed
Search budget/data5-15sparsity budget, calibration/search datasets, EA hyperparameters, fitness
Evaluation toggles16-20turn benchmark suites on/off
Routing/eval behavior21-27singleton control, lm-eval formatting, server mode, structural mode
Control flow28-33run search/eval, override dir, expert count for naming, resume/checkpoint
Full positional argument table
PosValue in exampleName in scriptMeaning
10CUDA_VISIBLE_DEVICESGPU device(s) to use. 0 means GPU 0.
2allenai/OLMoE-1B-7B-0125-Instructmodel_nameBase model checkpoint name.
3reappruning_methodExpert saliency/pruning metric used by search.
442seedRandom seed for reproducibility.
516int_sparsityInteger sparsity budget (experts pruned per layer baseline).
6theblackcat102/evol-codealpaca-v1dataset_nameCalibration/observer dataset used to collect pruning statistics.
7allenai/tulu-3-sft-personas-mathsearch_dataset_nameDataset used to score candidate plans in search.
832population_sizeNumber of candidate plans per generation.
950generationsNumber of evolutionary generations.
104topkNumber of top candidates kept each generation.
114mutation_max_deltaMax experts shifted in one mutation step.
123mutation_timesMutation attempts per offspring plan.
1332mutation_max_attemptsMax retries to create a valid mutation.
1464search_samples_per_categorySearch scoring sample count.
15esp-datasetfitnessFitness objective used by search.
16truerun_lm_evalRun lm-eval tasks after search.
17truerun_evalplusRun EvalPlus coding benchmarks.
18truerun_livecodebenchRun LiveCodeBench benchmarks.
19truerun_mathRun math evaluation tasks.
20truerun_wildbenchRun WildBench evaluation.
21falsesingleton_super_expertsKeep detected super-experts as singleton.
22falsesingleton_outlier_expertsKeep detected outlier experts as singleton.
23falselm_eval_apply_chat_templateApply tokenizer chat template in lm-eval.
240lm_eval_num_fewshotFew-shot count for lm-eval.
25falselm_eval_fewshot_as_multiturnFormat few-shot examples as multi-turn chat.
26trueuse_serverUse vLLM server backend for evaluation.
27truestructural_nonuniformUse structural non-uniform checkpoint output when supported.
28truerun_searchExecute search stage.
29truerun_final_evalExecute final evaluation stage.
30""pruned_dir_overrideOptional explicit pruned model directory to evaluate.
3164num_expertsExperts per layer used for ratio naming (int_sparsity / num_experts).
320search_resume_fromResume generation target (0 means from scratch).
33(not provided)search_checkpoint_everyCheckpoint interval during search (defaults to 10).

Outputs

Typical run artifacts are written under:

artifacts/<model_name>/<dataset_name>/pruned_models_searched/<run_name>/

Important files:

  • pruned_experts.json: pruned expert indices by layer
  • search_history.json: generation-by-generation search trace
  • search_metadata.json: run config and bookkeeping
  • nonuniform_plan.json: final selected layer-wise plan
  • eval_*: evaluation outputs

Acknowledgement

Built on top of the excellent REAP codebase:
REAP (Router-weighted Expert Activation Pruning) by Cerebras Research.

Contributors

ZongfangLiu

3 commits

Languages

Python

93.6%

Shell

6.4%