Technische GIDS

Sequentieparallellisme en ringaandacht

Sequence parallelism splitst één lange invoersequentie over meerdere GPU's of TPU's langs de token-dimensie, zodat geen enkel apparaat de volledige context hoeft te bevatten.

Luister naar deze gidsAI-verteld · ~8 min

Op deze pagina9 minuten lezen
  1. Overzicht
  2. Belangrijkste inzichten
  3. Diepe duik
  4. Tracing Ring Attention op vier apparaten
  5. Implementatie in de echte wereld
  6. De toekomst van sequentieparallellisme en ringaandacht
  7. Het in de praktijk brengen
  8. Bronnen en verdere literatuur
  9. Blijf verkennen
  10. Veelgestelde vragen

Overzicht

Ring Attention, gepubliceerd door onderzoekers van UC Berkeley in 2023, berekent exacte aandacht in die setting door sleutel- en waardeblokken rond een ring van apparaten te sturen terwijl elk apparaat blijft berekenen, waardoor trainingscontexten van miljoenen tokens praktisch werden.

Belangrijkste inzichten

  1. Sequence parallelism splitst één sequentie over apparaten langs de token-dimensie zodat elk apparaat slechts een deel van de context opslaat.
  2. Ring Attention stuurt sleutel- en waardeblokken rond een ring van apparaten en overlapt die overdracht met blokgewijze attentieberekening.
  3. Ring Attention berekent exacte aandacht, geen benadering, door blokgewijze resultaten te combineren met een voortschrijdende softmax.
  4. Het Ring Attention‑paper meldt meer dan 1 miljoen tokens context voor een 7B‑model op 32 A100‑GPU's.
  5. DeepSpeed-Ulysses gebruikt in plaats daarvan all-to-all‑communicatie zodat elke GPU volledige‑sequentie‑aandacht berekent voor een subset van heads.
  6. Communicatie verbergen vereist blokken van minstens FLOPS gedeeld door bandbreedte‑tokens, ongeveer 1.000 op NVLink‑verbonden A100's.

Diepe duik

A transformer processes a sequence of tokens, and its attention step lets every token look at every other token. That makes memory grow quickly with context length. The Ring Attention paper gives a concrete example: processing 100 million tokens with batch size 1 needs over 1,000 GB of memory even for a modest model with a hidden size of 1,024, while GPUs and TPUs typically have less than 100 GB of high-bandwidth memory. Sequence parallelism is the family of techniques that split a single sequence along its length, the token dimension, across several accelerators, so each one stores only a slice. It complements the older forms of parallelism: data parallelism splits the batch, tensor parallelism splits weight matrices, and pipeline parallelism splits layers.

Most transformer operations are easy to split by token, because they treat each token independently: layer normalization, the feed-forward network, dropout and the query, key and value projections. Attention is the exception. Each token's query must be compared with the keys of every other token in the sequence, and its output is a weighted sum of their values. If device 1 holds tokens 1 to 1,000 and device 2 holds tokens 1,001 to 2,000, device 2's queries still need device 1's keys and values. Every sequence-parallel method is really an answer to one question: how to get keys and values, or queries, to the right device without stalling the computation.

Ring Attention's answer is to arrange the devices in a ring. Each device keeps its own block of queries for the whole computation. Key and value blocks travel around the ring: at each step a device computes attention between its queries and the key-value block it currently holds, while simultaneously sending that block to the next device and receiving a new one from the previous device. After as many steps as there are devices, every query block has seen every key-value block. Because attention is computed blockwise with a running softmax, the same technique used by memory-efficient attention kernels, the partial results can be combined exactly, so the output is identical to ordinary attention, not an approximation. If each block's computation takes longer than its transfer, the communication is fully hidden.

The idea has a short history. Shenggui Li and colleagues at the National University of Singapore proposed sequence parallelism with Ring Self-Attention in May 2021; compared with tensor parallelism on 64 NVIDIA P100 GPUs, they reported 13.7 times larger maximum batch size and 3.0 times longer maximum sequence length. In May 2022, NVIDIA's Vijay Korthikanti and colleagues used the name sequence parallelism for a narrower technique inside Megatron-LM: splitting the LayerNorm and dropout regions along the sequence and swapping all-reduce operations for all-gather and reduce-scatter. Combined with selective recomputation, it cut activation memory by 5 times. In October 2023, Hao Liu, Matei Zaharia and Pieter Abbeel at UC Berkeley published Ring Attention with Blockwise Transformers, which fully overlapped communication with blockwise attention and feed-forward computation. In February 2024 the same group released Large World Model, a family of 7B models handling text and video beyond 1 million tokens.

The main alternative is DeepSpeed-Ulysses from Microsoft, published in September 2023. It also starts with the sequence split across GPUs, but just before attention it performs an all-to-all exchange so that each GPU receives the full sequence for a subset of attention heads, computes those heads, and then reverses the exchange. Its authors show that communication volume stays constant when sequence length and device count grow together, and report up to 2.5 times higher throughput with 4 times longer sequences than the prior state of the art. Because work is divided by heads, the number of devices it can use for one sequence is bounded by the number of attention heads, while Ring Attention divides by blocks of tokens. Megatron Core's context parallelism follows the Ring Attention pattern and adds cuDNN flash attention kernels and causal-mask load balancing.

The headline results are large. On 32 A100 GPUs, the Ring Attention paper reports over 1 million tokens of context for a 7B model, a 32 times improvement over the previous best memory-efficient transformer, and on TPUv4-512 a 256 times increase, allowing training sequences of over 30 million tokens. In general, Ring Attention allows sequences up to device-count times longer than memory-efficient transformers on a single device. Large World Model used it to train on TPUv4-1024, which its authors describe as roughly equivalent to 450 A100 GPUs, scaling RoPE positional embeddings as context grew.

There are real limitations. Hiding communication needs enough work per block: the Ring Attention paper derives that the block size must be at least the device's FLOPS divided by its interconnect bandwidth, which is about 1,000 tokens for A100s on NVLink or TPUs, but about 24,500 tokens for A100s linked by InfiniBand at 12.5 GB per second. Causal language models create load imbalance, because with contiguous blocks the device holding the first tokens has almost nothing to attend to while the last device does the most work; Striped Attention fixes this by giving each device tokens spread throughout the sequence, reporting up to 1.45 times speedups at 256K tokens on A100s and TPUs and 1.65 times at 786K tokens on 16 TPUv4 chips. Sequence parallelism also does not reduce the total compute of attention, which still grows with the square of sequence length, so a million-token step remains expensive.

In practice, using these methods requires a framework that supports them, such as Megatron Core with Transformer Engine, DeepSpeed, or a JAX implementation like the one published with Ring Attention, plus fast device-to-device links. Total GPU count becomes the product of all parallel dimensions; Megatron Core's documentation states it as tensor times context times pipeline times data parallel size. Training a long-context model also involves more than the parallelism scheme: the Large World Model authors describe data curation, progressive context extension and positional-embedding scaling as necessary parts of the process.

04Uitgewerkt voorbeeld

Tracing Ring Attention op vier apparaten

  1. Neem een sequentie van 16.000 tokens en vier apparaten, waarbij elk apparaat een contiguïteitblok van 4.000 tokens krijgt met eigen queries, keys en values.

  2. Op stap 1 berekent elk apparaat aandacht tussen zijn eigen queries en zijn eigen key-value blok, terwijl het dat blok naar het volgende apparaat in de ring stuurt.

  3. Op stap 2 ontvangt elk apparaat het key-value blok van het vorige apparaat, werkt zijn lopende maximum, exponentiële som en gewogen waarde som bij, en stuurt het blok opnieuw door.

  4. Herhaal voor stappen 3 en 4, zodat elk queryblok alle vier de key-value blokken heeft ontmoet.

  5. Verdeel de gewogen waarde som van elk apparaat door zijn exponentiële som om de uiteindelijke aandachtoutput voor zijn 4.000 tokens te krijgen.

  6. Voor een causaal model, let op dat het apparaat dat tokens 1 tot 4.000 bevat, de meeste blokken kan overslaan terwijl het laatste apparaat alle vier moet verwerken, wat de onevenwichtigheid is die Striped Attention aanpakt.

Wat het laat zien

Exacte attention-outputs voor alle 16.000 tokens, waarbij elk apparaat slechts ongeveer zes blokken van 4.000 tokens opslaat. Controleer dit door dezelfde input uit te voeren via een attention-implementatie op één apparaat met een klein voorbeeld en de outputs te vergelijken, die tot op numerieke precisie overeen moeten komen.

Implementatie in de echte wereld

Het Large World Model-project van UC Berkeley gebruikte Blockwise RingAttention om een LLaMA-2 7B-model stapsgewijs uit te breiden van 4K naar 1M tokens aan context, getraind op een TPUv4-1024 pod.

NVIDIA Megatron Core biedt context-parallelisme, wat het omschrijft als vergelijkbaar met Ring Attention, maar met cuDNN flash attention-kernels en load balancing voor causale maskers, gecombineerd met tensor-, pipeline- en data-parallelisme.

Microsoft's DeepSpeed-Ulysses splitst sequenties over GPU's en gebruikt all-to-all-communicatie om elke GPU volledige sequenties te geven voor een subset van attention-heads, en meldt training op sequenties van meer dan een miljoen tokens.

NVIDIA's Megatron-LM sequentiële parallelisme splitst LayerNorm- en dropout-activaties langs de sequentie; met selectieve recomputatie trainde het een GPT-3-achtig model van 530  miljard parameters met 54,2 % model-FLOPs benutting op 2.240 A100 GPU's.

Striped Attention (MIT, 2023) wijst tokens opnieuw toe aan apparaten in een gestript patroon om het werk van causale aandacht te balanceren, en meldt tot 1,45 × snellere training dan Ring Attention bij 256 k tokens.

De toekomst van sequentieparallellisme en ringaandacht

Work since 2023 has concentrated on three problems. Load balance for causal models is one: Striped Attention (November 2023) and Megatron Core's context parallelism both reorganize which tokens each device holds so that no device sits idle behind the causal mask. Communication is another: DeepSpeed-Ulysses (September 2023) showed that all-to-all exchanges can keep per-link volume constant, and frameworks increasingly combine head-based and ring-based splitting. Kernel efficiency is the third, with context-parallel implementations calling fused flash attention kernels for each block. The broader open question is how much long context helps compared with its cost. Ring Attention removes the per-device memory limit but not the quadratic compute of exact attention, so training on million-token sequences still consumes large accelerator budgets, and the Large World Model paper reports that data curation and positional-embedding scaling were as important as parallelism. Research into efficient attention variants, retrieval and memory mechanisms continues alongside these systems methods, and published benchmarks of throughput and long-context retrieval accuracy remain the reliable way to compare them.

Het in de praktijk brengen

Waarom het ertoe doet

  • Kosten en budget. Architectuurbeslissingen bepalen jarenlang de prestaties en bedrijfskosten.
  • Duidelijkere beslissingen. Technisch onderwijs helpt teams bij het kiezen van de juiste stapel, niet alleen de nieuwste.
  • Kwaliteitscontrole. Betere technische keuzes verminderen het aantal betrouwbaarheidsincidenten in de productie.

Pas op voor

  • Het optimaliseren van één benchmark kan bredere systeemzwakheden verbergen.
  • Infrastructuur- en onderhoudskosten worden vaak onderschat.
  • De lacunes op het gebied van beveiliging en waarneembaarheid kunnen groter worden naarmate systemen complexer worden.

Volgende stappen

  1. Definieer latentie-, kwaliteits- en kostendoelen vóór implementatie.
  2. Benchmark onder realistische belasting- en gegevensomstandigheden.
  3. Instrumentbewaking op fouten, drift en gebruikersimpact.
  4. Bereid rollback- en incidentresponspaden voor voordat u gaat schalen.

Bronnen en verdere literatuur

  1. arXiv (UC Berkeley)Ring Attention met blockgewijze transformers voor bijna oneindige context
  2. arXiv (National University of Singapore)Sequentiële parallelisme: lange sequentietraining vanuit systeemperspectief
  3. arXiv (NVIDIA)Verminderen van activatie-recomputatie in grote transformer-modellen
  4. arXiv (Microsoft)DeepSpeed Ulysses: systeemoptimalisaties om training van extreem lange sequentie-transformer-modellen mogelijk te maken
  5. arXiv (ICLR 2025)World Model op video en taal van een miljoen lengte met blockgewijze RingAttention
  6. arXivStriped Attention: snellere Ring Attention voor causale transformers
  7. NVIDIA Megatron Core documentationcontext_parallel pakket

Blijf verkennen

Gratis nieuwsbrief

Ontvang de dagelijkse AI-briefing

Drie verifieerde AI-verhalen elke weekdagmorgen, geschreven in eenvoudig Engels. Gratis voor altijd, geen advertenties.

Eén e-mail elke weekdag. Afmelden met één klik. We verkopen of delen je adres nooit.

Test jezelf

Doe de quiz over sequentiële parallelisme en Ring Attention

Directe feedback op elke antwoord, en een deelbare certificaat met een verifieerbare ID zodra je een cursus hebt afgerond.

Quiz starten

Ondersteun gratis AI-onderwijs. AI Understanding is een 501(c)(3) non-profit — geen advertenties, geen betaalmuur, nooit. Doe een donatie

Veelgestelde vragen

Wat is sequentieparallellisme en ringaandacht?

Sequentiële parallelisme splitst één lange invoersequentie over meerdere GPU's of TPU's langs de token-dimensie, zodat geen enkel apparaat de volledige context hoeft te bewaren. Ring Attention, gepubliceerd door onderzoekers van UC Berkeley in 2023, berekent exacte aandacht in die situatie door sleutel- en waardeblokken rond een ring van apparaten te laten circuleren terwijl elk apparaat blijft berekenen, waardoor trainingscontexten van een miljoen tokens praktisch werden.

Langs welke dimensie splitst sequentieparallellisme de gegevens?

Sequentie-parallellisme verdeelt een enkele reeks over GPU's langs de token/tijd-as, zodat elk apparaat een aaneengesloten stuk tokens bezit.

Wat geeft Ring Attention door tussen GPU's die in een ring zijn gerangschikt?

Elke GPU houdt zijn lokale zoekopdrachten vast en geeft sleutel-/waardeblokken hop voor hop door de ring, zodat elke zoekopdracht uiteindelijk elke sleutel ziet.

Hoe kan Ring Attention gedeeltelijke attentieblokken combineren zonder het volledige attentiepatroon te benaderen?

Online softmax verzamelt dezelfde attentie-expressie over blokken. De volgorde van floating‑point reductie kan nog steeds kleine numerieke verschillen veroorzaken.

Waarom heeft Ring Attention geen enkele GPU nodig om de volledige K/V op te slaan?

Omdat K/V-blokken stapsgewijs arriveren en elke GPU een deel van de aandacht verzamelt, heeft geen enkel apparaat ooit de volledige sleutel/waarde in één keer in het geheugen nodig.

Wanneer kan Ring Attention de zichtbare tijd die wordt besteed aan het overbrengen van K/V‑blokken verminderen?

Overlap kan de overdrachtstijd verbergen wanneer de berekening en bandbreedte het toelaten. Het garandeert geen communicatie‑vrije uitvoering voor elke indeling.