KV Cache 曲线计算器

按真实注意力结构估算不同模型的 KV cache 显存,并观察它随上下文长度增长的变化。

参数控制 调整上下文、精度、Batch、TP 和参与对比的模型。
曲线与卡片 比较增长趋势,并查看当前上下文下的显存占用。
参数明细 核对计算结构、原生窗口、备注并导出结果。
RSS订阅

KV cache 占用曲线

纵轴单位:GiB。虚线表示超过该模型公开 native context 后的公式外推。
X 轴:0–1,048,576 tokens 架构感知 2 bytes / element

模型卡片

全部 18 个模型
没有匹配的模型,请换个关键词或公司。

模型参数与计算结果

模型 用于计算的结构 每 token KV 当前上下文 1M 点 Native context 备注
公式与架构感知模式说明
架构感知计算原则: 标准 GQA 层按 T × 2(K,V) × KV heads × head_dim × bytes 计算;SWA 层只保留 min(T, window);recurrent / linear attention state 不按逐 token KV 计算,公开状态形状时单独计入固定缓存;稀疏索引与压缩缓存按模型公开实现单独计入。 所有结果再乘以 batch / tensor_parallel。
Inkling-Small 架构感知: 官方 config:42 层、8 KV heads、head_dim=128;7 层 full GQA,35 层 sliding-window GQA,window=512,native context=1,048,576。 注意力 KV_bytes = bytes × 2(K,V) × 8 × 128 × [7 × T + 35 × min(T,512)]。 模型每层另有 K、V、attention output、MoE output 四路 short convolution。本站按 vLLM 的 BF16 page layout 计入固定 sconv cache:每个 KV head 的原始宽度 1,280 padding 到 2,048,保留 4 slots,因此 TP=1 时 42 层合计 5.25 MiB。 在 BF16、batch=1、TP=1、1M context 下,全局 KV 为 28 GiB、SWA KV 为 70 MiB、sconv 为 5.25 MiB,总计约 28.07349 GiB。 相对位置项不产生随历史 token 增长的额外 cache;8 层 MTP、视觉/音频编码器和框架 page-size 对齐的额外浪费不计入主曲线。
GLM-5.1 / GLM-5.2 架构感知: 两者均为 78 层、每层保存 512 维 KV latent + 64 维 RoPE key;DSA 的完整 indexer 另存 128 维 index-K。 GLM-5.1:78 个完整 indexer,因此 elements/token = 78 × (512 + 64 + 128)。 GLM-5.2:IndexShare 由 21 个完整 indexer 服务其余 57 层,因此 elements/token = 78 × (512 + 64) + 21 × 128。 在 BF16、batch=1、TP=1 下,两者分别为 107.25 KiB/token 与 93 KiB/token;GLM-5.2 在 1M context 为 93 GiB。 这里统一按所选 KV 精度计算 index-K;实际引擎可为主 MLA cache 与 indexer cache 采用不同量化格式。
Kimi K2.5 / K2.6 / K2.7 Code 架构感知: 三者公开 config 的文本模型结构相同:61 层 MLA、kv_lora_rank=512、qk_rope_head_dim=64、native context=262,144。 KV_bytes = T × bytes × 61 × (512 + 64) 因此 BF16、batch=1、TP=1 时为 68.625 KiB/token,在 256K context 为 17.15625 GiB。 三条曲线完全重合是架构参数相同的结果;视觉编码器缓存不计入本页文本 KV cache。
MiMo V2.5 Flash / Pro 架构感知: MiMo V2.5(本页按常用别名标为 Flash)为 48 层:9 个 full-attention 层使用 8 KV heads,39 个 SWA 层使用 4 KV heads;Pro 为 70 层:10 full + 60 SWA,均使用 8 KV heads。 两者 key/value head dim 分别为 192/128,SWA window=128,native context=1,048,576。 KV_bytes = bytes × [(full_layers × T × full_KV_heads + SWA_layers × min(T,128) × SWA_KV_heads) × (192 + 128)] 因此 BF16、batch=1、TP=1、1M context 时,Flash 约为 45.01 GiB,Pro 约为 50.04 GiB;视觉与音频编码器缓存、3 层 MTP 草稿状态不计入文本主模型 KV cache。
腾讯 Hy3 架构感知: 官方 config:80 个主 decoder 层、8 KV heads、head_dim=128、native context=262,144;1 个 MTP 层不计入主模型 KV cache。 KV_bytes = T × bytes × 80 × 8 × (128 K + 128 V) 因此 BF16、batch=1、TP=1 时为 320 KiB/token,在 256K context 为 80 GiB。
Qwen3.5 架构感知: 60 层 = 15 × (3 个 Gated DeltaNet 线性注意力层 + 1 个 Gated Attention 层)。 本页只把 15 个 Gated Attention 层计入随 token 增长的 K/V cache。 DeltaNet 的 recurrent / convolution state 不按逐 token K/V cache 计入。
MiniMax M3 架构感知: 官方 config:60 层、4 KV heads、head_dim=128;前 3 层为 full GQA,后 57 层启用 MSA。 MSA 为选择分支,不会删除需要被任意检索的主 K/V cache;57 个 MSA 层另存 1 个 index-K head(dim=128)。 KV_bytes = T × bytes × [60 × 2 × 4 × 128 + 57 × 1 × 128] 因此 BF16、batch=1、TP=1 时,主 K/V 为 120 KiB/token,计入 index-K 后总量为 134.25 KiB/token。 注意:MSA 的主要收益是把每次注意力读取限制在固定 Top-K block,而不是把持久 KV cache 变成常数空间。
Kimi K3 架构感知: 官方 config:93 层 = 69 KDA + 24 Gated MLA;MLA 每层保存 512 维 KV latent + 64 维 RoPE key,native context=1,048,576。 KDA 使用 96 heads、head_dim=128、short-conv kernel=4。按 vLLM 的状态布局,每个 KDA 层保存 96 × 128 × 128 个 FP32 recurrent elements,以及 3(Q/K/V) × 96 × 128 × (4−1) 个所选精度的 convolution elements。 Cache_bytes = T × bytes × 24 × (512 + 64) + 69 × [96 × 128 × 128 × 4 + 3 × 96 × 128 × 3 × bytes] 因此 BF16、batch=1、TP=1、1M context 时,Gated MLA 为 27 GiB,KDA 固定状态约 0.41851 GiB,合计约 27.41851 GiB。Attention Residuals 不产生随历史 token 持久化的 KV cache;视觉编码器缓存不计入文本主模型。
Laguna-S-2.1 架构感知: 官方 config:48 decoder layers、8 KV heads、head_dim=128;12 层 full attention,36 层 sliding-window attention,sliding_window=512,native context=1,048,576。 entry = 2 × KV heads × head_dim × bytes KV_bytes = 12 × T × entry + 36 × min(T, 512) × entry 因此 BF16、batch=1、TP=1、1M context 时,KV cache 约为 48.07 GiB。配置中的逐层 Q-head 数为 full=48、SWA=72,但 KV heads 始终为 8,不改变 KV cache 公式。
Step-3.7-Flash 架构感知: 45 decoder layers = 12 × full_attention + 33 × sliding_attention,sliding_window = 512。 entry = 2 × KV heads × head_dim × bytes KV_bytes = full_layers × T × entry + sliding_layers × min(T, 512) × entry 其中 KV heads = 8,head_dim = 128。
DeepSeek-V4 架构感知: Flash 使用前 43 层 compress_ratios:2 个 SWA-only、21 个 c4a、20 个 c128a。 Pro 使用前 61 层 compress_ratios:30 个 c4a、31 个 c128a;inference config 的最后 1 个 0 对应 next-n/MTP,不计入核心 decoder。 SWA-only: min(T, 128) × head_dim × bytes c4a: [min(T,128) + ceil(max(T-128,0)/4)] × head_dim × bytes + ceil(T/4) × index_head_dim × bytes c128a: [min(T,128) + ceil(max(T-128,0)/128)] × head_dim × bytes 其中 head_dim = 512,index_head_dim = 128。

注意:实际部署中的 KV cache 还会受 paged attention block size、prefix cache、KV 量化格式、tensor parallel 切分方式、 MTP/speculative decoding、服务框架预留内存、batch scheduling、视觉 token 等影响。这个 SPA 适合做容量估算和不同架构的量级对比。