专家负载均衡 (EPLB)#

概述#

在 LLM 推理服务中,MoE 模型的专家均衡对于实现最优性能至关重要。由于“全局停顿 (stop-the-world)”操作的存在,在推理过程中动态更改专家可能会对 TTFT(首词元延迟)和 TPOT(每输出词元延迟)产生负面影响。SwiftBalancer 实现了异步专家负载均衡,具备零开销的专家迁移能力,确保了服务的无缝连续性。

EPLB 效果#

  • 降低延迟:通过在专家之间均匀分配工作负载,动态平衡专家负载,从而最小化 TTFT 和 TPOT。

  • Enhanced Throughput: Optimizes NPU utilization, increasing token generation speed under high-concurrency scenarios.

  • 零开销迁移:专家重分布过程异步进行,不会中断正在进行的推理请求。

  • 自适应缩放:自动调整以应对工作负载波动,同时保持性能稳定。

  • 容错性:冗余的专家放置策略确保了系统在硬件故障时的恢复能力。

支持场景#

模型#

DeepSeekV3/V3.1/R1, Qwen3-MoE

MoE 量化类型#

QuantType

Supported Hardware

W8A8 / W8A8-Dynamic

A2, A3, Ascend 950 Products

W4A8 (with fused MC2 enabled)

A2, A3, Ascend 950 Products

MXFP4

Ascend 950 Products

MXFP8

Ascend 950 Products

如何使用 EPLB#

EPLB has three usage modes:

Mode

Config in eplb_config

Env Variable

Dynamic EPLB

dynamic_eplb: true

DYNAMIC_EPLB=true

Recording (generate expert map)

expert_map_record_path

DYNAMIC_EPLB=true or EXPERT_MAP_RECORD=true

Static EPLB (load pre-recorded map)

expert_map_path

none required

[!IMPORTANT] For Dynamic EPLB and Recording modes, the env variable acts as a safety guard: setting dynamic_eplb: true in config alone is not enough — the assertion requires DYNAMIC_EPLB=true or EXPERT_MAP_RECORD=true. Static EPLB (loading a pre-recorded map via expert_map_path) does not require an env variable.

动态 EPLB#

需要添加环境变量 export DYNAMIC_EPLB="true" 来启用 vLLM 的 EPLB 功能。通过自动调优的参数启用动态平衡。根据工作负载模式调整 expert_heat_collection_intervalalgorithm_execution_interval。在当前版本中,建议使用以下策略:swift balancer(2)。

vllm serve Qwen/Qwen3-235B-A22 \
  --tensor-parallel-size 16 \
  --enable-expert-parallel \
  --additional-config '{ "eplb_config": {
    "dynamic_eplb": true,
    "expert_heat_collection_interval": 600,
    "algorithm_execution_interval": 50,
    "eplb_policy_type": 2,
    "num_redundant_experts": {ep_size},
    }}'

EPLB Policy Types#

The eplb_policy_type parameter selects the balancing algorithm used during dynamic expert redistribution:

Value

Policy

Description

0

Random

Randomly swaps experts between ranks. Suitable for basic testing only.

1

DefaultEplb

Open-source EPLB algorithm. Adds redundant experts to the hottest, packs via balanced assignment with local constraint exchange.

2

SwiftBalanceEplb

Optimized for low-bandwidth environments. Supports intra-node and inter-node expert redundancy, joint optimization of expert placement. (Recommended)

3

FlashLB

Statistical method using sliding-window mean/variance/covariance of expert loads. Uses FlashTree layered search for optimal replica allocation and minimize_redeploy for incremental adjustment. Best for high-frequency load fluctuations.

静态 EPLB#

初始设置(记录专家映射表)#

需要添加环境变量 export EXPERT_MAP_RECORD="true" 来记录专家映射表。使用 expert_map_record_path 生成初始专家分布图。这为未来的部署创建了基准配置。

vllm serve Qwen/Qwen3-235B-A22 \
  --tensor-parallel-size 16 \
  --enable-expert-parallel \
  --additional-config '{ "eplb_config": {
    "expert_map_record_path": "/path/to/eplb.json",
    "num_redundant_experts": 16,
    "expert_heat_collection_interval": 400,
    "algorithm_execution_interval": 30
  }}'

后续部署(使用已记录的映射表)#

加载预先记录的专家映射表以获得一致的性能。这避免了在运行时重新计算分布。

vllm serve Qwen/Qwen3-235B-A22 \
  --tensor-parallel-size 16 \
  --enable-expert-parallel \
  --additional-config '{
    "eplb_config": {"expert_map_path": "/path/to/eplb.json"}
  }'

关键注意事项#

  1. 参数调优:

    • expert_heat_collection_interval:对于稳定的工作负载,建议使用较高值(如 400+);对于波动的流量,建议使用较低值(如 100-200)。

    • algorithm_execution_interval:应 ≥ 30,以避免在启动阶段过早进行平衡。

    • num_redundant_experts: Must match tensor-parallel size (e.g., 16 for 16 NPUs) to ensure sufficient redundancy.

  2. 硬件要求:

    • Ensure that all NPUs have identical memory capacity and compute capabilities.

    • 网络带宽必须支持专家重分布的流量(建议 ≥ 10 Gbps)。

  3. 模型兼容性:

    • 仅支持具有显式专家并行支持的 MoE 模型(如 Qwen3 MoE 模型)。

    • 通过 --enable-expert-parallel 验证模型架构是否支持动态专家路由。

  4. 监控与验证:

    • Track metrics: expert_load_balance_ratio, ttft_p99, tpot_avg, and npu_utilization.

    • 使用 vLLM monitor 检测运行时的不平衡情况。

    • 加载前务必验证专家映射表的 JSON 结构(使用 jq 或类似工具验证)。

  5. 启动行为:

    • 在第一个平衡周期内(通常为 1-2 分钟),初始请求可能会经历较高的延迟。

    • 避免在预热阶段出现突发流量高峰。

  6. 常见陷阱:

    • Incorrect tensor-parallel-size vs. actual NPU count → causes resource underutilization.

    • 在未生成映射表的情况下使用 expert_map_path → 导致运行时错误。

    • Setting num_redundant_experts > available NPUs → system failure.