feifeibear/long-context-attention
USP: Unified (a.k.a. Hybrid, 2D) Sequence Parallel Attention for Long Context Transformers Model Training and Inference
What it solves
LongContextAttention addresses the limitations of applying DeepSpeed-Ulysses-Attention and Ring-Attention individually for long-context LLM training and inference. Ulysses is restricted by the number of attention heads (making it incompatible with Grouped-Query Attention or Multi-Query Attention when head counts are low), while Ring-Attention suffers from lower communication bandwidth and efficiency bottlenecks.
How it works
It combines DeepSpeed-Ulysses and Ring-Attention into a unified sequence parallel (USP) approach across two orthogonal process-group dimensions. It integrates with FlashAttention versions 2 and 3, PyTorch native attention, or hardware-specific kernels (such as Intel XPU), allowing users to drop it in as a sequence-parallel attention layer by configuring process groups and reordering input tensors for load balancing.
Who it’s for
This project is for machine learning engineers and researchers training or running inference on long-context large language models and generative AI models across distributed hardware setups like GPUs, TPUs, and NPUs.
Highlights
- Synergizes DeepSpeed-Ulysses and Ring-Attention for better performance and versatility
- Supports multiple hardware backends including NVIDIA GPUs, AMD GPUs, Intel XPUs, and NPUs
- Compatible with popular frameworks like Megatron-LM and various FlashAttention versions
- Provides QKV-packed and non-packed attention variants to handle different attention head layouts
Related
- Dispatch
- Project
- Project
- Dispatch
- Project