İçeriğe geç

Sequence Parallel + Context Parallel: Ulysses + Ring Attention + 1M Context

Long-context FT'in fizik sınırını aşmak: sequence/context'i GPU'lar arasında böl. DeepSpeed-Ulysses (sequence parallel — head-wise), Ring Attention (Berkeley, sequence-wise), Megatron Sequence Parallel. 1M token context'i mümkün kıl. Kimi-1.5 (Moonshot) 2M context reçetesinin teknik altyapısı.

Şükrü Yusuf KAYA
32 dakikalık okuma
İleri
Sequence Parallel + Context Parallel: Ulysses + Ring Attention + 1M Context

1. Niye Sequence Parallel?#

Long-context FT'in sınırı activation memory:
  • seq=128K, batch=1, Llama 70B → activation 60 GB+
  • 1M token istersen → 500 GB+ → tek GPU değil, hatta 8×H100 bile zorlanır
Çözüm: Sequence dimension'da paralel hesaplama.
MethodSplit DimComm patternUse case
DeepSpeed-Ulysseshead dimension (attention)all-to-all 4xsequence parallel attention
Ring Attention (UC Berkeley)sequence dimensionring all-gather1M context FT
Megatron Sequence Parallelsequence dim in MLP/LNreduce-scatterTP'ın long-seq extension

2. DeepSpeed-Ulysses#

Insight: attention'ın
Q K^T
ve
softmax(...) V
operasyonları head dimension'da bağımsız.
GPU 0: head 0-3 için Q, K, V GPU 1: head 4-7 için Q, K, V ... Forward (attention): - Q, K, V'yi sequence dim'inde gather (all-to-all input) - Per-head attention compute (no comm) - Output'u tekrar sequence dim'inde scatter (all-to-all output)
Avantaj: N GPU ile sequence length uzun mümkün.
Sayı (4×H100 SXM):
  • Standard FA2: max seq=128K (Llama 70B + grad-ckpt)
    • Ulysses (4-way SP): max seq=512K
    • Ulysses (8-way SP, 8 GPU): max seq=1M

3. Ring Attention (Berkeley)#

Insight:
softmax(QK^T)V
operasyonu iteratif olarak hesaplanabilir. Her GPU sequence'ın bir parçasını tutar, ring topolojisi ile parça parça hesaplar.
GPU 0: seq tokens [0..127] K, V'leri GPU 1: seq tokens [128..255] K, V'leri GPU 2: seq tokens [256..383] K, V'leri GPU 3: seq tokens [384..511] K, V'leri Adım 1: Her GPU lokal Q × lokal K (sub-block) Adım 2: K, V'yi sağa pass (ring) Adım 3: Lokal Q × yeni K (cross-block) ... N adım sonra: tüm Q × tüm K hesaplanmış
Online softmax ile birikim numerically kararlı.
Avantaj: Compute scaling N-way + bandwidth efficient (ring topology). Dezavantaj: Implementation karmaşık (Megatron / DeepSpeed integration gerekir).
✅ Teslim
  1. DeepSpeed-Ulysses paper'ı oku. 2) 4-GPU Ulysses ile bir uzun-context senaryosu simulate et. 3) Sonraki ders: 4.7 — Llama 3.3 70B QLoRA + FSDP.

Yorumlar & Soru-Cevap

(0)
Yorum yazmak için giriş yap.
Yorumlar yükleniyor...

İlgili İçerikler