Skip to main content

Overview

Pipeline Parallelism (PP) distributes model layers across multiple nodes, enabling efficient processing of ultra-long context sequences. Unlike Tensor Parallelism which requires frequent all-reduce operations, PP only communicates at layer boundaries, achieving better computation-communication overlap for multi-node deployments.

Why Pipeline Parallelism?

As LLMs scale toward trillion-parameter architectures and “infinite” context windows, serving infrastructure must evolve:
  • Long context bottleneck: Ultra-long sequences create prohibitive Time to First Token (TTFT)
  • Multi-node communication: TP faces bottlenecks when scaling across nodes
  • Better overlap: PP communicates only at pipeline stage boundaries
  • Chunked prefill: Different chunks can be processed simultaneously across nodes
Detailed analysis: Chunked Pipeline Blog

How It Works

Basic Pipeline Architecture

Each node processes a subset of layers and forwards activations to the next stage.

Dynamic Chunked Prefill

With chunked prefill, long sequences are split into chunks:
Different chunks are processed in parallel across pipeline stages, reducing TTFT.

Asynchronous Communication

SGLang implements micro-batching with non-blocking P2P communication:
  • Decoupled sync/async logic: Send operations return immediately, synchronization is deferred
  • Multi-stream execution: Separate streams for forward pass, data transfers, and result processing
  • Overlap computation and communication: While one micro-batch computes, the next prepares

When to Use Pipeline Parallelism

Use PP when:
  • Processing ultra-long contexts (64K+ tokens)
  • Scaling across multiple nodes (2-8+ nodes)
  • Communication bandwidth is limited between nodes
  • Working with large models (100B+ parameters)
Combine with TP when:
  • Each node has multiple GPUs
  • Model layers are too large for single GPU

Configuration

Basic Setup

Single Model - Multi-Node

This creates a 4-stage pipeline with 8-way TP per stage (32 GPUs total).

With Dynamic Chunking

Dynamic chunking automatically adjusts chunk sizes to minimize pipeline bubbles:
Key parameters:
  • --chunked-prefill-size: Initial chunk size (larger when using dynamic chunking)
  • SGLANG_DYNAMIC_CHUNKING_SMOOTH_FACTOR: Controls chunk size adaptation (0.6-0.85 recommended)

Dynamic Chunking

Why Dynamic Chunking?

Fixed chunk sizes cause pipeline bubbles because:
  • Transformer layers have non-uniform running time
  • Longer prefix sequences take more time for same chunk size
  • Bubbles propagate and accumulate across stages

How It Works

Dynamic chunking predicts optimal next chunk size to satisfy:
Where L is the current prefix sequence length. Algorithm:
  1. Model cumulative runtime as quadratic function of sequence length
  2. Solve for next chunk size given current prefix length L
  3. Align downward to nearest multiple of max(page-size, 64)
  4. Apply smoothing factor for stability

Tuning Dynamic Chunking

Step 1: Find Optimal Fixed Chunk Size Test different fixed chunk sizes:
Measure TTFT for your target input token length. Step 2: Set Initial Dynamic Chunk Size Use 2-3× the optimal fixed chunk size:
Step 3: Tune Smoothing Factor
  • 1.0: Follows prediction model strictly (may create very small tail chunks)
  • 0.6-0.85: Recommended range for best balance
  • 0: Disables dynamic adjustment (fixed chunking)
Test different values:

Layer Partition Optimization

For uneven layer divisions, place larger partitions on higher PP ranks:
This increases GPU utilization when higher ranks wait for previous stages.

Case Studies

DeepSeek-V3.1 (128K Context, 4×H20 Nodes)

Fixed Chunking (Baseline):
Dynamic Chunking (Optimized):

Qwen3-235B-A22B-FP8 (128K Context, 4×H20 Nodes)

Fixed Chunking:
Dynamic Chunking:
Note: --disable-radix-cache is for reproducible benchmarking only. Remove in production.

Combining with Other Parallelism

PP + TP

Most common combination for large models:

PP + TP + EP (MoE Models)

For Mixture-of-Experts models:

PP + PD Disaggregation

Combine pipeline parallelism with prefill-decode disaggregation:
See Prefill-Decode Disaggregation for details.

Configuration Summary

Performance Tips

  1. Start with fixed chunking to establish baseline, then enable dynamic
  2. Use larger initial chunks (2-3× fixed optimal) with dynamic chunking
  3. Place larger partitions on higher ranks for uneven layer divisions
  4. Monitor pipeline bubbles using profiling tools
  5. Adjust smoothing factor based on your workload characteristics

Troubleshooting

High TTFT

Symptom: Long time to first token with long contexts Solution: Enable dynamic chunking with appropriate smoothing:

Pipeline Bubbles

Symptom: Low GPU utilization on some pipeline stages Solution: Adjust layer partition:

OOM During Long Context

Symptom: Out of memory with very long sequences Solution: Reduce chunk size and memory fraction:

Best Practices

  1. Use PP for multi-node deployments over pure TP
  2. Combine with TP within each node for optimal performance
  3. Enable dynamic chunking for ultra-long contexts (64K+)
  4. Tune chunk sizes for your specific model and hardware
  5. Monitor communication overhead between pipeline stages