Folding Tensor and Sequence Parallelism for Memory-Efficient Transformer Training & Inference
This paper introduces Tensor and Sequence Parallelism (TSP), a novel execution strategy that folds weight and token sharding onto a single device axis to simultaneously reduce parameter and activation memory overhead, offering a hardware-efficient alternative for training and inference of long-context and memory-constrained transformer models.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you are trying to solve a massive jigsaw puzzle with a group of friends, but you only have a very small table (your computer's memory) to work on. The puzzle is so big that no single person can hold all the pieces at once.
This paper introduces a new way for a team of computers (GPUs) to work together to train giant AI models, which are essentially these massive puzzles. The authors call their new strategy TSP (Tensor and Sequence Parallelism).
Here is the breakdown using simple analogies:
The Problem: Two Old Ways to Share the Work
To solve the puzzle, the team usually uses one of two old methods, but both have flaws:
The "Weight Split" Method (Tensor Parallelism):
Imagine the puzzle pieces are the "rules" of the game (the model's weights). In this method, you cut the rulebook in half. Person A holds the first half of the rules, and Person B holds the second half.- The Good: You save space on the table because you aren't storing the whole rulebook twice.
- The Bad: If the puzzle has a long story (a long sequence of words), everyone still has to hold the entire story in their hands to play. If the story is huge, your hands (memory) get full, and you crash.
The "Story Split" Method (Sequence Parallelism):
Imagine the puzzle pieces are the story itself. In this method, Person A holds the first half of the story, and Person B holds the second half.- The Good: You save space on the table because you aren't holding the whole story at once.
- The Bad: Everyone still has to memorize the entire rulebook. If the rulebook is huge, your brain (memory) gets full, and you crash.
The Old Hybrid: Usually, teams try to do both by using two separate groups of friends. One group splits the rules, and a different group splits the story. But this is inefficient because it uses up all your friends just to split the work, leaving no one left to help with other tasks (like Data Parallelism).
The Solution: The "Folded" Method (TSP)
The authors say: "Why use two separate groups? Let's fold the work onto a single axis."
In TSP, every single person in the group does both things at the same time:
- They hold a slice of the rulebook (weights).
- They hold a slice of the story (sequence).
The Analogy:
Imagine you are at a dinner party.
- Old Way: You have a table where one person passes around the menu (weights) while everyone reads the whole book. Another table has people passing around the book (story) while everyone memorizes the whole menu.
- TSP Way: Everyone at the table gets a small piece of the menu and a small piece of the story.
How They Make It Work (The Magic Tricks)
Since everyone has a tiny piece of the menu and a tiny piece of the story, they have to talk to each other a lot to finish the puzzle. The paper describes two clever ways they do this without getting overwhelmed:
For the "Story" parts (Attention):
Imagine the group needs to know the whole story to understand a specific sentence. Instead of everyone shouting the whole story at once, they take turns. One person broadcasts their piece of the menu to everyone. Then, everyone calculates their part of the story, and they quickly swap their story pieces (keys and values) to reconstruct the full context. It's like a relay race where they pass the baton (data) while running.For the "Rules" parts (MLP):
Imagine the group needs to apply different rules to their story pieces. Instead of stopping to shout the rules, they pass the rulebook pages around in a circle (a ring). Person A does their math with Page 1, then passes Page 1 to Person B while Person B passes Page 2 to Person C. While the pages are moving, everyone is busy doing math. This keeps the "traffic" moving while the "work" gets done.
Why Is This Better?
The paper claims TSP is a "hardware-aware" solution, meaning it is designed specifically for how modern computer chips talk to each other.
- Memory Savings: Because everyone holds a piece of the rules and a piece of the story, the memory required on each computer drops significantly. This allows the team to handle much longer stories (longer context) without running out of memory.
- Speed: Even though they are passing more data back and forth (which sounds slower), they do it in a way that overlaps with their thinking. The "passing" happens while they are "thinking," so the total time doesn't get much longer.
- Fitting in the Room: In a computer cluster, the fastest connection is usually between chips on the same machine (like people sitting at the same table). The slower connection is between different machines (people in different rooms).
- Old methods often forced the team to split across different rooms, slowing them down.
- TSP allows the whole "split" team to fit on a single machine (one table), keeping them in the fast lane.
The Results
The authors tested this on a massive cluster of 1,024 powerful GPUs (MI300X).
- Memory: TSP used the least amount of memory at every test, especially when the stories were very long.
- Speed: TSP was just as fast, or faster, than the old methods.
- Scalability: As they added more computers to the group, TSP continued to perform well, whereas the old methods started to struggle with memory limits.
In short: TSP is a smarter way to organize a team of computers. Instead of splitting the "rules" and the "story" into separate groups, it combines them so every computer holds a little bit of both. This saves space, allows for longer stories, and keeps the team working efficiently on the same fast network.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.