ZeRO - memory optimizations toward training trillion parameter models

并行理论的黑称 Vertical Split: 竖切, PP Horizontal Split: 横切, TP 消耗显存的模块分类 Part Category Included Items Description 1 Model states optimizer states, gradients, parameters For large models, the majority of the memory is occupied by model states. 2 Residual states activation, temporary buffers, unusable fragmented memory The remaining memory is consumed by residual states. Model State 不足分析 + ZeRO-DP 性能 Parallelism Method Why Compute Efficiency Is High / Low Why Memory Efficiency Is High / Low Core Mechanism Main Problem Data Parallelism (DP) High compute efficiency because each GPU runs the full model independently on its own mini-batch, so computation is large-grained and continuous, and communication is mainly limited to gradient synchronization. Low memory efficiency because each GPU stores a full copy of all model states, including parameters, gradients, and optimizer states. Replicate the full model on every GPU, split data across GPUs, then synchronize gradients. Heavy memory redundancy across GPUs. Model Parallelism (MP) Low compute efficiency because one model computation is split across multiple GPUs, which introduces fine-grained coordination, frequent synchronization, and expensive communication on the critical path. High memory efficiency because each GPU stores only a partition of the model states instead of the full model. Partition the model itself across GPUs so each GPU holds only part of the parameters / states. Communication overhead, synchronization cost, and reduced scalability. ZeRO-DP Tries to retain the high compute efficiency of DP by preserving DP-style computation granularity and communication pattern as much as possible. Tries to achieve the high memory efficiency of MP by partitioning model states across data-parallel processes instead of fully replicating them. Keep DP-style training flow, but partition optimizer states, gradients, and eventually parameters to remove redundancy. More complex state management and dynamic communication scheduling. ...

2026-05-20 · 4 min · Yuchen You

Taming Throughput-Latency Tradeoff in LLM Inference with Sarathi-Serve

Sarathi-Serve 把 prefill 分块, 再与正在运行的 decode 请求混合调度, 目标是兼顾吞吐与 token 生成延迟. 这里讨论的是同一 serving 系统中的调度方式, prefill/decode 可以在同一个 batch 中执行. 原论文, OSDI 2024. Prefill vs. Decode Prefill 阶段做了什么 prefill = 对整个 prompt 做一次完整的 transformer forward. 包括了: 对所有输入 token 一起做 embedding 过每一层的 attention 过每一层的 FFN 同时把每层对应的 K/V 写入 KV cache 最后根据最后位置的 hidden state 过 lm head, 得到 next-token logits 采样 / greedy / top-k / top-p, 选出第一个输出 token 较长的 prompt 提供了足够多可以一起计算的 token, 能提高矩阵运算的算术强度. 在论文讨论的配置下, prefill 通常表现为 compute-bound. ...

2026-05-20 · 3 min · Yuchen You

Megatron-LM - Training Multi-Billion Parameter Language Models Using Model Parallelism

Attention 计算的线性代数问题 attention 和 FFN 的关系 如果记某层输入为 x, 那么可以粗略理解成: attention 输出: 给 x 补充上下文信息, 像"开会听别人说话" FFN 输出: 给 x 补充局部计算后的新特征, - 像"你自己在脑子里消化, 归纳, 形成判断" 如果我们尝试把一个 FFN 层变成一个 attention 层, 结果就是可能会更加适合长距离语义传输但是缺少本地语义特征变换器 多层 attention-FFN 结构 可以理解为不断重复"交换信息 $\rightarrow$ 消化信息 $\rightarrow$ 再交换 $\rightarrow$ 再消化" 也就是说各自对本 token 处于上下文的含义理解之后再次进行交换分享,让整体的文意理解更加深刻 ...

2026-05-20 · 4 min · Yuchen You

GPipe - efficient training of giant neural networks using pipeline parallelism

神经网络基础 如图是一个基础的神经网络结构, 我们这里首先要明确几个函数: 每一层内部的计算是 $h_i := \sigma(z_i)$, $z_i := W_i h_{i-1} + b_i$ 我们最终的输出函数是 $L :=$loss(sample; forward) forward: 指的是从输入样本数据 $h_0$ 到 最终输出 $\sigma(z_2)$ 的所有计算过程 backward: 从 $L$ 开始不断计算每一层中的 $\frac{\partial L}{\partial W_i}$ 和 $\frac{\partial L}{\partial b_i}$ 的方向梯度, 然后用这个来不断更新 $W_i,\ b_i$ 现在来拆解一下反向传播的过程: 基本根据的是莱布尼茨链式法则 (chain-rule) ...

2026-05-20 · 6 min · Yuchen You

21. The Design and Implementation of a Log-Structured File System

Design for File Systems of the 1990’s 文件系统的设计受到两种力量驱动: 技术 (Technology): 提供基本的硬件能力与性能边界; 工作负载 (Workload): 决定系统需要高效完成的操作类型; 本节总结了 1990 年代的技术变迁及其对文件系统设计的影响, 并说明为何当时的传统文件系统难以适应这些变化, 从而引出了 Sprite LFS(Log-Structured File System) 的设计动机; ...

2025-10-06 · 11 min · Yuchen You

20. Lottery Scheduling: Flexible Proportional-Share Resource Management

Lottery Scheduling 基本机制 Resource Rights (资源权利) 彩票 (ticket) 表示资源权利, 具有 三个性质: 抽象 (abstract): 与具体机器细节无关; 相对 (relative): 票所代表的份额随竞争情况 (总彩票数量) 动态变化; 统一 (uniform): 异构资源都能抽象为 tickets; 比如各种 CPU, I/O 设备; Lotteries (抽签调度) 每次调度就是一次抽签, 任务的获胜概率: $p = \frac{t}{T}$, 其中 t = 本任务票数, T = 总票数; 获胜次数服从 binomial distribution; 等待第一次获胜的时间服从 geometric distribution; 长期看, 任务的资源份额 $\approx$ 票份额; 因此保证概率公平 (probabilistic fairness); 任何持有 非零 票数的任务都会在有限时间内赢得抽签, 因此不会出现饿死 (starvation); 问题: 如果一个任务的彩票数量很少, 为什么不会 starvation? 它被运行的概率不是应该很低吗? 回答: 只要任务持有的票数大于零, 它在每次抽签中都有非零的获胜概率;虽然概率可能很小, 但等待时间服从几何分布, 期望为 1/p, 是有限的;因此平均响应时间有限, 任务最终一定会运行, 不会像传统优先级调度中那样被永久饿死; ...

2025-10-01 · 5 min · Yuchen You

19. Scheduler Activations: Effective Kernel Support for the User-Level Management of Parallelism

背景 并行计算的效果, 取决于创建和管理并行的开销; 开销大的话即使 coarse grained parallelism 也不划算; 开销小的话, 即使 fine grained parallelism 也划算; 传统 UNIX 进程 = 单地址空间 + 单执行流; 设计目标是单核多道程序环境(multiprogramming), 适合粗粒度并行, 不适合细粒度并行; 线程支持的两种方式 用户级线程 (User-level threads) 通过 runtime library 库实现(不改内核); 优点: 性能好: 上下文切换, 创建销毁的代价接近过程调用; 灵活: 可以按语言/应用需求定制; 缺点: 内核对线程不可见, 仍然只认识"进程"; 进程就像虚拟 CPU, 被内核调度到物理 CPU 上; 遇到 I/O 阻塞, 页面缺页, 多道并发 时, 线程库感知不到真实 CPU 情况, 导致性能下降甚至错误; 内核级线程 (Kernel threads) 内核直接提供多线程支持, 每个线程对内核可见, 内核负责调度; 优点: 与系统资源和调度机制直接集成, 没有"virtual/real processor 错位"的问题; 不会出现用户级线程那种 “一挂全挂”(比如一个线程阻塞整个进程); 缺点: 内核操作比用户空间 heavyweight 得多; 性能明显比用户级线程差 (通常差一个数量级); 对于很多并行程序仍然"太重"; ULT 库会在程序启动时调用内核 API(比如现代系统里 pthread_create())来创建一批内核线程; 数量一般与物理 CPU 数接近, 用来"占位", 相当于"虚拟 CPU 池"; ULT 线程 绑定 在这些 KLT 上运行 每个内核线程里跑的是用户线程库的调度循环; 库自己决定哪个用户线程在这个内核线程里执行; 所以用户线程确实是基于内核线程执行的; ...

2025-09-30 · 5 min · Yuchen You

Memory Resource Management in VMware ESX Server

Introduction VMware ESX Server is a thin software layer designed to multiplex hardware resources efficiently among virtual machines. The current system virtualizes the Intel IA-32 architecture In contrast, ESX Server manages system hardware directly, providing significantly higher I/O performance and complete control over resource management. machine addr: real hardware address physical addr: guest OS’s address pmap: data structure for each VM that maps physical addr to machine addr (ppn -> mpn) 注意这就是 EPT 的功能, 只是 2002 年 Intel 还没有 EPT 技术 Reclamation Mechanisms 每个虚拟机都会有一个 constant max size (Virtual Mem), 也就是一旦启动之后就不会变了 Overcommit: 过量使用后收回页替换机制 如果出现 ESX 宿主机承诺了过量的内存页使用量, 就会出现问题: 如何回收? 如果使用基于 pmap 的额外页表机制, 就还要改一下接口, 也就是撤回的页必须以 (VM, Vaddr) 这样的 tuple 形式才能让 ESX 实现页的撤回, 也就是 Meta-level Page Replacement 但是 ESX/VMM 层并不能知道哪个页更适合 evict, 这只有 guest OS 才知道 Double Paging Problem: 这样设计也会导致 double paging 的问题, VMM 撤回了某个特定的 (VM, page), 但是该 VM 在同时也在对应 page 写入了新的内容, 这样就会出现 inconsistency Balloon 机制 ...

2025-09-29 · 7 min · Yuchen You

My VM is Lighter (and Safer) than your Container

Introduction 背景 容器(Docker/LXC)在工业界广泛应用: Google, AWS, Azure, GCP 都依赖容器; 容器优势: 快速实例化(毫秒~百毫秒) 高密度运行(单机可数千~上万实例) 内存占用小, 镜像体积小 问题 安全性不足: 容器暴露 400+ syscalls, 内核攻击面巨大; 隔离性不如 VM, 常需要"容器运行在 VM 内"来补强; 资源滥用(fork bomb, 文件描述符耗尽)可导致宿主机 DoS; 目标 结合容器的轻量性与 VM 的强隔离; 需求: 毫秒级实例化 高密度运行 小镜像/低内存占用 快速挂起/恢复 保持 VM 的硬件隔离安全性 贡献 分析 Xen 性能瓶颈, 重构控制面: 移除 XenStore (noxs), 消除中心化瓶颈; 新工具链 chaos/libchaos + split toolstack; 提出 Tinyx 工具, 生成极小 Linux VM; 支持 unikernel; 实现 LightVM ...

2025-09-23 · 10 min · Yuchen You

The Turtles Project: Design and Implementation of Nested Virtualization

Authors: Muli Ben-Yehuda et al., IBM Research / IBM Linux Technology Center 1. 背景与动机 传统虚拟化 (single-level): 一个 hypervisor (L0) 管理多个 VM, 每个 VM 运行 OS; 嵌套虚拟化 (nested virtualization): 允许一个 hypervisor (L1) 作为 guest 运行, 并且还能继续运行自己的 VM (L2); 需求来源: 现代操作系统自带虚拟化功能(Windows XP mode in Win7, Linux 内置 KVM); IaaS 场景: 云提供商 (L0) 希望用户能运行自己的 hypervisor (L1), 自己管理 VM (L2); 研究和测试: 嵌套虚拟化方便调试/benchmark hypervisor; 安全性: 可以研究/防御 hypervisor-level rootkit; IaaS (Infrastructure as a Service) 云计算三层服务之一: IaaS / PaaS / SaaS; IaaS = 提供虚拟化的计算资源(VM, 存储, 网络); 例子: AWS EC2: 创业公司快速租用 VM, 按需扩展; Google Cloud GPU: 科研人员租用 A100 GPU VM; 与论文关系: 云提供商必须支持 nested virtualization, 才能让用户在 VM 内运行自己的 hypervisor; 2. 虚拟化理论基础 Popek–Goldberg (1974) 三大条件: 等价性 (equivalence), 资源控制 (resource control), 效率 (efficiency); 定理: 如果架构中所有 sensitive 指令 都是 privileged 指令, 则该架构是可虚拟化的; 影响: 解释了早期 x86 不可完全虚拟化 $\rightarrow$ VMware 使用二进制翻译绕过; 推动了 Intel/AMD 添加 VT-x / SVM 硬件扩展; 3. 两种嵌套虚拟化模型 1) Multi-level support 硬件直接支持多层 hypervisor; Trap 从 L2 直接交给 L1; 例子: IBM System z; 高效, 但硬件设计复杂; 且一般多层的支持都是有限的, 如只支持两层, 这篇论文是在理论上支持任意层数的嵌套虚拟化, 因此更高层的虚拟化实际上还是依赖于单层虚拟化的软件支持逻辑: compress 2) Single-level support 硬件只有一层 root mode (L0); 所有 trap(无论来自 L1, L2, L3)都掉到 L0; L0 决定是否转发给 L1; 例子: x86 的 Intel VT-x (VMX), AMD SVM; Multiplexing single-level: L0 将唯一的一层虚拟化能力"复用", 对上层 L1/L2 进行模拟; 4. CPU 虚拟化 (VMX) VMX & L0 VMX = Intel VT-x 的指令扩展集; L0 = 唯一运行在 VMX root mode 的 hypervisor; 所有 VMExit/VMEntry 都必须经过 L0; Trap 流程: Single-level support: L2 trap $\rightarrow$ L0 trap handler $\rightarrow$ L0 转发给 L1; ...

2025-09-22 · 4 min · Yuchen You

A Comparison of Software and Hardware Techniques for x86 Virtualization

The main technical contributions of this paper are: a review of VMware Workstation’s software VMM, focusing on performance properties of the virtual instruction execution engine; a review of the emerging hardware support, identifying performance trade-offs; a quantitative performance comparison of a software and a hardware VMM. Establishes three essential characteristics for system software to be considered a VMM Fidelity(保真性) Software on the VMM executes identically to its execution on hardware, barring timing effects. Performance(高性能) An overwhelming majority of guest instructions are executed by the hardware without the intervention of the VMM. Safety(安全性) The VMM manages all hardware resources. 1. 基础概念 VMM vs Hypervisor VMM (Virtual Machine Monitor): 来自 Popek & Goldberg (1974), 强调核心虚拟化功能(trap & emulate, BT, shadow structures); 负责虚拟机执行控制; Hypervisor: 工程上更常用的术语, 指整个虚拟化层; 包含 VMM, 同时提供调度, 资源分配, 设备模型, 管理接口; Type 1(bare-metal, 如 Xen, ESXi), Type 2(hosted, 如 VMware Workstation); ...

2025-09-21 · 5 min · Yuchen You

Xen and the Art of Virtualization

背景 应用设计需要一个稳定的环境, 而传统的 OS 隔离技术不足以支持这种要求, 比如一个程序消耗了大量的算力并且被 scheduler 赋予了非常高的优先级, 或者系统被程序攻击了, 从而被某个其他进程消耗了很多资源导致当前进程的性能受损, 因此需要更高层的 VM 设计来实现工业界需要的 isolation 级别 ...

2025-09-15 · 10 min · Yuchen You