llm-kv-cache-paged-attention

llm-kv-cache-paged-attention is a skill for Claude Code, Codex from j4flmao/agent-skills. It costs 150 tokens per session (2,044 once invoked), scanned A, original, MIT.

A technical guide to KV caching and PagedAttention in Transformer text generation. A KV cache stores attention data for earlier tokens so the model does not recompute it at every next-token step; PagedAttention organizes that data in GPU memory blocks.

In plain words
What is it for?
Use it when studying or designing memory management for autoregressive model serving, especially with vLLM. It covers logical and physical memory blocks, block tables, fragmentation, and concurrent batching.
Why use it?
It explains how fixed memory allocation can waste GPU memory and limit how many generation requests run together, and how block-based storage addresses that problem.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when studying or designing memory management for autoregressive model serving, especially with vLLM. It covers logical and physical memory blocks, block tables, fragmentation, and concurrent batching.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/j4flmao/agent-skills/kv-cache
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add j4flmao/agent-skills --skill kv-cache
Clone the repo
git clone --depth 1 https://github.com/j4flmao/agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for llm-kv-cache-paged-attention

README.md
[![agentmods](https://agentmods.dev/badge/skills/j4flmao/agent-skills/kv-cache/github.svg)](https://agentmods.dev/skills/j4flmao/agent-skills/kv-cache)
Your own site
<a href="https://agentmods.dev/skills/j4flmao/agent-skills/kv-cache"><img src="https://agentmods.dev/badge/skills/j4flmao/agent-skills/kv-cache/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for llm-kv-cache-paged-attention

Your own site · 80×15
<a href="https://agentmods.dev/skills/j4flmao/agent-skills/kv-cache"><img src="https://agentmods.dev/badge/skills/j4flmao/agent-skills/kv-cache.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 150 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,044 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00150 $0.02044
Opus 5.5 $0.00060 $0.00818
Sonnet 5.5 $0.00030 $0.00409
Haiku 4.5 $0.00015 $0.00204

Measured yesterday against content hash d57e36dd142b, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

llm-kv-cache-paged-attention scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/ai/llm-engineering/kv-cache/SKILL.md · 139 lines

How it starts

The opening of the file, as written. The whole thing — 139 lines — stays where its author put it; the contents beside it link to each section on GitHub.

KV Cache & PagedAttention

Purpose

During decoding each new token attends to the keys and values of all previous tokens. Caching K and V avoids recomputing them, but the cache grows linearly with sequence length and batch size and usually becomes the binding constraint on concurrency. This skill gives the sizing math and the serving-engine levers (paging, prefix sharing, KV quantization, scheduling) to maximize throughput without OOM.

Agent Protocol

Trigger

"KV cache", "PagedAttention", "vLLM OOM", "gpu_memory_utilization", "max_num_seqs", "prefix caching", "long context memory", "KV cache quantization".

Input Context

  • Model architecture: layers, KV heads, head dim (from config.json), dtype.
  • GPU count/VRAM, target context length, expected concurrent requests.
  • Prompt shape: shared system prompts or few-shot prefixes?

Output Artifact

KV budget calculation and serving configuration (vLLM flags or equivalent) with expected max concurrency.

Response Format

Model: {name} L={layers} kv_heads={h} head_dim={d} dtype={bytes}
KV per token: 2*L*h*d*bytes = {KiB}
KV budget: {GiB} -> tokens in cache ≈ {n}
Max concurrency at {ctx} tokens ≈ {n}
Config: --max-model-len {..} --gpu-memory-utilization {..} --kv-cache-dtype {..} --max-num-seqs {..}

Completion Criteria

  • KV bytes/token computed from the real config (KV heads, not attention heads).
  • Budget accounts for weights and activation/workspace memory.
  • Concurrency estimate validated with a load test.
  • Prefix caching considered for shared prompts.

Sizing Math

KV bytes per token = 2 (K and V) × num_layers × num_kv_heads × head_dim × bytes_per_element

Model (config) Per-token KV (bf16) 8k-token sequence
Llama-3-8B: 32 layers, 8 KV heads, head_dim 128 2·32·8·128·2 = 128 KiB 1 GiB
Same model with fp8 KV cache 64 KiB 0.5 GiB
Hypothetical MHA (32 KV heads) 512 KiB 4 GiB

Grouped-query attention (GQA) shares each KV head across several query heads, cutting the cache by the group factor; multi-query attention (MQA) uses one KV head; multi-head latent attention (MLA, DeepSeek-V2/V3) stores a compressed latent instead of full K/V.

Read the full file on GitHub · 139 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday Changed · +83 lines · +150 tokens per session d57e36dd142b
  2. 1mo ago First seen · 56 lines · 0 tokens per session scan A efd4223325fa

Subscribe to this mod's changes

llm-kv-cache-paged-attention is a skill published in the GitHub repository j4flmao/agent-skills (35 stars, last pushed yesterday), licensed MIT. It adds 150 tokens to every session and 2,044 once invoked, about $0.0006 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.