docs: Phase 18 pipeline parallelism — design + benchmark results

docs/18-pipeline-parallelism.md: PP design (layer split, NCCL P2P,
per-stage KV, engine/threading model).
docs/benchmarks/pp-sweep.md: measured on dash5 (8x RTX 5090, Qwen3-8B
BF16) — single-stream latency + per-GPU VRAM (~1/N), byte-exact
correctness (single x2 vs pp4 x2 control), and the full AIME-30 +
GSM8K-30 quality matrix (xserv & llama.cpp PP=1/2/4): GSM8K 29/30 in
every cell, TPOT flat across PP.
README: multi-card (TP/PP) section + roadmap to Phase 18.
gitignore: /.claude/ runtime state.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-05-29 18:46:06 +08:00
parent d5dcf1a5ab
commit 11e0154e4d
4 changed files with 314 additions and 5 deletions

View File

@@ -144,16 +144,53 @@ HF_ENDPOINT=https://hf-mirror.com python3 -m tools.bench.fetch_datasets
- `docs/00-roadmap.md`:总体路线图与各 Phase 设计
- `docs/01..15-*.md`CUDA FFI / Tensor / GEMM / Attention / KV cache / 性能优化等每个 Phase 的设计文档
- `docs/16-llama-cpp-comparison.md`llama.cpp 对比基准的设计
- `docs/benchmarks/`:各阶段的 benchmark 报告
- `docs/17-tensor-parallelism.md`张量并行TP设计
- `docs/18-pipeline-parallelism.md`流水线并行PP设计
- `docs/benchmarks/`:各阶段的 benchmark 报告(含 `pp-sweep.md`
## 多卡并行TP / PP
单机多卡,复用 NCCLcrate `xserv-distributed`)。两种切法正交、二选一:
- **张量并行 `--tp N`**:按 head / 中间维切每一层,层内用 AllReduce 聚合(每 token `2·层数` 次)。
- **流水线并行 `--pp N`**:按层切成 N 段,相邻段间用 NCCL **P2P** 传 hidden state每 token 仅 `N-1` 次),
通信量远小于 AllReduce对无 NVLink 的 PCIe 更友好。
```bash
# 组内 GPU 0-34 卡张量并行 / 4 卡流水线并行
CUDA_VISIBLE_DEVICES=0,1,2,3 ./target/release/xserv-server /path/to/qwen3-8b --tp 4
CUDA_VISIBLE_DEVICES=0,1,2,3 ./target/release/xserv-server /path/to/qwen3-8b --pp 4
```
**PP 实测**dash5Qwen3-8B BF16单流贪心每卡显存为权重+最小 KV 池):
| 配置 | TTFT | TPOT | tok/s | 每卡显存 |
|------|------|------|-------|----------|
| 单卡 | 33ms | 17.4ms | 57.5 | 24.0 GB |
| PP=2 | 36ms | 18.1ms | 55.3 | 11.6 / 13.6 GB |
| PP=4 | 36ms | 17.9ms | 55.8 | 7.3 / 5.3 / 5.3 / 9.4 GB |
**质量对比**AIME 2025 30 题 + GSM8K 30 题贪心xserv 在 GPU 0-3、llama.cpp 在 GPU 4-7 并行):
| 引擎 | PP | AIME | GSM8K |
|------|----|------|-------|
| xserv | 1/2/4 | 8 / 7 / 7 (/30) | 29/30 (96.7%) 全部一致 |
| llama | 1/2/4 | 7 / 7 / 7 (/30) | 29/30 (96.7%) 全部一致 |
正确性hidden state 跨段是 **bit-exact BF16 P2P 拷贝**PP=4 输出与单卡逐字节一致用「单卡×2 vs
PP=4×2」对照确认——单卡自身因 cuBLAS 非确定性 run-to-run 会变,而 PP=4 可复现且落在某次单卡轨迹上)。
GSM8K 12 个格子全是 29/30xserv 与 llama.cpp 完全一致AIME 的 ±1 是长生成下贪心对 GEMM 抖动的敏感,
非 PP 或引擎效应。**收益在显存**(每卡权重+KV ≈ 1/Nv1 为串行流水线,单流 TPOT 基本持平、不优于单卡,
真正的吞吐提升需后续做 microbatch / 1F1B 重叠。完整数据见 `docs/benchmarks/pp-sweep.md`
## 路线图(节选)
已完成 Phase 015CUDA 基础设施 → Tensor → GEMM → Transformer kernels → Attention →
已完成 Phase 018CUDA 基础设施 → Tensor → GEMM → Transformer kernels → Attention →
模型加载 → 分词器 → GPT-2 → KV cache → Qwen3-8B → Paged Attention → 连续批处理 →
HTTP API → Flash Attention 2 → 性能优化;并在此基础上加入了 **llama.cpp 对比基准**
**KV CPU 换出** 等基础设施。
HTTP API → Flash Attention 2 → 性能优化**张量并行TP****流水线并行PP**
并加入了 **llama.cpp 对比基准** **KV CPU 换出** 等基础设施。
后续方向:投机解码speculative decoding、张量并行TP多卡、量化FP8 / INT8、多模态。
后续方向:PP microbatch/1F1B 流水线重叠吞吐收益、2D TP×PP、投机解码、量化FP8 / INT8、多模态。
## 许可