คู่มือทางเทคนิค

ลำดับความเท่าเทียมและความสนใจของวงแหวน

ความขนานของลำดับจะแยกลำดับอินพุตยาวหนึ่งลำดับระหว่าง GPU หรือ TPU หลายตัวตามมิติโทเค็น ดังนั้นจึงไม่มีอุปกรณ์ใดต้องเก็บบริบททั้งหมด

ฟังคำแนะนำนี้บรรยายโดย AI · ~8 min

บนหน้านี้อ่าน 9 นาที
  1. ภาพรวม
  2. ประเด็นสำคัญ
  3. เจาะลึก
  4. ติดตาม Ring Attention บนอุปกรณ์สี่เครื่อง
  5. การใช้งานจริงในโลกแห่งความเป็นจริง
  6. อนาคตของการเรียงลำดับความเท่าเทียมและความสนใจของวงแหวน
  7. การนำไปปฏิบัติ
  8. ที่มาและอ่านเพิ่มเติม
  9. สำรวจต่อไป
  10. คำถามที่พบบ่อย

ภาพรวม

Ring Attention ซึ่งเผยแพร่โดยนักวิจัยของ UC Berkeley ในปี 2023 คำนวณความสนใจที่แน่นอนในการตั้งค่านั้นโดยการส่งบล็อกคีย์และค่าไปรอบๆ วงแหวนของอุปกรณ์ ในขณะที่แต่ละอุปกรณ์ยังคงประมวลผลอยู่ ซึ่งทำให้บริบทการฝึกอบรมล้านโทเค็นใช้งานได้จริง

ประเด็นสำคัญ

  1. ความขนานของลำดับจะแยกหนึ่งลำดับระหว่างอุปกรณ์ต่างๆ ตามมิติโทเค็น ดังนั้นอุปกรณ์แต่ละเครื่องจะจัดเก็บบริบทเพียงบางส่วนเท่านั้น
  2. Ring Attention จะส่งผ่านบล็อกคีย์และค่าไปรอบๆ วงแหวนของอุปกรณ์ และซ้อนทับกันซึ่งถ่ายโอนด้วยการคำนวณความสนใจแบบบล็อก
  3. Ring Attention คำนวณความสนใจที่แน่นอน ไม่ใช่การประมาณ โดยรวมผลลัพธ์แบบบล็อกกับซอฟต์แม็กซ์ที่ทำงานอยู่
  4. รายงาน Ring Attention รายงานบริบทมากกว่า 1 ล้านโทเค็นสำหรับรุ่น 7B บน A100 GPU จำนวน 32 ตัว
  5. DeepSpeed-Ulysses ใช้การสื่อสารแบบ all-to-all แทน ดังนั้น GPU แต่ละตัวจึงคำนวณความสนใจตามลำดับแบบเต็มสำหรับชุดย่อยของส่วนหัว
  6. การซ่อนการสื่อสารต้องใช้บล็อกอย่างน้อย FLOPS หารด้วยโทเค็นแบนด์วิธ ประมาณ 1,000 บล็อกบน A100 ที่เชื่อมต่อกับ NVLink

เจาะลึก

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.

04ตัวอย่างการทำงาน

ติดตาม Ring Attention บนอุปกรณ์สี่เครื่อง

  1. ใช้ลำดับโทเค็น 16,000 โทเค็นและอุปกรณ์สี่ตัว โดยให้แต่ละอุปกรณ์มีบล็อกที่ต่อเนื่องกันจำนวน 4,000 โทเค็นพร้อมคำสั่ง คีย์ และค่าของตัวเอง

  2. ในขั้นตอนที่ 1 อุปกรณ์แต่ละเครื่องจะคำนวณความสนใจระหว่างการสืบค้นและบล็อกคีย์-ค่าของตัวเอง ขณะเดียวกันก็ส่งบล็อกนั้นไปยังอุปกรณ์ถัดไปในวงแหวน

  3. ในขั้นตอนที่ 2 อุปกรณ์แต่ละเครื่องจะได้รับบล็อกคีย์-ค่าของอุปกรณ์ก่อนหน้า อัปเดตการทำงานสูงสุด ผลรวมเอ็กซ์โพเนนเชียล และผลรวมของค่าถ่วงน้ำหนัก และส่งต่อบล็อกอีกครั้ง

  4. ทำซ้ำสำหรับขั้นตอนที่ 3 และ 4 ดังนั้นทุกบล็อกการสืบค้นจะตรงตามบล็อกคีย์-ค่าทั้งสี่รายการ

  5. หารผลรวมมูลค่าถ่วงน้ำหนักของอุปกรณ์แต่ละเครื่องด้วยผลรวมเอ็กซ์โปเนนเชียลเพื่อให้ได้เอาต์พุตความสนใจสุดท้ายสำหรับโทเค็น 4,000 รายการ

  6. สำหรับโมเดลเชิงสาเหตุ โปรดทราบว่าอุปกรณ์ที่ถือโทเค็น 1 ถึง 4,000 สามารถข้ามบล็อกส่วนใหญ่ได้ในขณะที่อุปกรณ์ตัวสุดท้ายต้องประมวลผลทั้งสี่อัน ซึ่งเป็นที่อยู่ Striped Attention ที่ไม่สมดุล

มันแสดงให้เห็นอะไร

เอาต์พุตความสนใจที่แน่นอนสำหรับโทเค็นทั้งหมด 16,000 โทเค็น โดยแต่ละอุปกรณ์จะจัดเก็บโทเค็น 4,000 เพียงประมาณหกบล็อกเท่านั้น ตรวจสอบโดยเรียกใช้อินพุตเดียวกันผ่านการใช้งานอุปกรณ์เครื่องเดียวในตัวอย่างเล็กๆ และเปรียบเทียบเอาต์พุต ซึ่งควรตรงกับความแม่นยำเชิงตัวเลข

การใช้งานจริงในโลกแห่งความเป็นจริง

โปรเจ็กต์ Large World Model ของ UC Berkeley ใช้ Blockwise RingAttention เพื่อขยายโมเดล LLaMA-2 7B อย่างต่อเนื่องจากโทเค็นบริบท 4K เป็น 1M การฝึกบนพ็อด TPUv4-1024

NVIDIA Megatron Core นำเสนอความขนานของบริบท ซึ่งอธิบายว่าคล้ายกับ Ring Attention แต่ด้วยเคอร์เนลความสนใจแฟลช cuDNN และการปรับสมดุลโหลดสำหรับมาสก์เชิงสาเหตุ รวมกับเทนเซอร์ ไปป์ไลน์ และความขนานของข้อมูล

DeepSpeed-Ulysses ของ Microsoft แยกลำดับระหว่าง GPU และใช้การสื่อสารแบบ all-to-all เพื่อให้ลำดับ GPU แต่ละตัวเต็มรูปแบบสำหรับชุดย่อยของหัวความสนใจ โดยรายงานการฝึกอบรมเกี่ยวกับลำดับมากกว่าล้านโทเค็น

ความขนานของลำดับ Megatron-LM ของ NVIDIA จะแยกการเปิดใช้งาน LayerNorm และ dropout ตามลำดับ ด้วยการคำนวณซ้ำแบบเลือกได้ จึงฝึกโมเดลสไตล์ GPT-3 พารามิเตอร์ 530B ที่การใช้งานโมเดล FLOP 54.2% บน A100 GPU 2,240 ตัว

Striped Attention (MIT, 2023) กำหนดโทเค็นใหม่ให้กับอุปกรณ์ในรูปแบบลายเส้นเพื่อสร้างสมดุลระหว่างงานที่ต้องให้ความสนใจเชิงสาเหตุ โดยรายงานการฝึกที่เร็วกว่า Ring Attention ถึง 1.45 เท่าที่โทเค็น 256,000 โทเค็น

อนาคตของการเรียงลำดับความเท่าเทียมและความสนใจของวงแหวน

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.

การนำไปปฏิบัติ

ทำไมมันถึงสำคัญ

  • ต้นทุนและงบประมาณ. การตัดสินใจด้านสถาปัตยกรรมขับเคลื่อนประสิทธิภาพและต้นทุนการดำเนินงานเป็นเวลาหลายปี
  • การตัดสินใจที่ชัดเจนยิ่งขึ้น. การศึกษาด้านเทคนิคช่วยให้ทีมเลือกกลุ่มที่เหมาะสม ไม่ใช่แค่กลุ่มใหม่ล่าสุด
  • การควบคุมคุณภาพ. ตัวเลือกทางวิศวกรรมที่ดีกว่าจะช่วยลดเหตุการณ์ด้านความน่าเชื่อถือในการผลิต

ระวัง

  • การเพิ่มประสิทธิภาพเกณฑ์มาตรฐานหนึ่งรายการสามารถซ่อนจุดอ่อนของระบบในวงกว้างได้
  • ต้นทุนโครงสร้างพื้นฐานและการบำรุงรักษามักถูกประเมินต่ำไป
  • ช่องว่างด้านความปลอดภัยและความสามารถในการสังเกตสามารถเพิ่มขึ้นได้เมื่อระบบมีความซับซ้อนมากขึ้น

ขั้นตอนต่อไป

  1. กำหนดเป้าหมายเวลาแฝง คุณภาพ และต้นทุนก่อนนำไปใช้งาน
  2. เกณฑ์มาตรฐานภายใต้สภาวะโหลดและข้อมูลจริง
  3. การตรวจสอบเครื่องมือเพื่อหาข้อผิดพลาด การเบี่ยงเบน และผลกระทบต่อผู้ใช้
  4. เตรียมเส้นทางการย้อนกลับและการตอบสนองต่อเหตุการณ์ก่อนปรับขนาด

ที่มาและอ่านเพิ่มเติม

  1. arXiv (UC Berkeley)เรียกความสนใจด้วยหม้อแปลงแบบบล็อกสำหรับบริบทที่ใกล้ไม่มีที่สิ้นสุด
  2. arXiv (National University of Singapore)ความเท่าเทียมของลำดับ: การฝึกอบรมลำดับยาวจากมุมมองของระบบ
  3. arXiv (NVIDIA)การลดการคำนวณการเปิดใช้งานซ้ำในรุ่นหม้อแปลงขนาดใหญ่
  4. arXiv (Microsoft)DeepSpeed Ulysses: การเพิ่มประสิทธิภาพระบบสำหรับการเปิดใช้งานการฝึกอบรมโมเดลหม้อแปลงลำดับยาวมาก
  5. arXiv (ICLR 2025)โมเดลระดับโลกของวิดีโอและภาษาที่มีความยาวนับล้านพร้อมความสนใจแบบ Blockwise Ring
  6. arXivความสนใจแบบสไทรพ์: ความสนใจของวงแหวนที่เร็วขึ้นสำหรับหม้อแปลงเชิงสาเหตุ
  7. NVIDIA Megatron Core documentationแพ็คเกจ context_parallel

สำรวจต่อไป

จดหมายข่าวฟรี

รับสรุป AI รายวัน

เรื่องราว AI ที่ตรวจสอบแล้ว 3 เรื่องทุกวันทำงาน เช้า, เขียนเป็นภาษาอังกฤษธรรมดา ฟรีตลอดไป ไม่มีโฆษณา

อีเมลหนึ่งฉบับทุกวันทำงาน ยกเลิกการสมัครในคลิกเดียว เราไม่เคยขายหรือแชร์ที่อยู่อีเมลของคุณ

ทดสอบตัวเอง

ทำแบบทดสอบ Sequence Parallelism และ Ring Attention

ข้อเสนอแนะทันทีสำหรับทุกคำตอบ และใบรับรองที่สามารถแชร์ได้พร้อม ID ที่ตรวจสอบได้เมื่อคุณผ่านหลักสูตร

เริ่มแบบทดสอบ

สนับสนุนการศึกษา AI ฟรี AI Understanding เป็นองค์กรไม่แสวงหาผลกำไร 501(c)(3) — ไม่มีโฆษณา ไม่มีกำแพงเงิน, ตลอดไป บริจาค

คำถามที่พบบ่อย

Sequence Parallelism และ Ring Attention คืออะไร

ความขนานของลำดับจะแยกลำดับอินพุตยาวหนึ่งลำดับระหว่าง GPU หรือ TPU หลายตัวตามมิติโทเค็น ดังนั้นจึงไม่มีอุปกรณ์ใดต้องเก็บบริบททั้งหมด Ring Attention ซึ่งเผยแพร่โดยนักวิจัยของ UC Berkeley ในปี 2023 คำนวณความสนใจที่แน่นอนในการตั้งค่านั้นโดยการส่งบล็อกคีย์และค่าไปรอบๆ วงแหวนของอุปกรณ์ ในขณะที่แต่ละอุปกรณ์ยังคงประมวลผลอยู่ ซึ่งทำให้บริบทการฝึกอบรมล้านโทเค็นใช้งานได้จริง

ความขนานของลำดับจะแบ่งข้อมูลตามมิติใด

ความขนานของลำดับจะแบ่งลำดับเดียวทั่วทั้ง GPU ตามโทเค็น/แกนเวลา ดังนั้นอุปกรณ์แต่ละชิ้นจึงเป็นเจ้าของโทเค็นชิ้นที่ต่อเนื่องกัน

Ring Attention ส่งผ่านอะไรระหว่าง GPU ที่จัดเรียงเป็นวงแหวน

GPU แต่ละตัวจะรักษาการสืบค้นในเครื่องไว้คงที่ และส่งบล็อกคีย์/ค่าแบบ hop-by-hop ไปรอบๆ วงแหวน เพื่อให้ทุกการสืบค้นเห็นทุกคีย์ในที่สุด

Ring Attention สามารถรวมบล็อคความสนใจบางส่วนโดยไม่ต้องประมาณรูปแบบความสนใจทั้งหมดได้อย่างไร

ซอฟต์แม็กซ์ออนไลน์สะสมการแสดงออกความสนใจแบบเดียวกันข้ามบล็อก ลำดับการลดจุดลอยตัวยังคงสามารถสร้างความแตกต่างเชิงตัวเลขได้เล็กน้อย

เหตุใด Ring Attention จึงไม่ต้องใช้ GPU ตัวเดียวในการจัดเก็บ K/V แบบเต็ม

เนื่องจากบล็อก K/V เข้ามาทีละน้อยและ GPU แต่ละตัวจะสะสมความสนใจบางส่วน จึงไม่มีอุปกรณ์ใดที่ต้องการชุดคีย์/ค่าทั้งหมดในหน่วยความจำพร้อมกัน

เมื่อใดที่ Ring Attention สามารถลดเวลาที่ใช้ในการถ่ายโอนบล็อก K/V ได้

การทับซ้อนสามารถซ่อนเวลาในการถ่ายโอนเมื่อการคำนวณและแบนด์วิธอนุญาต ไม่รับประกันการดำเนินการแบบไร้การสื่อสารในทุกเลย์เอาต์

เรียนรู้ต่อไป

คำแนะนำที่เกี่ยวข้อง

คำแนะนำเพิ่มเติมที่เลือกสำหรับหัวข้อนี้

รับใบรับรอง AI ฟรีหลักสูตรและการสอบสั้น ๆ ฟรี ไม่มีค่าใช้จ่าย ไม่มีบัตรเครดิต ประมาณ 2.5 ชั่วโมงเริ่มต้นฟรี →