Skip to main content

Overview

Expert Parallelism (EP) distributes expert weights across multiple devices in Mixture-of-Experts (MoE) models. This addresses memory bottlenecks for large-scale MoE models where tokens are dynamically routed to specialized experts across GPUs.

Key Benefits

  • Reduced memory footprint per GPU by sharding expert weights
  • Higher throughput with optimized all-to-all communication
  • Better scalability for models with 100+ experts
  • Load balancing to minimize GPU utilization variance

When to Use Expert Parallelism

Use EP for:
  • Mixture-of-Experts models (DeepSeek, Mixtral, Qwen-MoE)
  • Models with 64+ experts that don’t fit on a single GPU
  • Large-scale deployments requiring maximum throughput
Typical EP models:
  • DeepSeek-V2, DeepSeek-V3, DeepSeek-R1
  • Mixtral-8x7B, Mixtral-8x22B
  • Qwen2-57B-A14B, Qwen3-235B-A22B

Architecture

How EP Works

In a typical MoE layer with EP:
  1. Token Routing: Each token is routed to top-K experts based on gating scores
  2. All-to-All Dispatch: Tokens are shuffled across GPUs to their assigned experts
  3. Expert Computation: Each GPU processes its local expert subset
  4. All-to-All Combine: Results are gathered back to original token positions

Configuration

Basic Setup

Key parameters:
  • --tp: Tensor parallel size (intra-node parallelism)
  • --ep: Expert parallel size (typically equals tp)
  • --moe-a2a-backend: All-to-all communication backend
  • --moe-runner-backend: Expert computation backend

Multi-Node Setup

Communication Backends

All-to-All Backends (--moe-a2a-backend)

DeepEP Dispatch Modes

DeepEP supports two dispatch modes:
  • normal: Optimized for prefill workloads (high throughput)
  • low_latency: Optimized for decode workloads (low latency, CUDA Graph compatible)
Recommended setup:

MoE Runner Backends (--moe-runner-backend)

Advanced Features

Two-Batch Overlap (TBO)

TBO splits requests into micro-batches, interleaving attention with dispatch/combine operations:
Benefits:
  • Up to 2× throughput improvement
  • Hides communication latency behind computation
  • No peak memory increase
Implementation:
Details: Large-Scale EP Blog - TBO Section

Single-Batch Overlap (SBO)

SBO enables overlapping operations within a single batch (e.g., shared experts with communication):
Uses dispatcher-hook system for modularity. See PR #13327.

Expert Parallelism Load Balancer (EPLB)

EPLB addresses routing imbalances by analyzing expert activation statistics:
How it works:
  1. Collects expert activation statistics during inference
  2. Computes optimal expert arrangement to minimize variance
  3. Strategically places or replicates experts across GPUs
  4. Reduces idle cycles and improves load balance
Tuning:
  • Increase batch sizes for stable statistics
  • Configure periodic rebalancing (e.g., every 1000 requests)
  • Monitor load balancedness ratio (mean/max computation time)
Details: EPLB Repository

Hardware-Specific Configuration

NVIDIA GPUs

Standard setup:
Blackwell (B100/B200) with FP4:

AMD GPUs (ROCm)

Note: MORI backend only supports normal mode currently.

Huawei Ascend NPUs

Prefill instance:
Decode instance:
DeepEP Ant-moving Function (for long sequences on Ascend):
Buffer size calculation:

Combining with Other Parallelism

EP + TP

Most common combination:

EP + DPA (Data Parallelism Attention)

For MLA-based MoE models like DeepSeek:
See Data Parallelism for DPA details.

EP + PP (Pipeline Parallelism)

For very large models:

EP + Speculative Decoding

For speculative decoding with different precisions:

Performance Tuning

Tuning Triton Backend

For custom kernel optimization:
See Triton MoE Tuning Guide.

Extending the EP Framework

SGLang’s EP framework is highly modular and extensible:

Architecture

Adding New Backends

For new all-to-all dispatcher:
  1. Implement BaseDispatcher subclass with dispatch and combine methods
  2. Register via --moe-a2a-backend
For new MoE runner:
  1. Define MoeRunnerCore subclass for grouped GEMMs
  2. Register permute methods:
    • Fused mode (static, torch.compile-compatible): register_fused_func
    • Permute mode (dynamic): register_pre_permute and register_post_permute
  3. Register via --moe-runner-backend
See:

Troubleshooting

Communication Backend Not Working

Symptom: Error initializing DeepEP/Mooncake Solution: Check backend constraints:

Poor Load Balance

Symptom: High variance in GPU utilization Solution: Enable EPLB and increase batch size:

Low Throughput

Symptom: Lower than expected throughput Solution: Enable overlap optimizations:

Best Practices

  1. Set ep == tp for DeepEP/Mooncake backends
  2. Use --deepep-mode auto for automatic dispatch mode switching
  3. Enable TBO for maximum throughput (up to 2× improvement)
  4. Enable EPLB with large batch sizes for better load balance
  5. Monitor expert activation patterns to understand routing behavior
  6. Combine with DPA for MLA-based MoE models

Configuration Summary