Knowledge note

Context Parallelism

A distributed inference strategy that shards a long sequence and its KV state across ranks while preserving exact attention.

Updated September 16, 2026Confidence: High

Context Parallelism

Context Parallelism is a distributed inference strategy that shards a request’s sequence tokens and KV-cache entries across ranks while reconstructing exact attention through communication.

Why It Exists

Long-context prefill has both quadratic attention work and linearly growing KV-cache storage. Context parallelism adds hosts to the sequence dimension so local attention and cache capacity scale with the number of ranks.

How It Works

Each rank keeps the model’s TP-sharded weights and a slice of the request. A ring circulates either KV blocks or query blocks, depending on which message is cheaper for the current new-token length and cache-hit rate. Partial softmax outputs are merged with log-sum-exp statistics, so the result is exact dense attention rather than a sparse approximation.

Tradeoffs

Context parallelism is strongest for long prefill, where attention compute can hide ring communication. Decode has less compute to overlap, and query padding plus an output All-to-All can make time-to-incremental-token worse as the CP group grows. CP also replicates the model across hosts and therefore complements rather than replaces tensor parallelism.

Common Confusions

  • Context parallelism vs. sequence parallelism: Context parallelism here targets inference, persistent KV state, and multi-turn decode; sequence parallelism is primarily a training strategy with a related sequence-sharding idea.
  • Context parallelism vs. sparse attention: CP preserves every exact attention interaction; sparse attention reduces the number of interactions.

Where It Appears

  • Ring Attention - The blockwise communication pattern used to compute attention across shards.
  • Sequence Parallelism - The training-oriented predecessor with a related sequence-dimension split.
  • Tensor Parallelism - The complementary strategy that shards model weights.
  • KV Cache - The request-specific state distributed by context parallelism.