跳转至

动态分块流水线并行

Note

设计细节和数学模型请参见设计文档。部署教程请参见动态分块流水线并行教程

概述

动态分块流水线并行(CPP)是一种基于性能分析的动态分块策略,用于优化流水线并行(PP)场景中长序列的预填充性能。

使用场景

  • 变长序列服务:PP对短序列不会引入性能退化,并通过长序列的动态分块获得收益。
  • 超长序列推理:对于超出单机内存容量的序列(如1M tokens),动态分块可显著减少流水线空闲时间。

支持场景

目前CPP主要专注于预填充阶段的优化,建议在PD分离场景中使用。支持的功能如下:

Eager Graph 前缀
缓存
分块
预填充
CPP

启用方法

在线服务

vllm serve <model_path> \
    --pipeline-parallel-size 2 \
    --enable-chunked-prefill \
    --additional-config '{"profiling_chunk_config": {"enabled": true}}'

离线推理

from vllm import LLM

llm = LLM(
    model="<model_path>",
    pipeline_parallel_size=2,
    additional_config={"profiling_chunk_config": {"enabled": True}},
)

配置参数

参数 类型 默认值 描述
enabled bool False 启用/禁用动态分块流水线并行
smooth_factor float 1.0 平滑因子(0 < x ≤ 1.0),值越大越信任动态预测
min_chunk int 4096 动态计算的最小分块大小
need_timing bool True 启用/禁用在线校准
max_fit_chunk int 30 在线校准的分块时间数据数量

参数调优

  • smooth_factor:控制对动态预测的信任程度
    • 1.0:严格遵循模型预测
    • 0.6~0.85:平衡动态调整与调度开销
    • 0.0:无动态调整(退化为固定分块)
  • min_chunk:通常无需调整,应小于max-num-batched-tokens

推荐设置

max-num-batched-tokens

值得注意的是,CPP的TTFT对max-num-batched-tokens(视为动态求解的初始分块大小)非常敏感。 因为如果设置过大,会引入显著的计算空洞;如果设置过小,则会导致算子效率下降。为给动态调整留出足够空间,建议处理的序列越长,max-num-batched-tokens设置越大。推荐值:

序列长度 max-num-batched-tokens
64k 20480
128k 32768

在线校准

为获得最佳性能,建议在生产前使用真实数据进行在线校准:

可使用aisbench生成固定长度的随机数据集,详情请参见使用AISBench进行性能评估

  1. 修改<YOUR_AISBENCH_PATH>/benchmark/ais_bench/datasets/synthetic/synthetic_config.py

    synthetic_config = {
        "Type": "string",
        "RequestCount": 5,
        "TrustRemoteCode": False,
        "StringConfig": {
            "Input": {
                "Method": "uniform",
                "Params": {"MinValue": 131072, "MaxValue": 131072}  # Your max sequence length, max-model-len
            },
            "Output": {
                "Method": "uniform",
                "Params": {"MinValue": 1, "MaxValue": 1}
            }
        },
    }
    
  2. Run for online calibration:

    ais_bench --models vllm_api_stream_chat --datasets synthetic_gen --mode perf --debug
    

Configure online calibration data length to match your max-model-len. Use batch_size=1 and ensure data differs to avoid cache hits if prefix caching is enabled.

Performance

Refer to Using AISBench for performance evaluation for details.

To evaluate the effectiveness of Dynamic Chunked Pipeline Parallel in long sequence LLM inference scenarios, we use DeepSeek-V3.1-W8A8 and Qwen3-235B, deploy P instance in Ascend Atlas A3 inference products*64G (A3), the configuration and performance data are as follows.

Fixed-length requests, concurrency=1:

  • DeepSeek-V3.1-W8A8:

    Configuration CPP
    (Dynamic Chunk,
    chunksize=32k)
    PP
    (Static Chunk,
    chunksize=32k)
    Input length 128k TTFT: 22.5s TTFT: 27.0s
  • Qwen3-235B:

    Configuration CPP
    (Dynamic Chunk,
    chunksize=32k)
    PP
    (Static Chunk,
    chunksize=32k)
    Input length 256k TTFT: 53.5s TTFT: 61.4s

Variable-length requests, concurrency=4:

  • DeepSeek-V3.1-W8A8:

    Configuration 4k~64k Input, mean=32k, std=32k
    prefix hit rate=99%
    CPP2TP8 Input throughput: 22424 tps/card
    DP2TP8 Input throughput: 16150 tps/card
    PCP2TP8 Input throughput: 18197 tps/card
    TP16 Input throughput: 18875 tps/card

Constraints

  • Pipeline Parallelism Required: --pipeline-parallel-size > 1
  • Chunked Prefill Required: --enable-chunked-prefill
  • Incompatible with Balance Scheduling: Cannot enable VLLM_ASCEND_BALANCE_SCHEDULING
  • 启动开销:性能分析增加约64次前向传播(数十秒)