Marrying Ulysses and Ring to dodge the attention-head limit
Because pure Ulysses chokes on GQA and Ring-Attention is slow, this library fuses both into a single drop-in distributed attention layer.

What it does
LongContextAttention is a drop-in replacement for standard attention that distributes long sequences across GPUs. It hybridizes DeepSpeed-Ulysses and Ring-Attention, trying to keep the former’s speed while escaping its rigid head-count ceiling.
The interesting bit
Ulysses parallelism is capped by the number of attention heads, so it stumbles with GQA, MQA, or Tensor-Parallel layouts. Ring-Attention scales further but slices QKV into smaller blocks and relies on async peer-to-peer comms that can deadlock in large deployments. This project layers the two: Ulysses shards across heads, Ring shards across sequence, letting you raise parallelism even when head counts are low. NVIDIA liked the idea enough to fold it into TransformerEngine.
Key highlights
- Exposes a unified
LongContextAttentionAPI withzigzag,stripe, andbasicring variants. - Supports FlashAttention v2/v3 on NVIDIA hardware and a PyTorch fallback for NPUs, though the latter is forward-only.
- Verified against Megatron-LM; the authors report matching loss curves with standard Data Parallel.
- Benchmarked on A100 NVLink and L20 PCIe clusters, with tuning guidance for heterogeneous nodes.
- Already integrated into downstream projects including NVIDIA TransformerEngine, xDiT, and FlagScale.
Caveats
- If your model has enough attention heads, pure Ulysses is still faster; this is not a universal upgrade.
- FlashAttention is a finicky dependency and the README admits it is “often the cause of errors.”
- The PyTorch-efficient fallback lacks backward-pass support, so NPU users are stuck in inference or forward-only mode.
Verdict
Grab it if you are training long-context models with GQA/MQA and have run out of Ulysses head-parallelism. If you are on a small cluster with plenty of heads and no deadlock issues, you may not need the extra complexity.
Frequently asked
- What is feifeibear/long-context-attention?
- Because pure Ulysses chokes on GQA and Ring-Attention is slow, this library fuses both into a single drop-in distributed attention layer.
- Is long-context-attention open source?
- Yes — feifeibear/long-context-attention is open source, released under the Apache-2.0 license.
- What language is long-context-attention written in?
- feifeibear/long-context-attention is primarily written in Python.
- How popular is long-context-attention?
- feifeibear/long-context-attention has 692 stars on GitHub.
- Where can I find long-context-attention?
- feifeibear/long-context-attention is on GitHub at https://github.com/feifeibear/long-context-attention.