# Zarządzanie KV cache

EN: **KV cache management** · id `kvcache`

Path: [AI Atlas](https://aiatlasgraph.com/llms.txt) › [Inferencja i infrastruktura](https://aiatlasgraph.com/t/systems.md) › [Serwowanie i dekodowanie](https://aiatlasgraph.com/t/serving.md) › Zarządzanie KV cache

## Description

- PL: Pamięć podręczna atencji przy generowaniu: stronicowanie, współdzielenie, kompresja.
- EN: The attention cache during generation: paging, sharing, compression.

## In one sentence

- PL: To przechowywanie części wcześniejszych obliczeń uwagi, żeby model nie powtarzał ich przy każdym nowym fragmencie odpowiedzi.
- EN: This stores earlier attention computations so a model need not repeat them for every new response element.

## Problem it solves

- PL: Długa rozmowa wymaga coraz więcej pamięci, a jej ponowne przeliczanie przy każdym słowie byłoby kosztowne.
- EN: A long conversation needs growing memory, while recomputing it for every word would be costly.

## What it does

- PL: Zapisy można dzielić na bloki, współdzielić dla zgodnych początków lub kompresować, kontrolując zajęte miejsce i wpływ zmian na wynik.
- EN: Cached representations can be blocked, shared for matching prefixes or compressed, while monitoring memory use and effects on results.

## Everyday example

- PL: Serwer zachowuje obliczenia wcześniejszego tekstu i przy dalszej odpowiedzi wykorzystuje je zamiast liczyć wszystko od początku.
- EN: A server keeps earlier text computations and reuses them for later response elements instead of recalculating everything.

## This concerns you if you…

- PL: prowadzisz długie rozmowy z modelem
- PL: pamięć ogranicza liczbę obsługiwanych zapytań
- EN: hold long conversations with a model
- EN: find memory limits how many requests can be served

## Keywords

PagedAttention · RadixAttention · grouped-query attention · multi-head latent attention · prefix sharing · memory fragmentation · KV pages

## How it works

- PL: Klucze i wartości wcześniejszych tokenów zachowuje się, aby nie przeliczać ich przy każdym kroku dekodera. Stronicowanie mapuje logiczne pozycje na bloki pamięci, a zgodne prefiksy mogą współdzielić stan z kontrolą własności i wersji.
- EN: Earlier-token keys and values are retained to avoid recomputation at every decoder step. Paging maps logical positions onto memory blocks, while matching prefixes can share state with ownership and version controls.

## Limits

- PL: Rozmiar zależy od kontekstu, warstw, głów i współbieżnych sekwencji. Współdzielenie wymaga zgodności modelu oraz prefiksu; kompresja zmienia dokładność, a przenoszenie stanu zwiększa koszt transferu.
- EN: Size depends on context, layers, heads and concurrent sequences. Sharing needs matching models and prefixes; compression changes accuracy, while moving state adds transfer costs.

## Key terms

- PL: **strona KV**: Blok pamięci przechowujący fragment kluczy i wartości sekwencji.
- PL: **fragmentacja**: Niewykorzystana pamięć wynikająca z niedopasowania przydziału do potrzeb.
- EN: **KV page**: A memory block storing part of a sequence's keys and values.
- EN: **fragmentation**: Unused memory caused by allocation mismatching requirements.

## Know first

- [Mechanizm self-attention (zapytania, klucze, wartości) (Self-attention (queries, keys, values))](https://aiatlasgraph.com/t/selfattention.md)
- [Tokenizacja tekstu (BPE, WordPiece, SentencePiece) (Text tokenisation (BPE, WordPiece, SentencePiece))](https://aiatlasgraph.com/t/tokenization.md)

## Examples

- PL: PagedAttention · GQA · MLA

## Related topics

Untyped, symmetric "see also" links.

- [Architektury hybrydowe: uwaga + warstwy liniowe (Hybrid architectures: attention plus linear/recurrent layers)](https://aiatlasgraph.com/t/hybridattention.md)
- [Cache promptu (wspólny początek zapytań) (Prompt (prefix) caching)](https://aiatlasgraph.com/t/promptcaching.md)
- [FlashAttention](https://aiatlasgraph.com/t/flashattn.md)
- [Oszczędne warianty uwagi (MQA, GQA, MLA) (Memory-efficient attention variants (MQA, GQA, MLA))](https://aiatlasgraph.com/t/attnvariants.md)
- [Pamięć HBM i ściana pamięci (High-bandwidth memory and the memory wall)](https://aiatlasgraph.com/t/memorywall.md)
- [Rozdzielenie fazy prefill i decode (Disaggregated prefill and decode)](https://aiatlasgraph.com/t/disaggregation.md)
- [Silniki serwowania modeli językowych (LLM) (LLM inference engines and servers)](https://aiatlasgraph.com/t/inferenceengines.md)
- [Szacowanie pamięci GPU (wagi i KV cache) (Estimating GPU memory for deployment)](https://aiatlasgraph.com/t/gpumemory.md)
- [Uwaga lokalna z przesuwnym oknem (Sliding-window (local) attention)](https://aiatlasgraph.com/t/slidingwindow.md)

## Sources

- [Performance Engineering for AI Infra — learning guide](<https://github.com/wafer-ai/gpu-perf-engineering-resources>) `wafer-gpu` · GitHub repository · tiered curriculum (Tier 1–3) · MIT licence · by Wafer (wafer-ai): Company material with a hiring note, but the evidence is mostly primary sources. Table of contents sieved: only topics became nodes; tiers kept as link labels.

---

AI Atlas revision 122 (2026-10-30) · HTML: https://aiatlasgraph.com/t/kvcache · index: https://aiatlasgraph.com/llms.txt · everything: https://aiatlasgraph.com/llms-full.txt · updated 2026-10-30
