Snowflake’s Ulysses trick trains transformers on million-token contexts across GPUs
Curated by the Inblix editorial team
The quadratic cost of attention has been the brick wall for training transformers on truly long sequences. You can’t just throw more GPUs at the problem with standard data parallelism—each device still chokes on the full attention matrix. Snowflake’s AI Research team has a compelling workaround baked into their Arctic Long Sequence Training protocol, and it’s now spreading through the Hugging Face ecosystem.
It’s called Ulysses Sequence Parallelism, originally detailed in a DeepSpeed paper. The core idea sidesteps the memory bottleneck by sharding the input sequence across GPUs and then cleverly swapping what each GPU owns. After computing their local QKV projections, an all-to-all communication step shuffles the data so each GPU holds the full sequence but for only a subset of attention heads. Since attention heads are independent, each GPU can compute its share using standard FlashAttention locally before another all-to-all operation restores the original sharding. You’re trading sequence locality for head locality, and the math works out in your favor.
The communication savings versus an approach like Ring Attention are significant. Ulysses needs two all-to-all operations per layer with a total volume of O(hidden_dim × seq_len / parallelism_degree). Ring Attention, which passes chunks sequentially around a ring, communicates O(hidden_dim × seq_len) per GPU—a factor of parallelism_degree more data. Ulysses also gets a latency win by using one collective step that exploits full bisectional bandwidth instead of serializing over multiple hops.
What makes this more than a research curiosity is the integration. It’s not just a paper; it’s landing in tools developers actually use. Accelerate lets you configure it through a ParallelismConfig class with a DeepSpeed backend, and calling accelerator.prepare() automatically registers the model with the proper attention handler and wraps the dataloader. This support extends up the stack into the Transformers Trainer and TRL’s SFTTrainer, which means fine-tuning a model like Llama-3.1-8B on book-length contexts doesn’t require you to build a custom training loop from scratch. The benchmarks for real-world document understanding and code analysis tasks should be interesting to watch, but the plumbing is finally in place for more people to run those experiments.
💡 Key Takeaways
- Ulysses shards sequences across GPUs, then uses all-to-all collectives to swap sequence chunks for attention head subsets, making each GPU’s attention computation completely independent.
- The communication volume per GPU is O(hidden_dim × seq_len / parallelism_degree), which is a factor of `parallelism_degree` less data transfer than Ring Attention’s O(hidden_dim × seq_len).
- Ulysses is integrated into Hugging Face Accelerate, the Transformers Trainer, and TRL’s SFTTrainer, requiring only a configuration change and a standard `accelerator.prepare()` call to set up.
Keep reading: See related articles below for more coverage on this topic.
Get smarter about AI
The sharpest AI news, curated daily. Delivered free to your inbox.