[Feature] Dynamic Prefill Context Parallelism
Checklist
- If this is not a feature request but a general question, please start a discussion at https://github.com/sgl-project/sglang/discussions. Otherwise, it will be closed.
- Please use English. Otherwise, it will be closed.
Motivation
Summary
--enable-prefill-cp is a static, server-lifetime switch: once it is on, every prefill batch goes through CP. But CP is only profitable above a certain sequence length. On a DSA model (GLM-5.2-FP8, --attention-backend dsa, --cp-strategy zigzag, attn_cp_size=4) we measured TTFT 15–21% worse for every request shorter than ~4K tokens, break-even at ~8K.
Long-context serving traffic is never uniformly long. A deployment sized for 128K requests also receives short chats, short tool-call turns, and short follow-ups on a cached prefix, and today every one of them pays the CP tax. The only workaround is to stand up a second CP-disabled deployment and route by length at the gateway, which doubles the prefill footprint just to avoid a per-request regression.
Request: make prefill CP dynamic — decide per forward batch, at runtime, whether to run that batch under CP, instead of deciding once at server startup. A CP-enabled long-context deployment should be able to serve short requests at non-CP latency.
Measured data
Single-request TTFT (ms), one request in flight, 20 measured runs per length after warmup requests. Both groups are the same 1P1D deployment on the same node; the only difference is --enable-prefill-cp --cp-strategy zigzag on the prefill server.
| input_len | CP mean | non-CP mean | Δ (CP vs non-CP) |
|---|---|---|---|
| 64 | 371.0 | 306.2 | +21.2% |
| 128 | 357.5 | 299.3 | +19.4% |
| 256 | 359.8 | 311.6 | +15.5% |
| 512 | 360.7 | 300.6 | +20.0% |
| 1024 | 366.3 | 306.0 | +19.7% |
| 2048 | 347.1 | 303.1 | +14.5% |
| 4096 | 351.7 | 334.8 | +5.1% |
| 8192 | 402.7 | 403.5 | −0.2% |
| 12288 | 422.1 | 545.9 | −22.7% |
| 16384 | 503.2 | 709.7 | −29.1% |
| 20480 | 601.9 | 875.4 | −31.3% |
| 24576 | 658.2 | 1004.2 | −34.5% |
| 28672 | 800.3 | 1210.9 | −33.9% |
| 32768 | 857.1 | 1333.3 | −35.7% |
Positive = CP is slower.
Related resources
Source: sgl-project/sglang