跳转至

专家并行负载均衡器 (EPLB)

概述

在LLM(大语言模型)服务中,对MoE(混合专家)模型进行专家均衡对于实现最佳性能至关重要。由于stop-the-world操作,推理过程中动态变更专家会对TTFT(首Token时间)和TPOT(每输出Token时间)产生负面影响。我们的解决方案旨在最小化该操作带来的负面影响。

EPLB效果

  • 降低延迟:通过将工作负载均匀分布到各专家,动态均衡专家负载以最小化TTFT和TPOT。
  • 自适应扩展:自动适应工作负载波动,同时保持稳定的性能。

支持场景

模型

All MOE models supported by vLLM-Ascend. But we have only verified the performance on deepseek-v3.1/r1 models.

MOE量化类型

量化类型 支持硬件
W8A8 / W8A8-Dynamic A2, A3
W4A8(启用融合MC2) A2, A3
MXFP4 昇腾950系列产品
MXFP8 昇腾950系列产品

如何使用EPLB

EPLB有三种使用模式:

模式 eplb_config配置 环境变量
动态EPLB dynamic_eplb: true DYNAMIC_EPLB=true
记录模式(生成专家映射) expert_map_record_path DYNAMIC_EPLB=trueEXPERT_MAP_RECORD=true
静态EPLB(加载预记录映射) expert_map_path 无需设置

[!IMPORTANT] For 动态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=trueEXPERT_MAP_RECORD=true. 静态EPLB (loading a pre-recorded map via expert_map_path) does not require an env variable.

动态EPLB

需要添加环境变量export DYNAMIC_EPLB="true"以启用vLLM-Ascend EPLB。使用自动调优参数启用动态均衡。根据工作负载模式调整expert_heat_collection_interval和algorithm_execution_interval。在当前版本中,建议使用以下策略:swift balancer(2)。

参数 描述 默认值
dynamic_eplb 启用动态EPLB。 False
expert_heat_collection_interval 收集专家热度的间隔。 600
algorithm_execution_interval 执行均衡算法的间隔。 50
eplb_policy_type EPLB策略类型。 2
num_redundant_experts 冗余专家数量。 0
graph TB
   A[start] --> B(collect_heat)
   B --> C(execute_algorithm)
   C --> D(update_layer one by one)
   D --> B
   D --> F[termination upon service termination]
# D node or colocation
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": 16
    }}'

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

EPLB策略类型

eplb_policy_type参数选择动态专家重分配期间使用的均衡算法:

策略 描述
0 随机 在rank之间随机交换专家。仅适用于基础测试。
1 默认值Eplb 开源EPLB算法。向最热的专家添加冗余,通过带局部约束交换的均衡分配进行打包。
2 SwiftBalanceEplb 针对低带宽环境优化。支持节点内和节点间专家冗余,联合优化专家放置。(推荐)
3 FlashLB 统计方法,使用专家负载的滑动窗口均值/方差/协方差。使用FlashTree分层搜索进行最优副本分配,使用minimize_redeploy进行增量调整。最适合高频负载波动场景。

静态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. 参数调优:
  2. expert_heat_collection_interval:稳定工作负载使用较大值(如600+);波动流量使用较小值(如50-100)。
  3. algorithm_execution_interval:应≥50,以避免启动期间过早均衡。
  4. num_redundant_experts:必须满足(num_experts + num_redundant_experts)能被专家并行度整除。

  5. 硬件要求:

  6. 确保所有NPU具有相同的内存容量和计算能力。
  7. 网络带宽必须支持专家重分配流量(建议≥10 Gbps)。

  8. 监控与验证:

  9. 跟踪指标:在日志中搜索[Expert Hotness],我们将计算不同rank上每层负载的峰值均值比,然后找出其平均值和最大值。Current表示实际峰值均值比,update表示算法调整后的预估峰值均值比。
  10. 使用vLLM监控器在运行时检测负载不均衡。
  11. 加载前务必验证专家映射JSON结构(使用jq或类似工具进行验证)。