{
  "analytic": "attention-memory",
  "kind": "declared_analytical_or_constructed_example",
  "experimental_model_result": false,
  "panels": [
    {
      "kind": "line",
      "x": [
        1024,
        2048,
        4096,
        8192,
        16384,
        32768
      ],
      "series": [
        {
          "label": "Materialized scores, one layer",
          "y": [
            0.0625,
            0.25,
            1.0,
            4.0,
            16.0,
            64.0
          ]
        },
        {
          "label": "KV, 32 layers",
          "y": [
            0.125,
            0.25,
            0.5,
            1.0,
            2.0,
            4.0
          ]
        }
      ],
      "xlabel": "Sequence length (tokens)",
      "ylabel": "GiB",
      "logx": true,
      "logy": true
    }
  ],
  "title": "Attention storage and KV state are different budgets",
  "assumptions": "Batch 1; score heads 32; KV heads 8; head dimension 128; FP16; scores for ONE layer, KV for 32 layers. Activations and workspaces omitted.",
  "worked": "在8192 token时，单层32头分数矩阵为4 GiB；32层、8个KV头的缓存为1 GiB。它们属于不同生命周期，不能将本图当作峰值显存或FlashAttention测速。",
  "source_ids": [
    "attention",
    "flash",
    "longformer",
    "arxiv-2104.09864"
  ],
  "formula_source": "Article equations and this versioned script",
  "diagram_nodes": [
    "词元与位置表示",
    "Q、K、V 投影",
    "分块分数与因果屏蔽",
    "运行最大值 / 分母 / 加权和",
    "多头合并与逐位置变换",
    "prefill 与逐步 decode"
  ]
}
