add moe bucket profiling and record bottlenecks
This commit is contained in:
@@ -1194,3 +1194,54 @@ _PROF_TRACE = os.environ.get("PROF_TRACE", "0") == "1"
|
||||
2. 拆分 `MLP` 时间中 routed expert、shared expert、TP all-reduce 的占比。
|
||||
3. 若 all-reduce 占比高,测试 `--disable-custom-all-reduce` 保持关闭/打开的差异和 TP 通信路径。
|
||||
4. 若 routed expert 占比高,继续优化 `_native_experts_sorted` 中逐 expert 循环和 `index_add_`。
|
||||
|
||||
## 2026-07-15:MoE 聚合 profiling
|
||||
|
||||
### 改动
|
||||
|
||||
在 `qwen3_5.py` 增加默认关闭的聚合 profiling:
|
||||
|
||||
- `PROF_MOE_SUMMARY=1` 开启;
|
||||
- `PROF_MOE_SYNC=1` 时每段前后 `torch.cuda.synchronize()`,用于获得更可信的 GPU 段时间;
|
||||
- `PROF_MOE_INTERVAL` 控制每多少次 MoE forward 输出一次汇总;
|
||||
- 分桶输出 `bucket=decode` (`T=1`) 与 `bucket=prefill` (`T>1`)。
|
||||
|
||||
默认 benchmark 不开启这些变量,因此生产路径不受影响。
|
||||
|
||||
### 归档
|
||||
|
||||
- `worklogs/remote_results/2026-07-15-official-like-baseline/eager_100k_b16384_moe_profile_r2_t256_cap40k.json`
|
||||
- `worklogs/remote_results/2026-07-15-official-like-baseline/driver_moe_profile.log`
|
||||
- `worklogs/remote_results/2026-07-15-official-like-baseline/moe_summary_profile.log`
|
||||
- `worklogs/remote_results/2026-07-15-official-like-baseline/eager_100k_b16384_moe_bucket_profile_r2_t256_cap40k.json`
|
||||
- `worklogs/remote_results/2026-07-15-official-like-baseline/driver_moe_bucket_profile.log`
|
||||
- `worklogs/remote_results/2026-07-15-official-like-baseline/moe_bucket_summary_profile.log`
|
||||
|
||||
### 关键结果
|
||||
|
||||
bucket 分桶的最终平均值如下。数值是每个 worker 进程最终 summary 的均值,单位为 ms / MoE layer call。
|
||||
|
||||
| Bucket | router gate | routed expert | shared expert | all-reduce | total |
|
||||
| --- | ---: | ---: | ---: | ---: | ---: |
|
||||
| decode (`T=1`) | 0.069 | 0.768 | 0.235 | 0.333 | 1.416 |
|
||||
| prefill (`T>1`) | 0.577 | 77.970 | 2.078 | 4.177 | 84.814 |
|
||||
|
||||
占比:
|
||||
|
||||
| Bucket | router gate | routed expert | shared expert | all-reduce |
|
||||
| --- | ---: | ---: | ---: | ---: |
|
||||
| decode | 4.9% | 54.2% | 16.6% | 23.5% |
|
||||
| prefill | 0.7% | 91.9% | 2.4% | 4.9% |
|
||||
|
||||
### 结论
|
||||
|
||||
MoE routed expert 是最明确主瓶颈:
|
||||
|
||||
- 对 TTFT/prefill:routed expert 占 MoE 时间约 92%,优先级最高。
|
||||
- 对 Output TPS/decode:routed expert 仍是最大项,约 54%;all-reduce 约 23%,属于第二优先级。
|
||||
|
||||
下一步优先做 routed expert 路径优化:
|
||||
|
||||
1. decode `T=1` 路径尝试使用 `ixformer.functions.act_bias_mm + silu_and_mul` 替换 `F.linear + torch` 激活,保留 bmm down projection。
|
||||
2. prefill `_native_experts_sorted` 重点减少逐 expert Python loop / 小 kernel 串行开销;需要查 ixformer 是否提供 grouped GEMM 类接口。
|
||||
3. all-reduce 暂时不是第一主因,但 decode 中占 23%,后续可独立测通信路径。
|
||||
|
||||
Reference in New Issue
Block a user