Logo de Kv Cache Latency Budgeter

Kv Cache Latency Budgeter

Comunidade
AnthonyAlcaraz
kv-cache-latency-budgeter

Budget a specialist model fleet against the two production bottlenecks: KV-cache-bound concurrency and end-to-end latency. Computes how many concurrent users a GPU can host (peak KV per active user, not model size, is the binding constraint), proves that quantizing weights does not move that ceiling while KV compression (MEMENTO) does, estimates GPU speedups for graph analytics (cuGraph / nx-cugraph), and checks a multi-node workflow against the book's latency budget and the sub-2s target. Use when scaling a multi-model agent to real-time latency. NOT for model selection (that is model-routing-selector), NOT for cost/quality scoring (that is cost-performance-scorer), NOT for defining GPU terms (that is gpu-glossary-anchor).

Visão geral

Publicado porAnthonyAlcaraz
Repositórioagentic-graph-rag-skills
Nome da habilidadekv-cache-latency-budgeter
Estrelas
29
Forks
9
Arquivos incluídos
2
LicençaMIT
Links
  • Instruções em Markdown

    Um arquivo SKILL.md que o modelo carrega sob demanda, consumindo tokens apenas quando uma solicitação é realmente relevante para a habilidade.

  • Funciona com qualquer LLM

    As habilidades de IA são escritas em Markdown simples, não em código específico de um provedor. Por isso, funcionam com GPT, Claude, Gemini, Grok ou um modelo local.

  • Arquivos incluídos: 2

    Scripts, templates e referências que o modelo pode ler enquanto trabalha. Os arquivos são somente para leitura e nunca são executados.

  • Código aberto

    Publicada por AnthonyAlcaraz no GitHub. Leia os arquivos da habilidade antes de instalá-la.

Instalação

Instale a habilidade de IA Kv Cache Latency Budgeter no TypingMind para usá-la com qualquer LLM ou adicione-a a outro agente que leia SKILL.md.

1

Instalar no TypingMind

O TypingMind instala uma habilidade diretamente da pasta dela no GitHub — lê o arquivo SKILL.md, reúne os arquivos de recursos em um pacote e armazena o resultado localmente.

  1. Abra o app e vá para Plugins → Habilidades.
  2. Escolha "Instalar do GitHub".
  3. Cole a URL abaixo, que aponta para a pasta da habilidade, e confirme.
    https://github.com/AnthonyAlcaraz/agentic-graph-rag-skills/tree/main/skills/optimization/kv-cache-latency-budgeter
  4. Ative a habilidade em cada chat em que quiser disponibilizá-la.
Plugins → Habilidades → Adicionar habilidade → Via URL do GitHub. Depois, cole a URL da pasta e pressione Continuar.
2

Instalar em outro agente

Qualquer agente que leia o formato Agent Skills pode usar esta habilidade — copie a pasta para o diretório de habilidades desse agente.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/AnthonyAlcaraz/agentic-graph-rag-skills.git /tmp/agentic-graph-rag-skills
mkdir -p .claude/skills
cp -r /tmp/agentic-graph-rag-skills/skills/optimization/kv-cache-latency-budgeter .claude/skills/kv-cache-latency-budgeter
Reinicie Claude Code após copiar para que a nova habilidade seja reconhecida.

Use no TypingMind

Ative Kv Cache Latency Budgeter em qualquer chat do TypingMind e o modelo cuida do resto. O nome e a descrição da habilidade ficam no prompt do sistema e, assim que uma solicitação relevante aparece, o modelo carrega as instruções completas automaticamente — sem precisar de acionamento manual e sem consumir tokens até que ela seja realmente usada.

O modelo carrega Kv Cache Latency Budgeter automaticamente assim que uma solicitação é relevante para essa habilidade.

Funciona com qualquer modelo de IA

Habilidades de IA são instruções em Markdown simples, não código específico de um provedor. Por isso, Kv Cache Latency Budgeter não fica vinculada ao modelo para o qual foi criada. Instale-a uma vez no TypingMind e use-a com GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama ou um modelo local executado por conta própria — tudo com suas próprias chaves de API.

  • Carregada apenas quando necessário

    O prompt do sistema contém apenas o nome e a descrição. As instruções são buscadas na primeira solicitação relevante, então uma habilidade sem uso não gera custo.

  • Troque de modelo durante a conversa

    Como a habilidade é composta de instruções, não de código, trocar de modelo não afeta seu funcionamento — o próximo modelo lê o mesmo arquivo SKILL.md.

Instruções da habilidade

Este é o conteúdo de SKILL.md que o modelo carrega. Leia antes de instalar — uma habilidade é um conjunto de instruções que seu modelo seguirá.

KV-Cache Latency Budgeter

Overview

The architecture distributes work across two channels that both bottleneck at production scale: graph traversals that navigate the knowledge graph, and model-inference calls that power the workflow nodes.

Graph analytics (PageRank, community detection, centrality) are bound by memory bandwidth, not compute — irregular random access CPUs handle poorly and GPUs handle well. cuGraph / nx-cugraph report order-of-magnitude speedups: PageRank 137x on A100, Louvain 125x over NetworkX, multi-GPU PageRank 80x over a 100-node Spark cluster, and betweenness centrality on the LiveJournal graph (4.8M nodes, 69M edges) from 7 minutes to 5 seconds — a 485x speedup. For the DevOps agent, blast-radius analysis drops from 3-5 seconds on CPU to under 100 ms on one GPU.

Inference latency is bound by the KV cache. Multi-LoRA serving lowers cost per weight but not the binding constraint: peak KV per active user, not model size, sets how many concurrent analyses one H100 (80 GB) can host. Quantizing the weights does not move this ceiling — you have to bound the cache itself. The chapter's first production-ready recipe is Microsoft MEMENTO: a two-stage supervised fine-tune on 228,000 traces teaches the model to segment its chain of thought into blocks, emit a compressed summary token per block, and mask the original block from future attention, producing a sawtooth KV pattern.

The chapter's source redacts the exact MEMENTO reduction factor, per-block compression factor, and concurrent-incident multiplier. This skill treats those as caller-measured inputs and never fabricates them — consistent with the chapter's own [Tip]: measure peak KV per active user first.

When to Use

  • Scaling a multi-model agent and deciding how many concurrent incidents one GPU can host.
  • Choosing between weight quantization and KV compression to raise concurrency.
  • Estimating whether GPU-accelerated graph analytics fit the latency budget.
  • Setting an end-to-end latency target for a multi-step workflow.

Phrases that should invoke this skill: "how many concurrent users per GPU", "KV cache bound", "peak KV per user", "MEMENTO", "latency budget", "cuGraph speedup", "is this pipeline fast enough".

When NOT to Use

  • Model selection / routing — that is model-routing-selector (Ch8).
  • Cost per successful completion — that is cost-performance-scorer (Ch8).
  • Defining GPU terms (VRAM, tensor core, quantization) — that is the gpu-glossary-anchor skill.
  • When peak KV is unmeasured. The concurrency math needs a measured peak KV per active user. Measure it on a representative reasoning-heavy workload first; do not guess.

Process

StepInputActionOutputVerification
1GPU GB, weights GB, peak KV GBlib.kv_bound_concurrency(...)Concurrent usersBound by KV, not weights
2Same + factorslib.weight_quant_vs_kv_compression(...)Concurrency gain comparisonKV compression out-gains weight quant when KV dominates
3(design)lib.memento_note()MEMENTO recipe + measure-first tipReduction factor marked caller-measured, not fabricated
4CPU seconds + algolib.estimate_gpu_time(s, algo)GPU wall-clock estimateUses the published speedup
5(design)lib.LATENCY_BUDGETComponent budget + targetsRanges match the book (5-50 / 50-200 / 500-2000 ms)
6SLM calls, graph ops, parallelismlib.budget_pipeline(...)End-to-end estimate vs 2s targetwithin_2s_target true for the DevOps pipeline

Rationalizations

Agent rationalizationDocumented rebuttal
"Use a smaller model to fit more concurrent users."Model size is not the ceiling — peak KV per active user is. An 80 GB GPU hosts a small number of concurrent reasoning-heavy users regardless of how small the model is (Ch8).
"Quantize the weights to raise concurrency."Quantizing weights frees a little memory but does not move the KV ceiling. Bounding the cache (MEMENTO) multiplies concurrency; the comparison in this skill shows the KV gain dominating the weight-quant gain.
"KV compression always helps, turn it on."Not if peak KV is already small (short prompts, no reasoning traces) — then multi-LoRA dominates and KV compression is secondary. The chapter's tip is to MEASURE peak KV first and optimize the binding constraint.
"GPU acceleration is fast, load the graph per query."Cold-start data transfer to GPU memory can take seconds for large graphs, negating the speedup. Keep a warm GPU-resident copy of the hot subgraphs (Ch8 pitfall).
"Optimize per-call latency."The user perceives the whole workflow. The meaningful target is end-to-end task completion time, not per-call latency (Ch8 Latency Budgets).

Red Flags

  • Concurrency computed from model size instead of peak KV. The binding constraint is misidentified; the estimate will be wildly optimistic.
  • A fabricated MEMENTO reduction factor. The source redacts it; any hardcoded multiple is invented. Mark it measured.
  • Pipeline estimate ignores parallelism. Independent DAG nodes run concurrently; a purely sequential estimate overstates latency.
  • cuGraph speedup applied to a Cypher traversal. No major graph DB runs Cypher/Gremlin traversal on GPU; only analytics (PageRank, centrality) via cuGraph. The traversal query engine stays CPU-bound.
  • CLI --help exits non-zero. SKILL.md / CLI mismatch.

Non-Negotiable Verification

Before trusting a capacity or latency estimate from this skill:

  1. Run the benchmark battery.

    python cli.py benchmark

    Confirms KV bounds concurrency (not model size), KV compression out-gains weight quantization, the MEMENTO factor is caller-measured, the cuGraph speedups match the book, and the 5-call pipeline lands within 2 seconds.

  2. Prove the KV-vs-weights claim on your numbers.

    python cli.py kv-compress --gpu 80 --weights 16 --peak-kv 8 --kv-factor 2

    Confirm verdict is kv_compression and the KV gain exceeds the weight-quant gain.

  3. Measure peak KV before optimizing.

    python cli.py memento

    Read the tip; run your representative reasoning-heavy workload and measure peak KV per active user before choosing multi-LoRA vs KV compression.

  4. Domain test in the notebook. Run notebooks/ch8-optimization.ipynb; confirm the hardware-acceleration section estimates the blast-radius GPU speedup and checks the completed pipeline against the sub-2s budget using moto-mocked CloudWatch latency signals.

Security Posture

  • Advisory calculator, no execution. lib.py makes no network calls and runs no GPU code; it returns estimates the caller acts on.
  • Estimates are inputs, not guarantees. The speedups are published figures for specific graphs/hardware; validate against your own workload before committing an SLO. A latency SLO backed by an un-measured estimate is an optimistic guess, not a design.
  • Do not fabricate the redacted factors. Treat peak_kv_reduction_factor and per_block_compression_factor as measured on your workload; a hardcoded value is a fabricated capacity claim that fails silently at production load.

Composition

  • Follows model-routing-selector (Ch8): routing lowers cost per weight; this budgeter checks the resulting fleet against the concurrency + latency ceiling. Together they cover cost AND latency.
  • Pairs with cost-performance-scorer: cost/quality on one axis, latency/ concurrency on the other; both gate a production routing change.
  • Composes with the gpu-glossary-anchor skill for term definitions and with the vLLM multi-LoRA serving pattern (Example 8-12).

Source Attribution

Distilled from Agentic GraphRAG (O'Reilly, by Anthony Alcaraz and Sam Julien), Chapter 8 — Optimization, "Hardware Acceleration". Key references:

  • cuGraph / nx-cugraph speedups (PageRank 137x, Louvain 125x, multi-GPU 80x, betweenness 485x on LiveJournal 4.8M/69M; blast radius 3-5s -> <100ms)
  • vLLM continuous batching + multi-LoRA (Example 8-12; 50-80ms TTFT, 100 users)
  • Cerebras Inference (1,800 tok/s, 20x; 22s -> 1.5s; 75x Artificial-Analysis- verified) and SambaNova SN50 RDU (millisecond hot-swap)
  • MEMENTO (Microsoft) — two-stage SFT on 228,000 traces; block-summary KV bound
  • Latency budget framework (5-50 / 50-200 / 500-2000 ms; sub-100ms / sub-30ms)

Arquivos incluídos

O modelo lê esses arquivos sob demanda enquanto a habilidade está carregada. Eles são disponibilizados para leitura e nunca são executados.

Perguntas frequentes

O que a habilidade de IA Kv Cache Latency Budgeter faz?

Budget a specialist model fleet against the two production bottlenecks: KV-cache-bound concurrency and end-to-end latency. Computes how many concurrent users a GPU can host (peak KV per active user, not model size, is the binding constraint), proves that quantizing weights does not move that ceiling while KV compression (MEMENTO) does, estimates GPU speedups for graph analytics (cuGraph / nx-cugraph), and checks a multi-node workflow against the book's latency budget and the sub-2s target. Use when scaling a multi-model agent to real-time latency. NOT for model selection (that is model-rout...

Por que usar Kv Cache Latency Budgeter no TypingMind?

Porque basta instalar uma vez para usar com qualquer modelo. A habilidade Kv Cache Latency Budgeter é escrita em Markdown simples, e não em código específico de um provedor, então a mesma habilidade funciona com GPT-5, Claude, Gemini, Grok ou um modelo local — e é possível trocar de modelo no meio do chat sem que ela deixe de funcionar. No TypingMind, você usa suas próprias chaves de API e paga diretamente aos provedores, em vez de pagar uma assinatura por licença de usuário. Suas habilidades e chats permanecem no seu próprio armazenamento.

Como instalar Kv Cache Latency Budgeter no TypingMind?

Abra Plugins → Habilidades → Instalar do GitHub no TypingMind e cole https://github.com/AnthonyAlcaraz/agentic-graph-rag-skills/tree/main/skills/optimization/kv-cache-latency-budgeter. O TypingMind lê o arquivo SKILL.md, reúne os arquivos da habilidade e a instala para que possa ser ativada em cada chat.

Quais modelos de IA podem usar Kv Cache Latency Budgeter?

Qualquer modelo conectado no TypingMind. As habilidades de IA são instruções em Markdown simples, e não código específico de um provedor. Assim, GPT, Claude, Gemini, Grok e modelos locais podem carregar esta habilidade quando uma solicitação corresponder a ela.

Quantos modelos de IA posso usar com Kv Cache Latency Budgeter?

Quantos quiser. Desde que o modelo ofereça suporte a habilidades, é possível usar Kv Cache Latency Budgeter com ele — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama e outros — tudo no TypingMind com suas próprias chaves de API.

A habilidade de IA Kv Cache Latency Budgeter é gratuita?

Sim. A habilidade é publicada no GitHub por AnthonyAlcaraz sob a licença MIT. O pagamento é feito apenas ao seu provedor de IA pelos tokens usados.

O que são habilidades de IA?

Uma habilidade de IA é um conjunto reutilizável de instruções que ensina um modelo de IA a realizar uma tarefa específica. Ela segue o formato aberto Agent Skills: um arquivo SKILL.md com nome e descrição, além de scripts, templates ou arquivos de referência de que o modelo possa precisar. O modelo lê as instruções apenas quando sua solicitação corresponde à habilidade, então uma habilidade instalada não gera custos até ser usada.

Qual é a diferença entre habilidades de IA e plugins ou servidores MCP?

Um plugin ou servidor MCP oferece ao modelo novas ferramentas que ele pode acionar — código que é executado em algum lugar e retorna um resultado. Já uma habilidade de IA dá ao modelo o conhecimento e as orientações de que ele precisa: como abordar uma tarefa, quais etapas seguir e como deve ser um bom resultado. As habilidades são escritas em Markdown simples, por isso não precisam de servidor, chave de API nem ambiente de execução, e funcionam com qualquer modelo.

Ver lista completa

Crie seu próprio espaço de trabalho com IA agora

Inscreva-se na nossa newsletter para receber avisos sobre novos recursos e futuros sorteios 👇