Command Palette

Search for a command to run...

Назад к скиллам
скилл № 69566

ml-inference-optimization

Use when the user asks to optimize LLM inference: time to first token (TTFT), tokens per second, throughput, vLLM vs SGLang vs TGI, speculative decoding…

БесплатноБез исполняемых скриптов
j4flmaoот j4flmao★ 47 звёзд на GitHub

Установить ml-inference-optimization в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

LLM Inference Optimization

Purpose

Serve LLMs at the required latency for the lowest cost. Decoding one token at a time is usually memory-bandwidth bound (every step reads all weights plus the KV cache), while prompt prefill is compute bound. Optimizations therefore aim to batch more requests per weight read, shrink bytes moved (quantization, KV compression), and generate more tokens per step (speculative decoding).

Agent Protocol

Trigger

"llm inference", "optimize inference", "ttft", "time to first token", "tokens per second", "throughput", "inter-token latency", "vllm", "sglang", "tgi", "tensorrt-llm", "speculative decoding", "serving cost".

Input Context

  • Model, GPU type/count, current engine and config.
  • Traffic: prompt and output length distributions, concurrency, latency SLOs (TTFT, inter-token latency).
  • Current metrics and cost per million tokens.

Output Artifact

Bottleneck diagnosis + prioritized changes + benchmark plan. No file unless requested.

Response Format

Workload: prompt {p50/p95 tokens}, output {p50/p95}, concurrency {n}
Bound: {prefill compute|decode bandwidth|KV capacity|scheduler/host}
Changes (ordered): 1) {...} 2) {...}
Benchmark: {tool + metric targets}

Completion Criteria

  • Baseline measured with realistic prompt/output lengths and concurrency.
  • Each change measured separately for TTFT, inter-token latency, throughput, quality.
  • Quality evaluated after quantization or speculative decoding config changes.

Metrics

Metric Meaning Dominated by
TTFT Time to first token Queueing + prefill (prompt length)
ITL / TPOT Time between output tokens Decode step time (weights + KV bytes / bandwidth)
Throughput Output tokens/s across all requests Batch size the KV memory allows
Goodput Requests/s meeting the SLO Trade-off between batch size and latency

Memory Budget

  • Weights: params x bytes per param (70B BF16 ≈ 140 GB → at least 2 x 80 GB GPUs; FP8 ≈ 70 GB; 4-bit ≈ 35-40 GB).
  • KV cache per token: 2 x layers x kv_heads x head_dim x bytes. Grouped-query attention models have far fewer KV heads than query heads.
  • Whatever remains after weights and activations is KV capacity, which caps concurrency.

Optimization Levers (roughly in order)

Lever Helps Notes
Dedicated engine (vLLM, SGLang, TensorRT-LLM, TGI) Large throughput gains over naive generate() loops Continuous batching, paged KV cache, fused kernels
Continuous batching Throughput New requests join at every step
Paged KV cache + prefix caching Concurrency, TTFT for shared prompts Keep shared system prompt/document first
FP8 weights/activations (Hopper+) Throughput, memory Near-lossless for most models; validate
4-bit weight-only (AWQ/GPTQ) Memory, small-batch latency Can be slower at large batch
FP8 KV cache Concurrency, long context Validate long-context quality
Tensor parallelism Latency, fit large models Needs fast intra-node links (NVLink)
Speculative decoding (draft model, n-gram, EAGLE, MTP heads) Inter-token latency at low/medium load Gains shrink when GPU is already saturated by batching
Chunked prefill Tail ITL during long prompts Interleaves prefill chunks with decode
Prefill/decode disaggregation SLOs at scale Separate GPU pools; KV transfer between them

Example: vLLM Offline Batch + Server

from vllm import LLM, SamplingParams

llm = LLM(
    model="Qwen/Qwen2.5-7B-Instruct",
    gpu_memory_utilization=0.90,
    max_model_len=8192,
    enable_prefix_caching=True,
)
params = SamplingParams(temperature=0.2, max_tokens=256)
outputs = llm.generate(["Summarize: ...document text...", "Translate to French: hello"], params)
for o in outputs:
    print(o.outputs[0].text)
vllm serve Qwen/Qwen2.5-7B-Instruct --max-model-len 8192 --enable-prefix-caching

Pass prompts as a list so the engine batches them; looping one prompt at a time throws away batching.

Benchmarking

  • Use the engine's benchmark tooling (e.g. vllm bench serve) or a load generator that replays real length distributions at fixed request rates.
  • Sweep request rate; plot TTFT/ITL p50/p99 vs throughput to find the knee.
  • Warm up first; report GPU type, engine version, precision, and max concurrency.

Decision Rules

TTFT high, ITL fine → prefill bound or queueing: prefix caching, chunked prefill, more replicas
ITL high at low load → bandwidth bound: quantize weights, speculative decoding, TP
Throughput capped with KV usage ~100% → FP8 KV, shorter max_model_len, quantized weights, more GPUs
GPU util low with high load → host/scheduler bound: check tokenizer, detokenization, Python overhead, engine version

Anti-Patterns

  • Serving production traffic with transformers pipeline()/generate() per request.
  • Benchmarking with one prompt length and concurrency 1, then sizing
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл ml-inference-optimization?

Use when the user asks to optimize LLM inference: time to first token (TTFT), tokens per second, throughput, vLLM vs SGLang vs TGI, speculative decoding, continuous batching or serving an LLM cheaper. Produces latency/throughput diagnosis, memory budget and engine and batching settings. Not for classic model serving (use ml-model-serving) or KV math alone (use llm-kv-cache-paged-attention).

Как установить скилл ml-inference-optimization?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл ml-inference-optimization запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить ml-inference-optimization с