From ct
Provides deep operational intuition for LLM inference serving engines (vLLM, SGLang, TensorRT-LLM), covering KV-cache math, quantization, speculative decoding, MoE parallelism, and production tuning tradeoffs.
How this skill is triggered — by the user, by Claude, or both
Slash command
/ct:llm-inference-servingThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Concise operational pointers for deep LLM-serving troubleshooting and tuning.
Concise operational pointers for deep LLM-serving troubleshooting and tuning.
Assumes you already know what an LLM, KV cache, and a token are. This skill covers the operational layer — the parts models tend to gloss over: V1-engine internals, KV-cache math (MHA/GQA/MLA), continuous-batching/chunked-prefill economics, prefill/decode disaggregation, speculative decoding tradeoffs, quantization-format choice, and MoE+parallelism layout — current as of late 2025/early 2026.
Load when the question is about:
Do NOT load for: training / fine-tuning, embedding or reranker serving, agent / tool-calling protocol design, hosted-API integration, plain "what's an LLM" questions. For training fundamentals see dl-training; for fine-tuning see fine-tuning-llms.
V1 is the default engine; V0 is deprecated. V1 unifies prefill and decode under one scheduler with a {request_id: num_tokens} budget. EngineCore runs in its own process; scheduler and worker 0 are decoupled (symmetric TP); Persistent Batch caches input tensors and applies diffs.
Key knobs and how they interact:
--gpu-memory-utilization (default 0.9) — fraction of GPU memory for the executor. KV cache pool ≈ this fraction × VRAM − weights − activations − buffers.--max-num-seqs (default 256 in V1) — max concurrent sequences (decode parallelism cap).--max-num-batched-tokens (default ≈8192 in V1; was 2048 in V0) — per-iteration token budget shared by prefill + decode chunks. Lower → better ITL; higher → better TTFT/throughput. Sweep 8k–64k.--enable-chunked-prefill (default True in V1) — splits long prompts into chunks so a giant prefill doesn't stall queued decodes.--enable-prefix-caching (default True in V1) — hash-keyed shared KV blocks across requests. Massive win for RAG / system-prompt / multi-turn; near-zero loss otherwise.--kv-cache-dtype fp8 (E4M3 by default on Hopper+) — halves KV bytes vs FP16 with negligible quality loss for most models.--quantization {fp8,awq,gptq,awq_marlin,gptq_marlin,nvfp4,...} — weight scheme. Marlin/Machete kernels accelerate GPTQ/AWQ vs naïve dequant.--tensor-parallel-size, --pipeline-parallel-size, --data-parallel-size, --enable-expert-parallel.--speculative-config '{...}' (V1 unified) replaces the older --speculative-model.KV-token capacity ≈ max-num-seqs × max-model-len. Setting max-model-len=128k with max-num-seqs=256 blows the KV budget on a single H100 — drop one. gpu-memory-utilization ≥ 0.95 leaves no headroom for activations under bursty prefill; OOM appears under load, not at boot.
Per-token MHA bytes: 2 × n_layers × n_kv_heads × head_dim × bytes_per_elem.
Worked: Llama 3 70B (80 layers, 8 KV heads via GQA, head_dim 128, BF16) = 2 × 80 × 8 × 128 × 2 = 327,680 B ≈ 0.31 MB/token. At 100K tokens that's ~31 GB just for one sequence.
GQA collapses n_kv_heads from n_query_heads → n_groups (Llama 3: 64→8 = 8× KV reduction).
MLA (DeepSeek V2/V3/R1) replaces per-head K/V with a per-token shared low-rank latent (d_c ≈ 512) plus a small RoPE key (d_R ≈ 64). Bytes ≈ batch × seq × n_layers × (d_c + d_R) × bytes. DeepSeek-V3 at FP16 ≈ ~70 KB/token vs ~860 KB on a hypothetical MHA equivalent (~60× reduction, ~12× vs comparable GQA). Why DeepSeek can serve 128K cheaply and why vLLM treats MLA via a separate hybrid_kv_cache_manager.
KV quant: FP8 E4M3 cuts bytes 2×. NVFP4 KV (Blackwell) halves again with micro-block scaling (block 16 + FP8 scale + per-tensor FP32 scale).
max-num-batched-tokens with decodes. Eliminates head-of-line ITL spikes; smooths P99. Default-on in V1.Co-locating both wastes the resource the other phase needs. PD disaggregation runs prefill and decode on separate GPU pools and transfers KV across; goal is to satisfy TTFT and TPOT independently and optimize goodput (requests/s meeting SLO), not raw throughput. Specific systems (Splitwise, DistServe, Mooncake, etc.) churn fast — pick what your engine integrates with at the time.
KV transfer is hundreds of MB/request — the new bottleneck. RDMA preferred over NCCL for cross-pod transfers. When worth it: medium-to-long prompts, strict TTFT SLO, concurrency high enough that PD interference is real. Skip for short-prompt high-frequency chat — KV-transfer overhead dominates.
Verifier runs N draft tokens per step, accepts the longest matching prefix. Speedup ≈ accepted_length × target_step_cost / (target_step_cost + draft_cost).
vLLM CLI: --speculative-config '{"method":"ngram","num_speculative_tokens":4,"prompt_lookup_min":2,"prompt_lookup_max":5}' or '{"method":"eagle3","model":"…","num_speculative_tokens":2}'.
Footgun: under high concurrency the batch fills naturally — speculation eats compute that would have served other requests, net throughput drops. Use spec decode for low-concurrency latency-sensitive workloads, not at saturation.
Server-grade:
--quantization fp8 on Hopper (cc ≥ 8.9) and Ada. E4M3 (range ±448) for weights/activations; E5M2 (range ±57344) historically for grads. Per-tensor scale standard; per-channel for sensitive layers.Edge / CPU / Mac:
Per-channel scales > per-tensor on sensitivity-prone layers (e.g., down_proj); per-tensor cheaper, often fine elsewhere.
MoE serving: Mixtral-style 8-expert models are straightforward TP. Wide-MoE designs (DeepSeek-V3/R1 with hundreds of experts, MLA) are the hard case — the bottleneck is per-step expert load imbalance, addressed by hot-expert duplication / load-balancing schemes (EPLB-family). Capacity factor caps per-expert tokens-per-step; over-cap tokens drop or reroute. Specific layout/balancer choices change quarterly — re-check what your engine ships.
rope_scaling={"type":"dynamic","factor":2.0}, linear, yarn, llama3 for trained extensions. ChunkAttention: prefix-tree-aware FlashAttention.Engine docs:
Speculation, kernels:
Before recommending a non-trivial serving change (KV dtype, quantization scheme, parallelism layout, spec-decoding method, disaggregation):
Tuning without measurement is worse than defaults.
npx claudepluginhub pvillega/claude-templates --plugin ctCompares LLM serving frameworks (SGLang, vLLM, TensorRT-LLM, TokenSpeed) to find optimal deployment for a model under given workload, GPU budget, and latency SLA.
Provides recipes and Docker Compose configs for serving LLMs on RTX 3090 GPUs with vLLM, llama.cpp, and SGLang, exposing an OpenAI-compatible API.
Orchestrates online benchmarks for vLLM inference services using `vllm bench serve`. Supports single/multi-case batch execution with result aggregation and auto-optimization for throughput under latency SLOs (TTFT, TPOT, P99).