{
 "schema_version": "1.0",
 "page_kind": "article",
 "pack_kind": "generate",
 "slug": "the-kv-cache-in-plain-words",
 "title": "The KV cache, in plain words",
 "dek": "What the keys and the values inside a language model are, why an engine keeps them instead of working them out again, and what that store costs in memory: a sum by hand from a model's own published numbers, held to an engine's own printed line, and why the simple sum runs from 2 to more than 11 times too high for several newer models.",
 "published": "2026-12-02",
 "series": [
  "guide"
 ],
 "licence": "CC BY 4.0",
 "status": "pending-judge",
 "pack_note": "no judge is seated, so every chip is held",
 "notice": "items with published:false are held and are not this page's published words",
 "source": {
  "url": "https://research.strata2signal.com/the-kv-cache-in-plain-words/",
  "md_url": "https://research.strata2signal.com/the-kv-cache-in-plain-words/index.md",
  "md_sha": "230d3f12119fbcfdba84eb1215d3968db359c46ecb6232b069a766b986d2da42",
  "html_sha": "3e32009a02861bb57f6b1b587463d1147f8432c97d2643d96f8dc4e5ea91bc01",
  "anchors_sha": "f131c6d7ebf82793b2a223d359e0fdfa336e0fc3acd3743762ecc9ca59e0d2e3"
 },
 "short": {
  "paragraph": "At every layer of a language model, each token is turned into three short lists of numbers. In our words: its query is what it is looking for, its key is what it offers to be found by, and its value is what it hands over when it is found. To write the next token, the model matches the newest token's query against every key so far and blends the values by how well each key matched. A token's key and value never change once they are made, so an engine keeps them: that store is the KV cache. It is saved working, and an engine can rebuild it from the text. For a model whose every layer is ordinary attention, it costs a fixed number of bytes for every token of window (the context length you set); for seven such models on our roster that is 56 to 320 KiB a token at 16 bits, by our arithmetic. For several newer models the simple sum is from 2 to more than 11 times too high, and this page says why.",
  "from_dek": false,
  "counts": {
   "words": 3740,
   "minutes": 17,
   "tables": 2,
   "kit": false
  },
  "bullets": []
 },
 "sections": [
  {
   "id": "what-a-layer-does",
   "heading": "What a layer does with the words so far",
   "level": 2,
   "span": [
    1902,
    4178
   ],
   "chunks": [
    [
     1902,
     4178
    ]
   ],
   "chars": 2276,
   "digest": "a layer reworks token lists, using multi-head attention to allow a token to read preceding text. attention maps a query, keys, and values to an output. each token generates its own query, key, and value from its list of numbers. a token attends to itself and previous tokens, but never later ones.",
   "digest_skipped": null
  },
  {
   "id": "one-step",
   "heading": "One step, with made-up numbers",
   "level": 2,
   "span": [
    4178,
    5362
   ],
   "chunks": [
    [
     4178,
     5362
    ]
   ],
   "chars": 1184,
   "digest": null,
   "digest_skipped": null
  },
  {
   "id": "why-they-can-be-kept",
   "heading": "Why the keys and values can be kept",
   "level": 2,
   "span": [
    5362,
    6660
   ],
   "chunks": [
    [
     5362,
     6660
    ]
   ],
   "chars": 1298,
   "digest": null,
   "digest_skipped": null
  },
  {
   "id": "what-it-saves",
   "heading": "What it saves, and what it does not",
   "level": 2,
   "span": [
    6660,
    8613
   ],
   "chunks": [
    [
     6660,
     8613
    ]
   ],
   "chars": 1953,
   "digest": null,
   "digest_skipped": null
  },
  {
   "id": "the-arithmetic",
   "heading": "The arithmetic",
   "level": 2,
   "span": [
    8613,
    12468
   ],
   "chunks": [
    [
     8613,
     12468
    ]
   ],
   "chars": 3855,
   "digest": null,
   "digest_skipped": null
  },
  {
   "id": "where-the-simple-sum-is-wrong",
   "heading": "Where the simple sum is wrong",
   "level": 2,
   "span": [
    12468,
    15301
   ],
   "chunks": [
    [
     12468,
     15301
    ]
   ],
   "chars": 2833,
   "digest": null,
   "digest_skipped": null
  },
  {
   "id": "checking-the-sum",
   "heading": "Checking the sum against a card",
   "level": 2,
   "span": [
    15301,
    16231
   ],
   "chunks": [
    [
     15301,
     16231
    ]
   ],
   "chars": 930,
   "digest": null,
   "digest_skipped": null
  },
  {
   "id": "between-requests",
   "heading": "The same trick between requests",
   "level": 2,
   "span": [
    16231,
    17404
   ],
   "chunks": [
    [
     16231,
     17404
    ]
   ],
   "chars": 1173,
   "digest": null,
   "digest_skipped": null
  },
  {
   "id": "the-name",
   "heading": "Where the name comes from",
   "level": 2,
   "span": [
    17404,
    18121
   ],
   "chunks": [
    [
     17404,
     18121
    ]
   ],
   "chars": 717,
   "digest": null,
   "digest_skipped": null
  },
  {
   "id": "what-to-take-with-you",
   "heading": "What to take with you",
   "level": 2,
   "span": [
    18121,
    19014
   ],
   "chunks": [
    [
     18121,
     19014
    ]
   ],
   "chars": 893,
   "digest": null,
   "digest_skipped": null
  },
  {
   "id": "what-this-cannot-say",
   "heading": "What this cannot say",
   "level": 2,
   "span": [
    19014,
    20123
   ],
   "chunks": [
    [
     19014,
     20123
    ]
   ],
   "chars": 1109,
   "digest": null,
   "digest_skipped": null
  },
  {
   "id": "who-ran-this-and-thanks",
   "heading": "Who ran this, and thanks",
   "level": 2,
   "span": [
    20123,
    20490
   ],
   "chunks": [
    [
     20123,
     20490
    ]
   ],
   "chars": 367,
   "digest": null,
   "digest_skipped": "credits"
  },
  {
   "id": "sources",
   "heading": "Sources",
   "level": 2,
   "span": [
    20490,
    25631
   ],
   "chunks": [
    [
     20490,
     25631
    ]
   ],
   "chars": 5141,
   "digest": "the sources include papers from 2017 and 2022, documentation from Hugging Face, llama.cpp, Ollama, and vLLM, and various model configurations. the text was read on 2026-11-30 (UTC).",
   "digest_skipped": null
  }
 ],
 "chips": [
  {
   "id": "c-293b19d4",
   "q": "how does a layer process tokens using attention?",
   "a": "A layer uses multi-head attention to allow a token to read preceding text. It maps a query, representing what the token seeks, and a set of key-value pairs to an output. The query matches against keys to create weights, which are then used to take a weighted blend of the corresponding values.",
   "cites": [
    "what-a-layer-does"
   ],
   "published": false,
   "publish_state": "held",
   "quote": "",
   "quote_cite": ""
  },
  {
   "id": "c-eca4d371",
   "q": "why can previous keys and values be stored?",
   "a": "Because a token only attends to itself and preceding tokens, nothing arriving later can change the representations a previous token's layers worked out. This allows the engine to cache and reuse those keys and values.",
   "cites": [
    "why-they-can-be-kept"
   ],
   "published": false,
   "publish_state": "held",
   "quote": "",
   "quote_cite": ""
  },
  {
   "id": "c-72a43cc6",
   "q": "how do sliding-window layers affect cache calculations?",
   "a": "For models with sliding-window layers, a simple sum overestimates the cache because those layers only look back a fixed distance. In such cases, the total must be calculated layer by layer rather than using a single formula.",
   "cites": [
    "where-the-simple-sum-is-wrong"
   ],
   "published": false,
   "publish_state": "held",
   "quote": "",
   "quote_cite": ""
  }
 ],
 "related": [
  {
   "slug": "temperature-and-sampling-in-plain-words",
   "why": "shares ground with § What a layer does with the words so far · § The model does not pick the word"
  },
  {
   "slug": "the-llama-weights-that-got-out",
   "why": "shares ground with § Sources · § February 2023: a model for researchers, by application"
  },
  {
   "slug": "mixture-of-experts-in-plain-words",
   "why": "shares ground with § What a layer does with the words so far · § What an expert is, and who picks"
  }
 ],
 "thanks": "## Who ran this, and thanks {#who-ran-this-and-thanks}\n\nThanks to the authors of the papers and manuals quoted here, and to the people who post their load logs in public bug reports, which let anyone check a sum. A small human team asked for this page and signed it; AI agents read the sources, did the arithmetic twice by two separate scripts, and wrote the words.",
 "kit": null,
 "seat_class": {
  "writer": "gemma-class",
  "judge": null,
  "writer_runtime": "vllm"
 },
 "bench": {
  "bullets_written": 3,
  "bullets_kept": 0,
  "digests_written": 12,
  "digests_kept": 2,
  "chips_written": 8,
  "chips_kept": 3,
  "chips_grounded": 0,
  "chips_published": 0,
  "dropped_by": {
   "new_noun": 0,
   "figure": 0,
   "length": 0,
   "cite": 0,
   "judge": 0,
   "quote": 0,
   "directive": 0,
   "redaction": 0,
   "profanity": 0,
   "identifier": 0,
   "bare_figure": 0,
   "house_voice": 0,
   "editorial": 0,
   "hand-edit": 18
  },
  "new_noun_tokens_checked": [
   "0.5327",
   "056",
   "072-token",
   "1",
   "128",
   "131",
   "16",
   "16-bit",
   "2",
   "2017",
   "2021",
   "2022",
   "2026-11-30",
   "211",
   "24",
   "26b",
   "3.1",
   "3.1366",
   "3090",
   "32",
   "361.4",
   "362",
   "448",
   "5080",
   "73.327",
   "768",
   "8",
   "8-bit",
   "8B",
   "April",
   "CORE",
   "EVGA",
   "Face",
   "GB",
   "Gaming",
   "GeForce",
   "Google",
   "Hugging",
   "KV",
   "KiB",
   "Llama",
   "MS-01",
   "MiB",
   "Minisforum",
   "NVIDIA",
   "November",
   "OC",
   "Ollama",
   "PC",
   "RTX",
   "Solid",
   "UTC",
   "Ultra",
   "XC3",
   "ZOTAC",
   "gemma4"
  ],
  "new_noun_tokens_withheld": 0,
  "figure_definition": "v3",
  "figure_boundary": "guarded",
  "drops": [
   {
    "kind": "digest",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 298,
    "text_sha": "299945baac9f",
    "section": "one-step",
    "withheld": "one section digest removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "When a new token arrives, each layer makes its query, key and value, adds the key and the value to the cache, and then matches the query against everything in the cache, the token's own key included.",
    "detail": "Carried forward by --carry-hand-edits on 2026-12-01: the writer produced this line again and the pack on disk records it removed by hand on 2026-12-01 (matched on its section). The earlier record reads: removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: When a new token arrives, each layer makes its query, key and value, adds the key and the value to the cache, and then matches the query against everything in the cache, the token's own key included. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "digest",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 301,
    "text_sha": "595c5c6a7d1c",
    "section": "why-they-can-be-kept",
    "withheld": "one section digest removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "It is tempting to call the cache the model's memory of the conversation, and our own fit guide comes close. It is narrower than that.",
    "detail": "Carried forward by --carry-hand-edits on 2026-12-01: the writer produced this line again and the pack on disk records it removed by hand on 2026-12-01 (matched on its section). The earlier record reads: removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: It is tempting to call the cache the model's memory of the conversation, and our own fit guide comes close. It is narrower than that. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "digest",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 291,
    "text_sha": "f3f3dfefd8fd",
    "section": "what-it-saves",
    "withheld": "one section digest removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "The transformers documentation puts the cost of attention for one step as \"quadratic with sequence length\" without the cache and \"linear with sequence length\" with it.",
    "detail": "Carried forward by --carry-hand-edits on 2026-12-01: the writer produced this line again and the pack on disk records it removed by hand on 2026-12-01 (matched on its section). The earlier record reads: removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: The transformers documentation puts the cost of attention for one step as \"quadratic with sequence length\" without the cache and \"linear with sequence length\" with it. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "digest",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 264,
    "text_sha": "716170a505a5",
    "section": "checking-the-sum",
    "withheld": "one section digest removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "was loaded with the cache at 8 bits and again at 16 bits, and the card's memory was read each time. At 32,768 tokens the card held 12,900 MiB with the 8-bit cache and 13,262 MiB with the 16-bit one: 362 MiB apart.",
    "detail": "Carried forward by --carry-hand-edits on 2026-12-01: the writer produced this line again and the pack on disk records it removed by hand on 2026-12-01 (matched on its section). The earlier record reads: removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: was loaded with the cache at 8 bits and again at 16 bits, and the card's memory was read each time. At 32,768 tokens the card held 12,900 MiB with the 8-bit cache and 13,262 MiB with the 16-bit one: 362 MiB apart. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "digest",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 297,
    "text_sha": "75a53b5c5419",
    "section": "between-requests",
    "withheld": "one section digest removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "gave a re-sent prompt's first token in 211 ms against 16.0 s for a fresh one",
    "detail": "Carried forward by --carry-hand-edits on 2026-12-01: the writer produced this line again and the pack on disk records it removed by hand on 2026-12-01 (matched on its section). The earlier record reads: removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: gave a re-sent prompt's first token in 211 ms against 16.0 s for a fresh one. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "digest",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 261,
    "text_sha": "40f1951b0d1d",
    "section": "what-to-take-with-you",
    "withheld": "one section digest removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "For ordinary attention, its size is 2 x layers x key-value heads x head width, times the bytes a number takes, for every token of window the engine reserves.",
    "detail": "Carried forward by --carry-hand-edits on 2026-12-01: the writer produced this line again and the pack on disk records it removed by hand on 2026-12-01 (matched on its section). The earlier record reads: removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: For ordinary attention, its size is 2 x layers x key-value heads x head width, times the bytes a number takes, for every token of window the engine reserves. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "digest",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 249,
    "text_sha": "b631731a81ac",
    "section": "what-this-cannot-say",
    "withheld": "one section digest removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "Why writing slows by the amount it does",
    "detail": "Carried forward by --carry-hand-edits on 2026-12-01: the writer produced this line again and the pack on disk records it removed by hand on 2026-12-01 (matched on its section). The earlier record reads: removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: Why writing slows by the amount it does. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "bullet",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 77,
    "text_sha": "56866215c6ba",
    "figure": "211",
    "withheld": "one bullet removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "under Ollama",
    "detail": "removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: under Ollama. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "bullet",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 67,
    "text_sha": "73ff08cc7994",
    "figure": "1,056",
    "withheld": "one bullet removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "For a model whose every layer is ordinary attention",
    "detail": "removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: For a model whose every layer is ordinary attention. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "bullet",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 61,
    "text_sha": "5310f08af41e",
    "figure": "3.1366",
    "withheld": "one bullet removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "Every number is made up to show the arithmetic.",
    "detail": "removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: Every number is made up to show the arithmetic. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "digest",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 283,
    "text_sha": "32c7df4c2a16",
    "section": "the-arithmetic",
    "withheld": "one section digest removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "a value is what it hands over",
    "detail": "removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: a value is what it hands over. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "digest",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 295,
    "text_sha": "3d7279c3d7ac",
    "section": "where-the-simple-sum-is-wrong",
    "withheld": "one section digest removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "left at its defaults on CUDA and ROCm cards",
    "detail": "removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: left at its defaults on CUDA and ROCm cards. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "digest",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 289,
    "text_sha": "1b4855c3f3d2",
    "section": "the-name",
    "withheld": "one section digest removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "Who said it first, we do not know.",
    "detail": "removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: Who said it first, we do not know. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "chip",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 287,
    "text_sha": "9329d6aa68d0",
    "chip_id": "c-e15d813a",
    "withheld": "one chip removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "for one step",
    "detail": "removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: for one step. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "chip",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 265,
    "text_sha": "4793528cc328",
    "chip_id": "c-f5cf05c8",
    "withheld": "one chip removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "are of no further use.",
    "detail": "removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: are of no further use. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "chip",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 258,
    "text_sha": "30e7927c4d61",
    "chip_id": "c-fea62bed",
    "withheld": "one chip removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "a value is what it hands over",
    "detail": "removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: a value is what it hands over. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "chip",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 234,
    "text_sha": "38a565f859b8",
    "chip_id": "c-f0d0d15f",
    "withheld": "one chip removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "we did not read Ollama's code to check that",
    "detail": "removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: we did not read Ollama's code to check that. Not a gate drop, and recorded here so the ledger adds up."
   },
   {
    "kind": "chip",
    "reason": "hand-edit",
    "item": null,
    "item_chars": 280,
    "text_sha": "483641af3318",
    "chip_id": "c-48cc5f18",
    "withheld": "one chip removed from this pack by hand",
    "removed_utc": "2026-12-01",
    "why": "On a Minisforum MS-01 mini PC (Intel Core i5-12600H, 32 GB) with no graphics card in use",
    "detail": "removed from this pack by hand on 2026-12-01 (UTC), after the writer ran and after the gates had counted: On a Minisforum MS-01 mini PC (Intel Core i5-12600H, 32 GB) with no graphics card in use. Not a gate drop, and recorded here so the ledger adds up."
   }
  ]
 },
 "generated_utc": "2026-12-01T18:42:20Z"
}
