Lightning Context Parallel

Abstract

Context parallelism (CP) scales attention to long sequences by sharding the sequence across GPUs and exchanging queries, keys, values, or partial outputs between them. Existing implementations keep the attention kernel unchanged and exchange data through separate collectives and layout copies, which leaves the kernel waiting on transfers or competing with collectives for streaming multiprocessors when overlapped on another stream.

We present Lightning Context Parallel (LCP), which fuses this communication into a single FlashAttention-4 kernel supporting Ulysses, K/V all-gather, pass-Q, and unified CP algorithms. In each thread block, a warp unused by FlashAttention-4 copies Q, K, and V over NVLink into peer GPUs in the layout attention expects, while the compute warps attend to blocks as they arrive. In algorithms where a GPU computes attention for another GPU's tokens, the kernel writes finished output tiles back to that peer's memory and merges partial outputs in-kernel. This eliminates separate collectives and intermediate layout copies while keeping all streaming multiprocessors dedicated to attention.

Across bidirectional, streaming, causal prefill, and chunked prefill workloads on 2, 4, and 8 NVIDIA B200 GPUs, LCP achieves 1.12×, 1.23×, and 1.39× geometric-mean kernel speedups over the fastest of 13 open-source CP libraries. In vLLM-Omni, SGLang, and FastFrames, LCP reduces transformer forward-pass latency by up to 15% on bidirectional video, 28% on streaming video, 35% on image diffusion, and 4–17% on LLM prefill.

Overview

0:00 / 0:45 Download

How context parallelism works

0:00 / 0:00 Download

Supported algorithms

Select an algorithm to view its runnable FcpAttention example.

Algorithm Arguments NVLink traffic Typical workload
Ulysses default Q, K, V by head; O written back Bidirectional video, image diffusion
K/V all-gather all_kv=True K, V to all peers; Q and O local GQA causal prefill (with zigzag=True)
Ulysses + K/V all-gather hybrid_u=u Ulysses in u-GPU groups; K/V all-gather across GQA causal prefill at larger GPU counts
Pass-Q own_kv=False, passq=True Q to peers; partial O written back and merged Streaming video, chunked prefill
Ulysses + Pass-Q own_kv=False, passq=True, passq_u=u Ulysses in u-GPU groups; pass-Q across High-head bidirectional & streaming at 8+ GPUs
Ulysses

Framework integrations

examples/wan_diffusers.py

Results

Kernel benchmarks run on 2, 4, and 8 B200 GPUs (1350 MHz locked clocks) against 13 open-source CP libraries; end-to-end benchmarks use unlocked clocks.

8-GPU kernel speedup and winning LCP variant across head and sequence configurations (head dim 128). “32/8” denotes 32 query heads and 8 K/V heads.
End-to-end transformer forward-pass latency reduction, 1 − TLCP / Tnative, in SGLang, vLLM-Omni, diffusers, and FastFrames. Negative values mean LCP is slower.
(a)–(d) Speedup over 1-GPU FA4. (e)–(p) 8-GPU parallel efficiency against 13 baseline libraries and a compute-only FA4 upper bound without communication (dashed).

BibTeX

@misc{lcp2026,
  title  = {Lightning Context Parallel},
  author = {{V S}, Aryan and He, Guande and Gu, Tianpei and Liu, Nan and Rockwell, Chris and Song, Yanke and Huang, Xun},
  year   = {2026},
  url    = {https://github.com/Roblox/lightning-context-parallel}
}