2309.14509-deepspeed-ulysses-long-sequence-training
DeepSpeed Ulysses: System Optimizations for Enabling Training of Extreme Long Sequence Transformer Models
DeepSpeed Ulysses 的核心贡献是把长序列训练中的 activation / context 维瓶颈变成一次可逆的数据布局转换:Transformer 其他算子沿 sequence 维分片,进入 attention 前用 all-to-all 把 sequence-partitioned, all-heads 的 QKV 变成 full-sequence, head-partitioned 的 QKV,让每张 GPU 只计算一部分 attention heads;attention 后再用 all-to-all 切回 sequence 分片。这个设计把 per-link 通信量从随序列长度线性增长降为还会除以并行组规模的水平,并与 ZeRO-3 组合把 model states 也按 data + sequence group 分片,从而支持百万 token 级训练和 7B/30B 长序列 GPT 实验。
Source
- Title: DeepSpeed Ulysses: System Optimizations for Enabling Training of Extreme Long Sequence Transformer Models
- arXiv: https://arxiv.org/abs/2309.14509
- PDF: https://arxiv.org/pdf/2309.14509
- TeX Source: https://arxiv.org/e-print/2309.14509
- Code/Project: https://github.com/deepspeedai/DeepSpeed
- Release blog / README: https://github.com/deepspeedai/DeepSpeed/blob/master/blogs/deepspeed-ulysses/README.md
- Microsoft Research page: https://www.microsoft.com/en-us/research/publication/deepspeed-ulysses-system-optimizations-for-enabling-training-of-extreme-long-sequence-transformer-models/
- Authors: Sam Ade Jacobs, Masahiro Tanaka, Chengming Zhang, Minjia Zhang, Shuaiwen Leon Song, Samyam Rajbhandari, Yuxiong He
- Submitted: 2023-09-25
- Current version read: v2, 2023-10-04
- DOI: https://doi.org/10.48550/arXiv.2309.14509
- Subjects: Machine Learning (cs.LG); Computation and Language (cs.CL); Distributed, Parallel, and Cluster Computing (cs.DC)
- Venue/status: Microsoft Research page lists arXiv, October 2023;ACM DOI page records a later proceedings version
10.1145/3662158.3662806。
作者与关系
- Sam Ade Jacobs: Microsoft Inc.
- Masahiro Tanaka: Microsoft Inc.
- Chengming Zhang: Microsoft Inc.
- Minjia Zhang: Microsoft Inc.
- Shuaiwen Leon Song: Microsoft Inc.
- Samyam Rajbhandari: Microsoft Inc.
- Yuxiong He: Microsoft Inc.
阅读目标与判断边界
本笔记关注:
- Ulysses 的 sequence-parallel all-to-all 变换到底在张量维度上做了什么。
- 为什么它的通信模型是
,以及这个公式和 Megatron-SP / ring-style 方法的差异。 - Ulysses 如何与 ZeRO-3、FlashAttention-2、dense/sparse attention 组合。
- 论文实验如何支撑 1M token、4x sequence length、2.5x throughput 这几个主张。
- 它与 Ring Attention、ZeRO、FlashAttention、RLHF / long-context systems 的关系。
判断边界:
- 本笔记分析 arXiv v2 和 DeepSpeed release blog;后续 DeepSpeed、Accelerate、Megatron-Core、RingAttention、context parallel 实现只作为关系背景。
- 论文主实验使用 A100、GPT-style dense/sparse attention 和 2023 年前后的 Megatron-LM / ColAI-SP baseline。现代 H100/H200、FA3/FA4、PyTorch SDPA、FlexAttention、Megatron-Core context parallel 会改变绝对吞吐和 baseline。
- Ulysses 保持 exact attention 语义,但 attention 的
算术复杂度仍然存在;它主要解决单卡 activation residency 和跨设备通信扩展问题。 - 论文质量实验是 1.3B GPT、32K sequence 的 convergence 对比,足以说明系统变换不应改变模型语义,但不足以证明所有大规模 long-context curriculum 都收敛同等稳定。
论文脉络
1. 研究问题、背景和价值
Transformer 训练系统长期围绕三类维度做并行:
- batch size:data parallelism。
- hidden dimension / tensor operator:tensor parallelism。
- layers / depth:pipeline parallelism。
长上下文把第四个维度推到系统中心:sequence length。对 GPT-style 模型,sequence length 增长会同时放大 attention 计算、activation residency、QKV / context tensor 的通信和 global batch tokens。只靠 data parallel 增加 GPU,通常会把 global batch tokens 一起放大;这会引入收敛和超参问题。只靠 tensor / pipeline parallel,则主要处理模型宽度和深度,对单个样本的超长 context 没有直接分片。
Ulysses 要解决的问题是:如何在不改变 Transformer attention 数学语义、不要求重写模型结构的情况下,把单个样本的 sequence dimension 切到多张 GPU 上训练,并让跨设备通信随 sequence parallel degree 扩展得足够好。
这个问题的价值来自三个场景:
- Long-context pretraining / continual pretraining:把 context 从 8K 推到 32K、128K 或更长时,希望 global batch size 不随 sequence length 机械增大。
- Scientific / multimodal / genomics workloads:单条样本天然很长,batch 维没有足够空间吸收全部并行。
- 后续 long-CoT / agentic RL 训练:长轨迹、长工具历史和长上下文 SFT/RLHF 需要训练侧能处理更长序列,rollout 侧还需要另一套 serving 调度。
2. 已有解决方案与不足
论文比较的 sequence parallelism 主要有两类。
ColAI-SP / ring self-attention 类方法把 query 留在本地,让 key/value 沿 ring 传递,通信复杂度随 message size 线性增长。它可以降低 activation memory,但 attention 形式和实现侵入性更强,泛化到不同 attention kernel / dense-sparse 变体的路径较窄。
Megatron-LM sequence parallelism 沿 sequence 切分,并在 attention 前后使用 all-gather / reduce-scatter 汇总 QKV 或 context。它和 Megatron tensor parallelism 绑定更深,通信量在论文模型里随
已有 data/tensor/pipeline parallelism 的问题也很明确:它们分别服务 batch、hidden 和 layer 维度,没有直接处理“单个样本太长导致 activation 无法驻留”的问题。ZeRO/FSDP 能切 model states,但 sequence activation 和 attention context 仍需要额外机制。
3. 作者可能的思考路径
可以把 Ulysses 的设计重建为一个张量布局问题。
第一步,训练中大部分非 attention 算子可以在 sequence 分片上本地执行。LayerNorm、MLP、residual、dropout 等位置独立或按 token 独立的算子天然适合每张 GPU 只处理
第二步,attention 需要每个 query 看到全序列的 key/value。若继续保持 sequence 分片,每张 GPU缺少远端 tokens 的 K/V。朴素 all-gather 会把完整序列的所有 heads 都复制到每张 GPU,通信和显存都重。
第三步,multi-head attention 有另一个可切维度:attention heads。每个 head 的 attention 相互独立,最终只需在 head dimension 上拼接。因此可以把数据布局从“每张 GPU 持有局部 sequence + 全部 heads”转成“每张 GPU 持有全 sequence + 部分 heads”。
第四步,这个布局转换正好对应 all-to-all collective。所有 GPU 互相交换 QKV 的 head slices:每张 GPU 发送自己本地 sequence 上的一部分 heads 给对应 GPU,收齐后得到全 sequence 上的一部分 heads。attention 计算完成后,再反向 all-to-all 把 context output 切回 sequence 分片,交给后续 MLP / layer norm。
这条路径的核心判断是:在 attention 内部,head-parallel layout 比 sequence-parallel layout 更适合 exact full attention;在 attention 外部,sequence-parallel layout 更适合 activation memory 和非 attention 算子。Ulysses 用两次 all-to-all 在这两种布局之间切换。
4. 核心假设或切入点
Ulysses 依赖几个关键假设:
- Multi-head attention 的 heads 可以独立计算,head dimension 可以作为 attention 内部并行维度。
- 集群 all-to-all collective 在 NVSwitch / InfiniBand 等现代互联上足够高效,per-link message size 可以按
摊薄。 - 非 attention Transformer 算子能在 sequence 分片布局下执行,不需要每层都保留全 sequence。
- ZeRO-3 可以扩展到 data parallel + sequence parallel 组合 group,使 model states 也获得对应分片收益。
- 本地 attention kernel 可以是 dense、sparse 或 FlashAttention 类实现;Ulysses 只要求 attention module 接收 full sequence / subset heads 的局部张量。
5. 方法 / 系统 / 理论框架
5.1 张量布局:从 sequence partition 到 head partition
设序列长度为
在 attention 外,GPU
其中
进入 attention 前,Ulysses 执行第一次 all-to-all:每个 GPU 把本地 sequence slice 上不同 head groups 发送给对应 GPU。之后,GPU
也就是 full sequence,但只包含一部分 attention heads。它可以对这些 heads 独立执行 exact attention:
attention 后执行第二次 all-to-all,把 head-partitioned output 切回:
后续 MLP、LayerNorm、residual 等算子继续在 sequence partition 上本地执行。
5.2 通信公式
论文用
- attention 前 QKV all-to-all:message size
。 - attention 后 context output all-to-all:message size
。
在 all-to-all 中,aggregate message size 为
也就是
Megatron-LM sequence parallelism 的模型是每层两次 all-gather 加两次 reduce-scatter,每次 message size 约为
也就是
这个公式是论文最关键的系统主张。它把长序列训练的扩展条件写成一句话:若愿意为更长序列投入更多 sequence-parallel GPUs,通信不会随全局 sequence length 同步恶化。
5.3 与 ZeRO-3 的组合
Ulysses 主要减少 activation / sequence 维压力。模型参数、梯度、optimizer states 仍需要 ZeRO-3 / FSDP 这类方法处理。
论文把 ZeRO-3 partition group 从 data parallel group 扩展到 data + sequence 组合 group。直观上,训练数据可以看成二维分片:
- batch/sample dimension。
- sequence dimension。
因此 model states 可以在更大的 group 上分片,参数需要时 all-gather,梯度在 data + sequence ranks 上 reduce。这样做的收益是:Ulysses 切 sequence activation,ZeRO-3 切 model states,二者叠加后能同时扩大 sequence length 和 model size。
5.4 Attention-agnostic 设计
Ulysses 对 attention module 的要求相对简单:attention 内部看到的是 full sequence、subset heads。因此 attention kernel 可以替换为:
- dense self-attention。
- causal attention。
- cross-attention。
- block sparse / sparse attention。
- FlashAttention / FlashAttention-2 这类 local efficient attention kernel。
这个性质很重要。Ulysses 没有改 attention 数学语义,也没有要求特定 ring attention kernel。它更像一个 attention 前后的 distributed tensor layout wrapper。DeepSpeed release blog 的示例中,用 DistributedAttention(attn, get_sequence_parallel_group()) 包装原 attention module 即可启用。
5.5 与 Ring Attention 的机制差异
Ulysses 和 Ring Attention 都服务 exact long-context training,但并行分解不同:
| 维度 | DeepSpeed Ulysses | Ring Attention |
|---|---|---|
| 核心 collective | 两次 all-to-all | KV block ring rotation / ppermute |
| attention 内布局 | full sequence + subset heads | local query block + rotating KV blocks |
| 对 head 数的依赖 | 需要 head partition 有足够粒度,sequence parallel degree 通常受 head groups 约束 | 主要受 block size、ring length、通信隐藏条件约束 |
| 通信模型重点 | per-link |
|
| kernel 泛化 | attention module 可替换,dense/sparse/FA 都可接 | 依赖 blockwise exact attention 和在线 softmax状态 |
| 主要优势 | 工程包装清晰,适合 DeepSpeed + ZeRO-3 生态 | 更直接面向 near-infinite context 和通信/计算重叠 |
本地理解:Ulysses 是“sequence/head layout transpose”;Ring Attention 是“local query + KV stream”。这两个抽象都值得保留,因为现代 context parallel 系统经常在它们之间取组合或变体。
6. 结论链条
论文的证据链是:
- 长序列训练需要沿 sequence 维扩展,data/tensor/pipeline parallelism 处理不了这个维度。
- 已有 sequence parallelism 能降低 activation memory,但通信效率和可用性不足。
- Ulysses 用 all-to-all 在 sequence partition 与 head partition 之间切换,使 attention 内部可以完整看见 sequence、外部仍保持 sequence 分片。
- 通信模型给出
per-link volume,相比 Megatron-SP 的 有 倍 per-link volume 优势。 - 与 ZeRO-3 组合后,activation 和 model states 两类内存都获得分片。
- 实验展示 1M token sequence length、7B/30B dense/sparse attention 上更高吞吐、固定/变化序列长度下较好 scaling、以及 1.3B 32K convergence 无明显负面影响。
关键实验/定理
结果 1:1.2B GPT sequence length 扩展到 1M tokens
- 设置:1.2B parameter GPT model;sequence length strong scaling 到 1M tokens;arXiv v2 评测最高使用 256 A100 GPUs。
- 指标:不同 sequence length 和 GPU count 下的 throughput / TFLOPs。
- 结果:论文报告 sequence length 可以随 GPU 数线性增长,并在合适 GPU count 下保持相近 computation throughput。
- 解读:这个实验支撑“Ulysses 可以把全局 sequence length 扩到单卡显存之外”。它证明 memory feasibility,但还需要结合训练时长、数据 curriculum 和最终任务质量判断 long-context pretraining 的收益。
结果 2:7B / 30B dense attention 上超过 Megatron-LM sequence parallelism
- 设置:7B GPT dense attention 在 32 A100 GPUs 上评测;30B GPT dense attention 在 64 A100 GPUs 上评测;选取各方法最佳 sequence parallel degree 和 micro-batch size;Ulysses 使用 ZeRO parallel degree 32 / 64。
- 指标:throughput / TFLOPs,支持的最大 sequence length。
- 结果:Ulysses 在双方都能运行的 sequence length 上持续超过 Megatron-LM sequence parallelism,并能运行更长 sequence。
- 解读:收益来自两部分:ZeRO-3 让 Ulysses 能放下更多 samples / 更长 sequences;all-to-all 相比 all-gather / reduce-scatter 降低通信量。长 dense attention 下,本地 attention 的
计算会逐渐主导,因此吞吐差距在可共同运行的长序列区间会收窄。
结果 3:Sparse attention 上超过 2x throughput,并支持 4x longer sequence length
- 设置:7B / 30B GPT sparse attention;对比 Megatron-LM sequence parallelism;7B 使用 32 GPUs,30B 使用 64 GPUs。
- 指标:throughput / TFLOPs,最大可运行 sequence length。
- 结果:论文报告 Ulysses 相比 Megatron-LM 有超过 2x throughput,并借助 ZeRO-3 支持 4x longer sequence length。
- 解读:sparse attention 减轻本地 attention 计算占比,通信效率差异更容易体现在端到端吞吐中。论文也指出当时 Ulysses sparse throughput 受本地 sparse attention implementation 限制,说明系统瓶颈会在 distributed layout 和 local kernel 之间移动。
结果 4:固定 131K sequence length 的 strong scaling
- 设置:GPT-7B dense model,global batch size 8,固定 sequence length 为 131,072 tokens,GPU 数从 64 增到 256。
- 指标:iteration time 与 per-GPU TFLOPs。
- 结果:
| Seqlen | GPUs | Time (ms) | TFLOPs/GPU |
|---|---|---|---|
| 131,072 | 64 | 32,432.1333 | 165.526667 |
| 131,072 | 128 | 17,052.5143 | 157.41 |
| 131,072 | 256 | 9,886.7 | 136.09 |
- 解读:时间随 GPU 数增加接近线性下降,但 per-GPU TFLOPs 逐渐下降,说明额外通信、同步和规模化 overhead 开始显现。表格标题写
Time (ms),正文写 microseconds;本笔记按表格单位记录,并保留该文本不一致作为复验注意点。
结果 5:随 sequence length 和 GPU 同比例增长的 scaling
- 设置:GPT-7B dense model,global batch size 8;sequence length 与 GPU 数一起增长。
- 指标:iteration time 与 per-GPU TFLOPs。
- 结果:
| Seqlen | GPUs | Time (ms) | TFLOPs/GPU |
|---|---|---|---|
| 65,536 | 64 | 9,676.76 | 161.3626667 |
| 131,072 | 128 | 17,052.5143 | 157.41 |
| 262,144 | 256 | 33,486.5 | 147.4 |
- 解读:per-GPU TFLOPs 下降不大,但 iteration time 随 sequence length 上升明显。原因是 attention compute 对 sequence length 是 quadratic;Ulysses 让 memory 和 communication 可扩展,但没有消除 exact attention 的二次计算。
结果 6:1.3B GPT 32K convergence study
- 设置:1.3B GPT,sequence length 32K,8 A100 GPUs;DeepSpeed-Ulysses 和 Megatron-LM sequence parallelism 的 sequence parallel degree 都为 4;Ulysses 比较不同 ZeRO stages。
- 指标:训练 loss / convergence curve。
- 结果:论文图 8 显示 Ulysses 与 Megatron-LM sequence parallelism,以及 Ulysses 不同 ZeRO stage 的收敛曲线基本一致。
- 解读:Ulysses 是执行布局变换,不改变 attention 数学语义;这个实验验证了系统优化对训练质量没有可见负面影响。证据规模较小,仍需在更大模型、long-context curriculum 和真实 downstream tasks 上复验。
证据链强度评估
强证据
- 通信公式清晰:Ulysses 每层两次 all-to-all,per-link volume 为
;对比 Megatron-SP 的 很直接。 - 机制清晰:attention 外 sequence-partitioned,attention 内 head-partitioned,前后各一次 all-to-all。
- 系统组合合理:Ulysses 处理 sequence activation,ZeRO-3 处理 model states,FlashAttention-2 处理 local attention kernel。
- 实验覆盖 1M token、7B/30B dense/sparse attention、64/128/256 A100 scaling 和 convergence。
- DeepSpeed 开源实现和 release blog 提供可用性证据,
DistributedAttentionwrapper 降低接入门槛。
中等强度证据
- Dense/sparse attention 对比图的完整数值主要在图中,正文只给趋势和部分表格;精确复验需要跑公开实现。
- ColAI-SP 在论文表格与 release blog 中出现,但 arXiv v2 evaluation 正文主要和 Megatron-LM 对比;不同版本材料的 baseline 叙述需要区分。
- Convergence study 模型为 1.3B、32K、8 A100,能验证语义保持,但对 30B/1M token 训练质量外推有限。
- All-to-all 的优势依赖网络拓扑和 collective implementation;跨节点 IB、拥塞、hierarchical all-to-all、TP/PP/DP/ZeRO group 交织都会影响实际收益。
需要谨慎的推论
- Ulysses 支持 1M token training,不等于 1M context training 在任务质量上必然有效;数据、位置编码、curriculum、loss mask 和 evaluation 都会影响 long-context 能力。
- Ulysses 降低通信/显存压力,但 exact dense attention 的二次计算仍然存在。超长 dense attention 最后会被 local attention compute 限制。
- Head partition 让 sequence parallel degree 与 attention head / head group 粒度相关。现代 GQA/MQA、MLA 或少 head 设置下,需要额外实现设计。
- Ulysses 解决 trainer 侧长序列训练问题;RL rollout / serving 侧的 prefill/decode、KV cache、scheduler、batch invariance 和 logprob consistency 仍需 Sarathi、vLLM/SGLang、TIM/VeXact 等系统处理。
OpenReview / 审稿意见吸收
- Venue status: 当前档案未记录公开 peer-review 状态。
- Public reviews: 当前档案未记录可可靠匹配的 OpenReview / ARR / 会议 reviewer comments。
- Ratings / confidence: 无公开评分可用于校准。
- Reviewer consensus: 暂无。
- Main criticisms: 暂无公开 reviewer 质疑可引用;可信度主要由论文、技术报告、项目证据和本地一致性检查决定。
- Author response: 暂无公开 rebuttal 记录。
- 对本文可信度的影响: 按未完成公开审稿吸收处理,结论需要依赖实验设置、baseline 强度、复现证据和跨论文一致性校准。
本地讨论补充
1. 讨论收敛点
- Ulysses 适合作为本地档案中 long-context distributed training 的基础节点,位置介于 ZeRO 和 Ring Attention 之间。
- 它的核心在于 attention 前后的 distributed tensor layout conversion,attention 公式保持不变。
- 对长序列 RLHF / SFT / continual pretraining,Ulysses 的价值在于保持 global batch size 更可控,把单条长样本沿 sequence 维分摊到多卡。
2. 修正后的理解
- “sequence parallelism”在不同论文中含义不同。FlashAttention-2 的 sequence parallelism 指单卡 kernel 内沿 sequence 切更多 thread blocks;Megatron-SP / Ulysses / Ring Attention 指跨设备 sequence/context dimension 分片。
- Ulysses 的 all-to-all 同时做 sequence-to-head layout transpose,避免把全量 QKV 简单复制到每张卡,使每张卡只承担部分 heads。
- 对 Ulysses 最直接的理解是:先按 sequence 维切分输入,每张卡本地为自己的
tokens 计算 Q/K/V;进入 attention 前,通过 all-to-all 把 local sequence + all heads转成full sequence + subset heads;每张卡随后只对自己负责的 head subset 做完整序列 attention;attention 输出再通过第二次 all-to-all 转回local sequence + all heads,交给后续 MLP、LayerNorm 和 residual。也就是 attention 外按 sequence 切,attention 内按 head 切。 - Ulysses 与 Ring Attention 的差异可以用一句话区分:Ulysses 做 all-to-all head partition,Ring Attention 做 KV stream rotation。
3. TP 与 Ulysses 的 activation 对照
设 micro batch 为
| 模块 / activation | TP 每卡形状 | TP 冗余在哪里 | Ulysses 每卡形状 | Ulysses 怎么省 |
|---|---|---|---|---|
| layer input / residual stream | [B, N, H] |
每个 TP rank 都有完整 sequence 和完整 residual hidden,形成 |
[B, N/P, H] |
sequence 常驻状态直接除以 |
| pre-attn LayerNorm input / output / stats | [B, N, H],stats [B, N] |
LayerNorm 作用在 hidden 维,但每张卡仍持有完整 tokens | [B, N/P, H],stats [B, N/P] |
LayerNorm 只处理本地 tokens |
| QKV projection input | [B, N, H] |
QKV linear 的输入 activation 在 TP ranks 上 full-sequence 复制 | [B, N/P, H] |
每张卡只为本地 tokens 算 Q/K/V |
| QKV projection output | [B, N, 3H/P] |
hidden/head 已切,基本没有 hidden 冗余;但仍覆盖完整 |
[B, N/P, 3H],随后 all-to-all 成 [B, N, 3H/P] |
元素数同为 |
| attention 前布局 | [B, N, heads/P, d] |
TP 的 head-parallel attention 核心:full sequence + subset heads | all-to-all 后同样是 [B, N, heads/P, d] |
attention 内临时变成 TP-like head split |
| QK / softmax / AV 中间量 | 若 materialize: [B, heads/P, N, N] |
dense attention 的二次项,TP 和 Ulysses 都绕不开 | 同 TP | Ulysses 对 dense attention core 没有额外降低;通常依赖 FlashAttention 避免保存完整 attention matrix |
| attention context before output merge | [B, N, H/P] |
head shard,无 hidden 冗余,但是 full sequence | [B, N, H/P] |
和 TP 类似 |
| attention context 回到层主布局 | TP 通常接 row-parallel output projection / all-reduce,回到 [B, N, H] |
attention 后又恢复 full-sequence full-hidden replicated activation | 第二次 all-to-all 回到 [B, N/P, H] |
离开 attention 后立刻回到 sequence shard |
| post-attn dropout / residual | [B, N, H] |
每个 TP rank 都保存完整 tokens 的 residual 结果 | [B, N/P, H] |
per-token activation 省 |
| pre-MLP LayerNorm | [B, N, H] |
full sequence 复制 | [B, N/P, H] |
只处理本地 sequence |
| MLP up/gate projection input | [B, N, H] |
输入 full-sequence 复制 | [B, N/P, H] |
输入 activation 省 |
| MLP intermediate / GeLU / SwiGLU | [B, N, αH/P] |
hidden 已切,但是 full sequence | [B, N/P, αH] |
元素数同为 |
| MLP down projection output | row-parallel 后常回到 [B, N, H] |
full-sequence full-hidden 再次复制 | [B, N/P, H] |
后续层继续 sequence shard |
| layer output / next residual | [B, N, H] |
每层边界 full activation 复制 | [B, N/P, H] |
层边界 activation 省 |
核心结论:
- TP 已经省掉 QKV、attention heads、MLP intermediate 这些 hidden/head 方向的 activation;TP 的主要冗余留在 full-sequence residual、LayerNorm、projection input/output 和 layer boundary activation。
- Ulysses 对 TP 的 activation 节省集中在
[B, N, H] -> [B, N/P, H]这一类常驻 per-token activation。attention core 内部仍是[B, N, H/P],和 TP-like head parallel 很接近。 - 因此 Ulysses 的收益可以概括为:TP 让 attention heads 分摊计算;Ulysses 让长序列 activation 不在每张卡上完整常驻。
4. 后续复验指标
- 通信:all-to-all volume、latency、overlap rate、跨节点/节点内 breakdown、collective algorithm。
- 显存:activation peak、ZeRO-3 parameter all-gather peak、sequence-parallel group 与 data-parallel group 组合后的 model-state memory。
- 吞吐:tokens/s、TFLOPs/GPU、MFU、attention kernel time、MLP time、collective time。
- 质量:long-context validation loss、needle/multi-hop/long-document benchmark、position extrapolation stability。
- RLHF/post-training:rollout/trainer max sequence length、logprob recomputation consistency、padding/loss-mask behavior、KV cache 与 training activation 的边界。
- 架构适配:GQA/MQA/MLA、MoE、sparse attention、FlashAttention-3/4、FP8/FP4、pipeline/tensor/expert parallel 的 group layout。
主要启发
- 长上下文训练系统要同时拆四类维度:model states、sequence activation、local attention kernel、global batch tokens。ZeRO、Ulysses、FlashAttention 各自解决其中一层。
- 系统优化里的“维度转换”很关键。Ulysses 的精髓是根据算子需求切换 layout:非 attention 用 sequence partition,attention 用 head partition。
- 通信公式要按 per-link volume 看。总 message size 大并不直接等于不可扩展;all-to-all 的每条 link 分摊和网络拓扑决定真实瓶颈。
- Exact long-context training 的可行性不只取决于显存。即使通信被摊薄,dense attention 的 quadratic compute 也会成为下一个边界。
- 对 RLHF / agentic long-horizon 训练,training-side context parallelism 只是底座;serving-side rollout 调度、KV cache 管理、MTP/speculative decoding 和 trainer/rollout consistency 需要单独设计。
局限
- Baseline 是 2023 年 Megatron-LM / ColAI-SP 生态,后续 context parallelism 和 attention kernels 已明显演进。
- dense attention 超长序列仍受
compute 限制;Ulysses 主要改善 memory / communication scaling。 - sequence parallel degree 通常受 attention head partition 粒度影响,GQA/MQA/MLA 等现代 attention 形态需要额外处理。
- 论文没有系统评估多种网络拓扑、跨机拥塞、hierarchical all-to-all、communication overlap 和 failure/restart 机制。
- 质量验证规模较小,缺少 million-token pretraining 后的下游 long-context capability 评测。
- 论文侧重 training,不覆盖 serving / RL rollout 中的 KV cache residency、prefill/decode 调度和 batch-invariant determinism。
跨论文关系
- 与 1910.02054:作者上有 Samyam Rajbhandari 和 Yuxiong He 重叠。ZeRO 处理 optimizer states / gradients / parameters 的冗余,Ulysses 处理 sequence activation 和 attention QKV/context layout。两者共同构成 DeepSpeed 大模型训练 memory / communication 底座。
- 与 2310.01889:两者都保持 exact attention 语义并沿 context/sequence 维扩展。Ulysses 用 all-to-all 在 sequence 和 head 之间转换布局;Ring Attention 让 KV blocks 沿 ring 轮转并依赖 blockwise attention 隐藏通信。
- 与 2205.14135 和 2307.08691:FlashAttention 系列优化单卡 local attention kernel 的 IO 和 work partition;Ulysses 优化跨设备 attention 输入/输出布局。Ulysses 可以把 FlashAttention-2 作为本地 attention kernel。
- 与 2405.17381、2606.10650 和 2026-04-24 DeepSeek-V4:Ulysses 是 exact attention + distributed execution 路线;Lightning/DLA/DeepSeek-V4 compressed attention 是 architecture / compression 路线。两类方法都服务长上下文,但质量、成本和系统边界不同。
- 与 2409.19256、verl 官方仓库 和 slime 官方仓库:这些 post-training 系统需要 trainer backend 支撑长序列 actor / critic / reference 训练。Ulysses 可以作为 Megatron/DeepSpeed 训练侧 context-parallel 底座;rollout engine 仍需 vLLM/SGLang/Sarathi/Seer/Bebop 类系统处理生成侧效率。
- 与 2605.14220 TIM/VeXact 和 2025-09-10 batch-invariant inference:Ulysses 改变 trainer 侧张量分布和 collective 路径;当它用于 RL logprob recomputation 或 trainer engine 时,仍需检查 rollout/trainer precision、kernel 和 batch behavior 是否一致。
Reference Intake Brief
Target
- Intended target system: 新增 DeepSpeed Ulysses / sequence parallelism 独立论文笔记;更新索引行和 long-context distributed training 关系章节;补充 DeepSpeed recurring authors。
- Existing related assets: 1910.02054、2310.01889、2205.14135、2307.08691。
- Proposed form: 新建独立 Markdown 文档并更新索引。
Reusable Elements
- Ulysses = sequence partition outside attention + head partition inside attention + two all-to-all layout conversions。
- 通信公式:Ulysses
vs Megatron-SP 。 - ZeRO-3 over data + sequence group 的 model-state sharding。
- Dense/sparse/FlashAttention-2 attention-agnostic wrapper 思路。
- Ulysses / Ring Attention / FlashAttention / ZeRO 的系统层分工。
- 长序列 RLHF/post-training 复验 checklist:trainer context parallel、rollout serving、logprob consistency 分开记录。
Risks
- Copyright/over-copying: 本笔记只转述论文机制和必要公式/表格数值,未复制长段正文。
- Unsourced or unverifiable claims: 作者、版本、实验数值来自 arXiv v2、TeX source、Microsoft Research page 和 DeepSpeed release blog;现代实现关系标为后续复验。
- Tone/brand mismatch: 中文表达遵循本目录规则,避免先否定再强调的对照句式。
- Safety/compliance issues: 论文为训练系统优化,无直接安全滥用内容。
- Overlap with existing assets: 与 Ring Attention / ZeRO / FlashAttention 有强关系;本篇定位为 DeepSpeed all-to-all sequence parallelism 节点。
Skipped
| Material | Reason |
|---|---|
| 图中全部 throughput 精确读数 | PDF 图像没有可靠文本数据;本笔记保留正文趋势和 TeX 表格数值 |
| DeepSpeed 当前 API / tutorial 全量分析 | 属于 2026 当前框架文档问题,可单独归档 |
| ACM proceedings 版本差异 | 本次以 arXiv v2 为准;只记录 ACM DOI 存在 |
Recommendation
Decision: merge。
Why: Ulysses 是 exact long-context training 系统图谱中的关键节点。它把 DeepSpeed 从 ZeRO 的 model-state sharding 推进到 sequence/context dimension sharding,也为理解 Megatron context parallel、Ring Attention、FlashAttention local kernel、长序列 RLHF trainer backend 提供了清晰的张量布局语言。