Token Lab搜索

← 全部实验
KV 缓存与分页 / 2 OF 5

多头注意力缓存

More KV heads scale cache bytes linearly.

本地计算 / 模拟

本地教学实验,不调用外部 API。合成示例不能替代生产环境测量。

学习指南与本课目录LEARNING CONTRACT

理解 → 实现 → 研究

目标:解释本课机制、复现一个例子、测试一个失败案例。读完不自动代表掌握。

02 · 预测与配置

技术场景说明、参数名称与参考答案目前为英文。

03 · 检查证据

运行实验后查看结果。

方法与参考资料

32 layers, head dimension 128. Dense cache only; excludes model weights, activations, block tables and sharing. Per-sequence allocation rounds up to the next page.

Text / 原始公式
KV bytes=2×layers×KV heads×head dimension×sequence×batch×bytes/value

An estimated cache footprint is not a measured GPU throughput or total memory requirement.

GQA (2023); PagedAttention (2023) ↗

PagedAttention paper ↗

练习题

kv-2 / 01What does “Multi-head cache” test?

More KV heads scale cache bytes linearly.

Original teaching answer / local derivation. Method reference: GQA (2023); PagedAttention (2023) ↗

打开实验 →
kv-2 / 02Which computation produces the result in “Multi-head cache”?

KV ×layers×KV heads×head dimension×sequence×batch×bytes/value

Original teaching answer / local derivation. Method reference: GQA (2023); PagedAttention (2023) ↗

打开实验 →
kv-2 / 03What is the baseline configuration for “Multi-head cache”?

{"sequence":4096,"batch":1,"heads":32,"bytes":2,"block":16}

Original teaching answer / local derivation. Method reference: GQA (2023); PagedAttention (2023) ↗

打开实验 →
kv-2 / 04What numerical result should you check for “Multi-head cache”?

{"KV cache (GiB)":2,"Allocated KV (GiB)":2,"Padding tokens":0}

Original teaching answer / local derivation. Method reference: GQA (2023); PagedAttention (2023) ↗

打开实验 →
kv-2 / 05How would you run a controlled comparison for “Multi-head cache”?

Keep the supplied fixture and other settings fixed; change sequence. Compare logical KV GiB, allocated GiB and padding tokens.

Original teaching answer / local derivation. Method reference: GQA (2023); PagedAttention (2023) ↗

打开实验 →
kv-2 / 06What failure could invalidate a conclusion from “Multi-head cache”?

An estimated cache footprint is not a measured GPU throughput or total memory requirement.

Original teaching answer / local derivation. Method reference: GQA (2023); PagedAttention (2023) ↗

打开实验 →
kv-2 / 07Is “Multi-head cache” a benchmark of a deployed language model?

No. 32 layers, head dimension 128. Dense cache only; excludes model weights, activations, block tables and sharing. Per-sequence allocation rounds up to the next page.

Original teaching answer / local derivation. Method reference: GQA (2023); PagedAttention (2023) ↗

打开实验 →
kv-2 / 08Which evidence should you report for “Multi-head cache”?

Compare logical KV GiB, allocated GiB and padding tokens. Export inputs, engine, result and method; distinguish synthetic fixtures from observed production data.

Original teaching answer / local derivation. Method reference: GQA (2023); PagedAttention (2023) ↗

打开实验 →
kv-2 / 09How can another researcher reproduce “Multi-head cache”?

Open kv-2, reset the preset, retain the exact inputs and run. The calculation is deterministic for identical inputs.

Original teaching answer / local derivation. Method reference: GQA (2023); PagedAttention (2023) ↗

打开实验 →
kv-2 / 10What is the next validation step after “Multi-head cache”?

An estimated cache footprint is not a measured GPU throughput or total memory requirement. Test the hypothesis on a representative held-out workload and document a baseline, success metric and stopping rule before claiming deployment readiness.

Original teaching answer / local derivation. Method reference: GQA (2023); PagedAttention (2023) ↗

打开实验 →
MATHEMATICAL REVIEW · 2026-10-26

假设、参考实现与验收

同时计 K/V,使用 KV 头数而不是 query 头数;序列×批次仅乘一次。字节公式不含激活、权重、分配碎片和注意力工作区。

已复核引擎公式、场景预设及数值保护。固定种子的合成输入不是生产基准。

层数、KV 头数、头宽 → 序列 × 批次 = 总 token → K 与 V × 每值字节数 → 逻辑字节 → 分配块
机制图:从上到下跟踪每次变换。

运行前:预测一个边界情况

More KV heads scale cache bytes linearly.

提示:隔离假设

固定基线输入,只改变一个参数或边界;同时比较数值与声明单位。单例通过仅验证该样例。

最小可运行算例

将算例及所链接模块保存在同一目录。使用 Node.js 22 或更高版本,然后运行 node kv-2.mjs. 无需第三方运行依赖。

import {calculate,network} from './academy-core.mjs';
const params={
  "sequence": 4096,
  "batch": 1,
  "heads": 32,
  "bytes": 2,
  "block": 16
};
const result=calculate('kv',params);
console.log(result.metrics);

测试与迁移

More KV heads scale cache bytes linearly.

在下方笔记记录输入、代码版本、期望值和实测值;再构造违反上述假设的反例,解释原结论为何不再成立。

下载完整代码包(.tar.gz) · 完整参考代码与回归检查

预测、检验与证据记录

展开答案前先预测一个结果;练习后记录差异和迁移测试。记录仅存本地,在不同语言版本间共用。

打开记录/导出/清除 →

数学复核范围逐篇记录,不代表完成论文实证复现;可在笔记中记录疑似错误。 复核范围