DEV Community

Prabhakar Chaudhary
Prabhakar Chaudhary

Posted on

KEEP: Dynamic Expert Sparsification for Memory-Constrained MoE Serving

Sparsely-gated Mixture-of-Experts (MoE) models have become the go-to architecture for open-weight Large Language Models (LLMs) because they keep inference compute low: a 749-billion-parameter model like DeepSeek-V4.1-Flash activates only 17.2 billion parameters per token. The catch for developers trying to self-host these models is memory. Even when most weights sit idle on any given forward pass, every routed expert still has to live in Graphics Processing Unit (GPU) Video Random-Access Memory (VRAM) or stream slowly over Peripheral Component Interconnect Express (PCIe) and Solid-State Drives (SSDs). A recent paper from TU Wien and the Institute of Science and Technology Austria (ISTA) introduces KEEP (Keep the Experts), an algorithm-and-runtime co-design that dynamically picks which experts to keep per prompt, pushing expert sparsity up to 75% while preserving over 90% of dense quality and boosting decode throughput up to 3x.

Why Static Expert Pruning Breaks Past 50%

In a standard MoE layer with K routed experts, a learned router picks the top-k experts for each token x, assigns normalized gating weights g_j(x), and sums their weighted outputs. To shrink these models without retraining, earlier methods like Router-weighted Expert Activation Pruning (REAP) and SlimWise compute an average saliency score per expert—roughly the gating weight multiplied by the expert's Euclidean (L2) output norm—over a calibration dataset, then permanently drop the lowest-scoring experts.

That static approach hits a wall at 50% sparsity. Below 50% removal, models hold up reasonably well; beyond it, quality collapses or narrows to whatever domain dominated the calibration set. The KEEP authors pin down why: expert importance is tightly concentrated within a single prompt, yet varies sharply across prompts and domains. On Qwen3.6-35B-A3B, Qwen3.8-Flash-Next, and DeepSeek-V4.1-Flash, the top 25% highest-saliency experts for one prompt capture 84–94% of total saliency, and the top 50% capture 96–99%. Lock in one global top-50% subset across domains, however, and coverage drops to 88–95%—while experts calibrated on a single domain can fall as low as 52% saliency on out-of-distribution tasks.

When static pruning fails at 75% sparsity, it also breaks stopping behavior. Across the paper's test suite, DeepSeek-V4.1-Flash generates 22 million tokens when run dense, and 23–26 million tokens with KEEP at 50–75% sparsity. Under static REAP and SlimWise at 75% sparsity, generated tokens explode to 437 million (+1,886%) and 377 million (+1,614%) as models loop and ramble.

Prefill Experts Aren't Decode Experts

If expert importance is prompt-specific, the obvious shortcut is to run prefill on the input prompt, log which experts fired most often, and keep only those experts for decoding. KEEP shows that this naive heuristic leaves major accuracy on the table because prefill and decoding rely on surprisingly different experts.

Across all three tested MoEs, the overlap between the top 25% highest-saliency experts in prefill and the top 25% in decoding is only 57–59%. Even at the top 50% threshold, overlap sits at 69–72%. Simply copying prefill winners into the decode pool fails to recover the experts that actually drive token generation.

Instead of trusting raw prefill saliency, KEEP treats prefill routing as a predictive signal. Offline, the authors run a calibration mix of 3,584 prompts across math, competitive programming, agentic coding, function calling, general knowledge, and creative writing. For each prompt and layer, they record the prefill expert activation rates r_p and normalized decoding saliency s_p, then fit a compact K x K linear matrix T via ridge regression to minimize ||sqrt(s_p) - r_p * T||_2^2 + lambda * ||T||_F^2. At serving time, KEEP needs no auxiliary neural encoders and changes zero backbone weights: right after prefill finishes, one tiny matrix multiply predicts which experts will matter during decoding for that exact prompt, masking out the rest.

Three-Tier Memory Co-Design: VRAM, Host RAM, and Disk

Dropping 50–75% of experts per request only speeds up inference if the serving engine turns smaller active sets into lower memory traffic. The authors co-designed the KEEP runtime on top of FreeToken, managing a three-tier memory hierarchy: GPU VRAM, pinned host Random-Access Memory (RAM), and disk storage.

The shared model skeleton and Key-Value (KV) cache live permanently in GPU VRAM, while the full expert pool sits in pinned host RAM—or spills to disk when host RAM is too small. During prefill, KEEP runs the full model without pruning so the initial KV cache stays exact. To hide host-to-device transfer stalls, it uses double-buffered prefill: while the GPU runs grouped General Matrix Multiply (GEMM) kernels on layer l in one buffer, it asynchronously streams layer l+1 experts into a second buffer over PCIe.

Once prefill finishes and the ridge predictor selects the prompt's retained experts, KEEP places that kept set inside GPU VRAM or across GPU VRAM plus pinned host RAM. Decoding never reads from disk. A Least Recently Used (LRU) cache keeps hot experts on the GPU, fetching misses solely from fast pinned host memory. Because the ridge predictor transfers cleanly across precisions, developers can also pair KEEP with low-bit quantization for tighter hardware budgets.

Benchmarks: Accuracy, Runaway Tokens, and Throughput

Evaluated on Qwen3.6-35B-A3B (34.7B total, 3.5B active), Qwen3.8-Flash-Next (176.9B total, 7.3B active), and DeepSeek-V4.1-Flash (748.9B total, 17.2B active), KEEP retains at least 99% of dense accuracy at 50% sparsity across MATH-500, graduate science (GPQA-D), MMLU-Pro, HumanEval+, and MBPP+. On agentic coding and tool-use benchmarks—SWE-Bench Verified and the Berkeley Function Calling Leaderboard v4 (BFCL-v4)—Qwen3.8-Flash-Next with KEEP is lossless at 50% sparsity and loses only 2 points at 65%. At 75% sparsity, KEEP preserves 90–97% of dense quality across all three models.

On systems ranging from an RTX 5090 desktop (32 GB VRAM, 62 GiB RAM) to dual-EPYC RTX 3090 and B200 servers, KEEP adds negligible prefill overhead while lifting decoding throughput by up to 3x over FreeToken and llama.cpp. Better yet, for large MoEs that cannot fit under FreeToken at all, KEEP trims the active decode footprint enough to run smoothly across GPU and host RAM.

Takeaways for Deploying MoE Models

For engineers building local or cost-sensitive inference stacks, KEEP makes a strong case that prompt-conditioned pruning beats static one-size-fits-all compression. Running prefill at full capacity while dynamically predicting decode-time experts recovers nearly lossless quality on workstation hardware. The main open question is how per-prompt expert sets will interact with continuous multi-request batching, where concurrent users in a single batch need different—and sometimes conflicting—subsets of experts. Implementation updates are tracked in the IST-DASLab keep-engine repository.

Sources

Top comments (0)