SGLang统一内存:Token全生命周期的单一竞技场

SGLang统一内存:Token全生命周期的单一竞技场

SGLang 最新发布的统一内存(Unified Memory)功能,通过单一内存竞技场实现全注意力 KV、滑动窗口 KV 与循环状态的动态共享,彻底告别启动时固定分区。

混合模型与内存分割难题

混合模型中,不同注意力层对内存的需求差异巨大:全注意力 KV 随上下文长度增长,滑动窗口 KV 和循环状态则受并发请求数驱动。传统设计需通过 --swa-full-tokens-ratio 等参数预先划分子池,极易造成长上下文与多短请求场景下的内存浪费。

Separate full-attention and bounded-state pools under long-context and many-short-request workloads

统一内存启用 --enable-unified-memory 后,全 KV 与有界状态共享同一字节区域,高低端分别增长,中间形成可动态分配的空闲区。

One arena with full-attention and bounded-state bands sharing the same bytes under both workloads

全新 KV 布局:每 Token 一个 Entry

统一内存将每个 Token 跨所有层的 KV 行打包为单一 Entry,支持不同形状与 dtype 的行共存,便于投机解码草稿 KV 与目标 KV 共享生命周期,也满足 Kimi K3.1 DSA 层索引键与 MLA KV 的融合需求。

Per-token entries whose target-layer rows and draft lanes differ in size, with strided per-layer views

灵活分配与零碎片化

通过延迟压缩与页面重定位,统一内存可在 GPU 操作进行中安全回收与迁移页面,实现任意页大小下的零碎片化复用。

Three arena layouts showing no move, compacting only the ends and relocating a floating bandA freed page becoming pending and a moved page leaving protected old bytes before reuse

端到端内存系统

统一分配器结合调度感知页面生命周期,支持从请求准入到 PD 分离解码预分配的全流程内存管理,并与 Radix Cache、HiCache、推测解码等特性完美兼容。

One arena at the centre: a storage plan builds it, one allocator hands out and moves its pages, and a ledger records who still touches each page