optimize-prefill-vs-decode-kernels

optimize-prefill-vs-decode-kernels is a skill for Claude Code, Codex from tensormux/kernel-skills. It costs 0 tokens per session (4,043 once invoked), scanned A, original, MIT.

A guide to choosing and tuning GPU kernels for the two main stages of large language model inference: prefill, which processes the input prompt, and decode, which generates new tokens.

In plain words
What is it for?
Tuning matrix multiplication, attention, key-value cache access, normalization, batching, chunked prefill, or speculative decoding in an LLM inference engine.
Why use it?
These stages use hardware differently, so one shared kernel strategy can make prompt processing fast while making token generation slow, or the reverse.

Skill for Claude CodeCodex

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

Good fit Tuning matrix multiplication, attention, key-value cache access, normalization, batching, chunked prefill, or speculative decoding in an LLM inference engine.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/tensormux/kernel-skills/optimize-prefill-vs-decode-kernels
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 tensormux/kernel-skills --skill optimize-prefill-vs-decode-kernels
Clone the repo
git clone --depth 1 https://github.com/tensormux/kernel-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 optimize-prefill-vs-decode-kernels

README.md
[![agentmods](https://agentmods.dev/badge/skills/tensormux/kernel-skills/optimize-prefill-vs-decode-kernels/github.svg)](https://agentmods.dev/skills/tensormux/kernel-skills/optimize-prefill-vs-decode-kernels)
Your own site
<a href="https://agentmods.dev/skills/tensormux/kernel-skills/optimize-prefill-vs-decode-kernels"><img src="https://agentmods.dev/badge/skills/tensormux/kernel-skills/optimize-prefill-vs-decode-kernels/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 optimize-prefill-vs-decode-kernels

Your own site · 80×15
<a href="https://agentmods.dev/skills/tensormux/kernel-skills/optimize-prefill-vs-decode-kernels"><img src="https://agentmods.dev/badge/skills/tensormux/kernel-skills/optimize-prefill-vs-decode-kernels.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 4,043 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.
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.00000 $0.04043
Opus 5.5 $0.00000 $0.01617
Sonnet 5.5 $0.00000 $0.00809
Haiku 4.5 $0.00000 $0.00404

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

Security

Grade A, and why

optimize-prefill-vs-decode-kernels 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 3mo ago.

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/inference/optimize-prefill-vs-decode-kernels/SKILL.md · 131 lines

How it starts

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

Skill: Optimize Prefill vs Decode Kernels

Purpose

Guide the agent through choosing and tuning kernels for the prefill phase versus the decode phase of LLM inference. The two phases have fundamentally different arithmetic intensity, occupy different sides of the roofline, and respond to different optimizations. Continuous batching and speculative decoding shift the balance and must be reasoned about explicitly.

Use this when

  • Designing or selecting kernels for an LLM inference engine (matmul, attention, KV cache access, normalization fusion).
  • An existing engine reuses a single kernel across both phases and decode latency or throughput is poor.
  • Tuning tile shapes, split-K, or persistent kernels separately for prefill and decode.
  • Adding speculative decoding, lookahead decoding, EAGLE, or Medusa, where decode shifts toward a small-batch GEMM regime.
  • Implementing chunked prefill or hybrid prefill/decode batches and choosing per-batch kernels.
  • Diagnosing why TTFT is good but inter-token latency is bad, or vice versa.

Do not use this when

  • An off-the-shelf kernel (cuBLASLt heuristics, vendor attention) already saturates the relevant resource. Trust the library until profiling shows a gap.
  • The bottleneck is outside the kernel layer (Python overhead, scheduler, RPC, host-device copies). Fix the host path first.
  • Training, not inference. Training runs in a different regime — large M dominates throughout, so this skill's decode reasoning does not apply.
  • A non-batched, latency-insensitive offline workload where one configuration is good enough.

Inputs the agent should gather first

  • Phase: prefill, decode, or mixed (continuous batching). For mixed, the per-request M distribution.
  • Effective M per request: prefill M = prompt length (typically 256–32k+); decode M = 1, or M = k for speculative decoding (typical k = 2–8, lookahead trees up to 32–64).
  • Batch size B: number of concurrent requests in this kernel call. With continuous batching, the kernel sees the aggregated M across all requests.
  • Model dimensions and dominant K: hidden size N, head dim d_h, num heads h, intermediate FFN size; K = hidden for QKV/output proj, K = intermediate for FFN down proj, K = head_dim for attention.
  • dtype of weights, activations, KV cache, and matmul accumulator (fp16, bf16, fp8, int8, int4 weight-only).
  • KV cache layout: paged (PagedAttention), contiguous, MQA, GQA group size. Cache bytes per token = 2 * num_layers * num_kv_heads * head_dim * dtype_bytes.
  • Target hardware: HBM bandwidth (H100 SXM ≈ 3.35 TB/s, H200 ≈ 4.8 TB/s, MI300X ≈ 5.3 TB/s, A100 80GB ≈ 2.0 TB/s), tensor core gen, FP8/INT8 support.
  • Whether speculative decoding is active, draft model, verified-tokens-per-step distribution (acceptance rate × tree size).
  • SLO targets: TTFT, p50/p99 inter-token latency, throughput. The right kernel for throughput is rarely the right one for tail latency.

Read the full file on GitHub · 131 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 3mo ago First seen · 131 lines · 0 tokens per session scan A 3edbe29f6bd7

Subscribe to this mod's changes

optimize-prefill-vs-decode-kernels is a skill published in the GitHub repository tensormux/kernel-skills (93 stars, last pushed 5mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 4,043 tokens. 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.

Related

optimize-prefill-vs-decode-kernels compared with skills from other repositories

optimize-prefill-vs-decode-kernels next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
optimize-prefill-vs-decode-kernelstensormux/kernel-skillsSkill935mo agoMITA0Claude Code, Codex
prompt-engineeringMagicKidd/Rokid-agentic-workflowSkill35mo agononeA0Claude Code, Codex
sglang-diffusion-cache-ditsgl-project/sglangSkill39ktodayApache-2.0A161Claude Code
recon-ai-enrichmentsamugit83/redamonSkill3.5ktodayMITA188Claude Code, Codex
pgvector-semantic-searchtimescale/pg-aiguideSkill1.9kyesterdayApache-2.0A190Cursor
postgres-hybrid-text-searchtimescale/pg-aiguideSkill1.9kyesterdayApache-2.0A162Cursor
huawei-cloud-maas-setupXiaoLuoLYG/GODSkill1.3k5d agoApache-2.0A133Claude Code