# roofline

Adopt this skill: https://proskills.md/skills/other/lenialno-roofline-skills-roofline

Page: https://proskills.md/skills/other/lenialno-roofline-skills-roofline
This document is the public skill bundle for that page. It contains SKILL.md and every helper file the catalog carries. No login is required.

## File: skills/roofline/SKILL.md
size: 4130
sha: a3d5a9f91a3aeca3dfbc726263be979c2f41ed4b
upstream: https://github.com/lenialno/roofline/blob/main/skills/roofline/SKILL.md

````text
---
name: roofline
description: "Router for the Inference Engineer role on on-prem LLM serving (vLLM/SGLang, OpenAI-compatible endpoint, air-gap). Use when the user asks what to do first with a local LLM server, how to approach a serving task, which skill, task or agent to use, what is inside or outside the inference engineer role, or talks about LLM serving, GPU inference, inference engineering in general terms."
license: MIT
---

# Inference Engineer: where to start

The role as roadmap.sh defines it: make the model answer fast, cheaply and predictably in production. The stack in this package: on-prem GPU, vLLM or SGLang, an OpenAI-compatible endpoint, Claude Code and Qwen Code clients through a proxy. Code and weights never leave the perimeter.

## First five minutes

```bash
task -t ${CLAUDE_SKILL_DIR}/../roofline-toolbox/Taskfile.yml status     # gpu + health + models
task -t ${CLAUDE_SKILL_DIR}/../roofline-toolbox/Taskfile.yml metrics    # queue, KV, prefix cache, p95
```

No server yet: skill `roofline-runtime`. The server exists but does not respond or has degraded: `roofline-incident`. Everything works and you need it faster: `roofline-perf`.

## Where to go for each request

| Request | Handled by |
|---|---|
| bring up, restart, choose vLLM or SGLang, write a profile | skill `roofline-runtime`, `task serve/stop/logs/flags` |
| tool calls arrive as plain text, parser, chat template, connect Claude Code or Qwen Code | skill `roofline-toolcall`, `task smoke-toolcall` |
| slow, OOM under load, quantization, KV, batching, bench | skill `roofline-perf`, `task bench/vram/metrics` |
| server is down, queue, p95 above SLO, broke after an upgrade | skill `roofline-incident`, then the `incident-investigator` agent for a long log review |
| how many GPUs, how many users, rollout and rollback plan | skill `roofline-capacity`, `task vram` |
| what the GPU can do right now, which models are up | `task gpu`, `task models` |

The `incident-investigator` agent is only for investigations that need long log reads or metric comparisons over hours: it runs in its own context and returns a digest.

## Role boundaries

In scope: serving, runtime flags, KV cache and batching, quantization with quality checks, SLOs and metrics, GPU memory and TP, observability, capacity, rollout. Full map across the 136 roadmap nodes: [references/competency-map.md](references/competency-map.md).

Out of scope: training and research, fine-tuning and distillation as the main job (we know when to order them), cloud serving (GKE, SageMaker, HF Endpoints), custom CUDA kernels, image/video/speech pipelines, NVIDIA Dynamo and prefill/decode disaggregation (needed for a multi-node cluster, not for one or two servers).

## Working rules

- Measure first, then change: `task metrics` and `task bench` before and after, one variable at a time
- Take flags from the installed version: `task flags Q=<word>`, not from memory
- After any configuration change: `task health`, `task smoke-toolcall`, `task bench`
- After an engine upgrade: `task doctor`
- Launch profiles come only from `profiles/`; the Taskfile does not run arbitrary server commands
- No SLO or load data: ask, do not guess

Theory the other skills rely on (KV cache, sampling, chat format, perplexity), with page numbers from Andriy Burkov, "The Hundred-Page Language Models Book" (page numbers refer to the Russian edition, BHV, 2026): [references/theory-from-burkov.md](references/theory-from-burkov.md).

## Sources

- [roadmap.sh: Inference Engineering](https://roadmap.sh/inference-engineering): the role map; every node translated in `docs/roadmap-ru/`
- [Claude Code: skills](https://code.claude.com/docs/en/skills), [plugins](https://code.claude.com/docs/en/plugins): package format
- [Agent Skills specification](https://agentskills.io/specification): SKILL.md format
- Andriy Burkov, "The Hundred-Page Language Models Book" (Russian edition: BHV-Petersburg, 2026, [buy on Ozon](https://www.ozon.ru/product/yazykovye-modeli-bez-lishnih-slov-burkov-andrey-4678629427/)): theory in [references/theory-from-burkov.md](references/theory-from-burkov.md)
````

## File: skills/roofline/references/competency-map.md
size: 3774
sha: 47829ec5c0f7751eca09995647a80a3e9dcba830
upstream: https://github.com/lenialno/roofline/blob/main/skills/roofline/references/competency-map.md

```text
# Competency map by roadmap.sh/inference-engineering

Source: 136 roadmap nodes (snapshot of 2026-10-07), translated in `docs/roadmap-ru/`. The "Here" column shows what the engineer does in this product (on-prem, vLLM/SGLang, Taskfile).

## In scope

| Roadmap group | Nodes | Here | Skill / task |
|---|---|---|---|
| Latency Metrics | TTFT, ITL, TPS, latency vs throughput, p50/p95/p99, end-to-end | set SLOs, measure p95 TTFT and TPOT, not the mean | perf, `task bench`, `task metrics` |
| Inference Phases | prefill (compute-bound), decode (memory-bound), online/offline/async | diagnose the bottleneck by phase | perf, incident |
| Application Context | AI-native apps, reasoning models | agents (Claude Code) produce many calls and long prompts; reasoning makes answers longer | capacity, toolcall |
| Model Strategy | model selection, evaluation | pick the smallest model that passes product evals and the tool-calling smoke test | capacity, perf |
| LLMs | transformer blocks, attention, KV cache, MoE | compute KV per token, understand MoE in a batch (all experts active) | perf, `task vram` |
| Bottleneck Analysis | ops:byte, arithmetic intensity, roofline | decode is memory-bound: quantization and batching help, FLOPS do not | perf |
| Attention Optimization | FlashAttention, PagedAttention, variants | built into the engines; check the backend, do not write your own | runtime |
| GPU Architecture | compute, memory, NVLink, MIG, sizing | sizing: 1 GB per 1B parameters in FP8 plus 50% for KV | capacity, `task gpu` |
| GPU Models | Hopper, Blackwell | FP8 on Hopper+, FP4 on Blackwell | perf |
| Model Formats | safetensors | safetensors only in air-gap, checksums | runtime, capacity |
| Inference Engines | vLLM, SGLang, TensorRT-LLM | vLLM and SGLang; TRT-LLM is not used | runtime |
| Benchmarking & Profiling | genai-bench, GenAI-Perf, Locust | our own fixed bench `task bench`, one variable at a time | perf |
| Quantization | PTQ, QAT, ModelOpt, quality | FP8 first, AWQ/GPTQ with a tool-calling check | perf |
| Speculative Decoding | draft-target, EAGLE, n-gram | n-gram for code, EAGLE at low concurrency | perf |
| Caching | prefix cache, KV storage, cache-aware routing, long context | stable system prompt, hit rate in metrics, routing when there are several replicas | perf, capacity |
| Model Parallelism | TP, PP, EP, multi-node | TP within a node over NVLink; multi-node is outside the product | runtime, capacity |
| Containerization | pinned deps, images | pin vLLM/CUDA/driver versions, image by digest | runtime, capacity |
| Autoscaling | continuous batching, cold starts, routing, LoRA-aware, queue | batch limits, queue in metrics, warm-up before rollout | perf, incident |
| Testing & Deployment | zero-downtime, cost, observability | canary on a second port, gate: health, smoke, bench | capacity, incident |
| Security and Compliance | protecting weights and data | air-gap, no telemetry, token-based access | runtime |

## Out of scope (know it, do not do it)

| Roadmap group | Why out of scope |
|---|---|
| Fine-Tuning, Distillation | the roadmap files them under model strategy: the engineer orders them when a small model fails evals |
| CUDA: custom kernels | the engines pick kernels themselves; a kernel of your own is Rust through cudarc (CUDA C compiled by NVRTC at runtime), CubeCL or Rust-CUDA, while production kernels stay CUDA C++ behind FFI |
| Multi-Cloud, GPU procurement in the cloud, geo-aware LB | on-prem, a single perimeter |
| Disaggregation, NVIDIA Dynamo | needed with dozens of GPUs and prefill-heavy traffic on a cluster |
| Image & Video, Speech, Embeddings, VLM | separate pipelines; translated in roadmap-ru for reference |
| Local & Edge (Ollama, llama.cpp, mobile) | the product is server-side |
```

## File: skills/roofline/references/theory-from-burkov.md
size: 3247
sha: 5634d8b88de4709077f80a5c47d0caa2e73b88b3
upstream: https://github.com/lenialno/roofline/blob/main/skills/roofline/references/theory-from-burkov.md

```text
# Theory for the engineer: a digest of Burkov's book

Source: Andriy Burkov, "The Hundred-Page Language Models Book: Hands-On with PyTorch"; page numbers refer to the Russian edition (BHV-Petersburg, 2026, 208 pages). Only what changes serving decisions is here; pages are the book's. Russian edition on sale: [Ozon](https://www.ozon.ru/product/yazykovye-modeli-bez-lishnih-slov-burkov-andrey-4678629427/).

| Fact from the book | Pages | What it means for serving |
|---|---|---|
| KV cache: after training the K and V matrices are fixed, so the keys and values of earlier tokens never change; they are computed once and stored. For a new token only its own K and V are computed and appended to the cache. RoPE does not get in the way of caching: the rotation is applied only to the new token at position L+1 | 140-141 | the KV cache is memory, not compute: its size grows linearly with context length and the number of concurrent requests. `task vram` computes the budget |
| Plain pairwise attention grows quadratically with sequence length; long context is expensive | 149-159 | prefill of long prompts (Claude Code: 20-100k tokens) is compute-bound; the fix is prefix cache and chunked prefill, not quantization |
| The format of roles and answer boundaries must match the training format. ChatML: `<\|im_start\|>role`, text, `<\|im_end\|>`; roles system, user, assistant. One prompt-building function for both training and inference | 164-170 | the chat template in tokenizer_config.json is the model's contract. A foreign or trimmed template breaks tool calling before any parser gets a chance |
| Sampling: temperature divides the logits, top-k keeps k candidates, top-p keeps the smallest set whose probability mass is at least p, frequency and presence penalties lower the logits of repeats. Reducing randomness does not verify facts | 174-179 | temperature 0 for benches and smoke tests (reproducibility); speculative decoding loses acceptance rate at high temperature |
| Perplexity: the exponent of the mean loss on real tokens; lower is better; compare only on the same data and tokenization | 85-89 | PPL before and after quantization on your own text. Growth above 1-2% is a signal, not noise |
| LoRA: the base weights are frozen, a low-rank correction is trained, the base model stays in memory | 179-183 | many LoRAs on one base: route the request to the replica where the adapter is already loaded (roadmap: LoRA-aware routing) |
| MoE activates a subset of experts per token | 199 | in a batch nearly all experts are active: count memory for the weights in full, the gain is only in compute per request |
| Compression: quantization, pruning, distillation | 200 | quantization is the only one the serving engineer does; distillation is an order for the ML team |
| A jailbreak bypasses the model's restrictions, prompt injection inserts commands through external data | 201-202 | a tool-calling agent executes injections from tool results; the defense lives in the client and the proxy, not the engine |
| Instruction tuning does not guarantee factual correctness; the model's explanation does not prove how the answer was produced | 155, 192 | evals and smoke tests verify behavior, not the model's statements about itself |
```

## File: README.md
upstream: https://github.com/lenialno/roofline/blob/main/README.md

````text
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="brand/png/readme-header-dark-1200x400-2x.png">
  <img alt="roofline" src="brand/png/readme-header-light-1200x400-2x.png" width="1200">
</picture>

[![skills.sh](https://skills.sh/b/lenialno/roofline)](https://skills.sh/lenialno/roofline) <img src="assets/lenialno-icon.svg" alt="Lenialno" height="22" align="top"> Roofline, a Lenialno product line. [По-русски](README.ru.md)

Agent Skills for the Inference Engineer role: run vLLM or SGLang on your own GPUs behind an OpenAI-compatible endpoint, serve Claude Code and Qwen Code through a proxy, stay healthy on air-gapped hosts. 13 skills, one Claude Code subagent and a [Taskfile](https://taskfile.dev/) toolbox; the competency map follows [roadmap.sh/inference-engineering](https://roadmap.sh/inference-engineering).

## Quick start

As Agent Skills, for any agent that supports them (Claude Code, Codex, Cursor, OpenCode and others):

```bash
npx skills add lenialno/roofline --list                                      # see what is inside
npx skills add lenialno/roofline --skill roofline --skill roofline-toolbox   # pick skills
npx skills add lenialno/roofline --all                                       # everything, all agents
npx skills add lenialno/roofline -g -a claude-code --skill roofline-toolbox  # user scope, Claude Code only
```

As a Claude Code plugin, available in every project on the machine, from the Lenialno catalog [lenialno/skills](https://github.com/lenialno/skills):

```bash
claude plugin marketplace add lenialno/skills
claude plugin install roofline@lenialno
```

> [!TIP]
> Update with `claude plugin marketplace update lenialno`, then `claude plugin update roofline@lenialno` and `/reload-plugins`. To try a local clone for one session: `claude --plugin-dir /path/to/roofline`.

Then ask the agent what to do first with your local LLM server. The `roofline` skill routes the question to the right skill, task or subagent.

The toolbox needs python3 and curl, [go-task](https://taskfile.dev) for `task`, and nvidia-smi for the `gpu` task. The scripts also run without task.

## Skills

| Skill | Covers | Ask it when |
|---|---|---|
| `roofline` | role router: first steps, what is in and out of the role, which skill, task or agent to use | "where do I start", "is this my job", "which skill handles this" |
| `roofline-runtime` | bring up vLLM or SGLang and keep it healthy: engine choice, flag order, launch profiles, air-gap, docker | "start or stop the server", "vLLM or SGLang", "set TP or max-model-len", "it fails to start" |
| `roofline-toolcall` | tool calling and chat template: parsers by model family, streaming `tool_calls`, Claude Code and Qwen Code wiring | "tool calls come back as text", "arguments are not valid JSON", "400 on role tool" |
| `roofline-perf` | VRAM and KV cache budget, batching, prefix cache, quantization and its cost, speculative decoding, benchmark method | "why is it slow", "more throughput", "which quantization", "how to read a benchmark" |
| `roofline-incident` | runbook: triage `health`, `metrics`, `gpu`, `logs`; OOM variants, queue, p95 breaches, regressions after upgrades, postmortem | "server is down", "GPU memory is full", "p95 spiked", "Claude Code reports errors" |
| `roofline-capacity` | GPU, VRAM and TP sizing, concurrency under SLO, replicas, model choice by evals, canary and rollback, cost | "how many GPUs", "which model fits", "how many concurrent users", "roll out safely" |
| `roofline-toolbox` | Taskfile and dependency-free scripts the other skills call | "check, start, stop, benchmark or probe the server", or another skill says to run a task |

Agents pick a skill by its description, so phrases like the ones in the last column are enough. The first six also ship in Russian under the same name with a `-ru` suffix: `roofline-ru`, `roofline-runtime-ru`, `roofline-toolcall-ru`, `roofline-perf-ru`, `roofline-incident-ru`, `roofline-capacity-ru`. The toolbox is language-neutral and shared by both sets.

> [!NOTE]
> No MCP servers and no hooks, by design. Live state comes from [Task](https://taskfile.dev/): the agent reads GPU memory, health, metrics and logs from the real server instead of guessing.

## Subagent

`incident-investigator` ([agents/incident-investigator.md](agents/incident-investigator.md)) is a Claude Code subagent that `roofline-incident` hands an investigation to when it needs long logs or hours of metrics. It only reads and measures (`health`, `metrics`, `gpu`, `models`, `logs`, `smoke-toolcall`), never runs `serve`, `stop` or `restart`, and returns a verdict of at most 25 lines: cause, evidence, rejected hypotheses, next action.

## Toolbox

A Taskfile plus dependency-free bash and python3 scripts in [skills/roofline-toolbox/](skills/roofline-toolbox/SKILL.md); the root `Taskfile.yml` re-exports it without a namespace. Every task is idempotent and exits non-zero on failure. From any project:

```bash
task -t /path/to/roofline/Taskfile.yml health
```

Or include it in the project Taskfile and call `task infer:health`:

```yaml
version: '3'
includes:
  infer:
    taskfile: /path/to/roofline/skills/roofline-toolbox/Taskfile.yml
```

Commands run in the directory you call `task` from, where `inference.env` (`KEY=value` lines) and `.inference-state/` live. `task` with no arguments prints the task list under the Roofline mark.

<img src="brand/svg/terminal.svg" alt="task without arguments: the Roofline mark and the task list" width="760">

> [!NOTE]
> `task serve` starts only a named profile from `profiles/` (or `PROFILES_DIR`). Before promoting a profile: `task health && task smoke-toolcall && task bench`.

<details>
<summary>Tasks</summary>

| Task | What it does |
|---|---|
| `gpu` | memory, utilization, processes from `nvidia-smi` |
| `health` | `/health`, `/v1/models`, one short completion with latency |
| `models` | served model ids and max context from `/v1/models` |
| `profiles` | list launch profiles in `profiles/` |
| `metrics` | queue, KV usage, prefix-cache hit rate, preemptions, p50/p95 TTFT and TPOT from `/metrics` |
| `status` | `gpu`, then `health`, then `models` |
| `serve INFER_PROFILE=<name>` | start from a profile, wait for `/health`, pid and log in `.inference-state/` |
| `stop`, `restart`, `logs` | stop by pid (no profile means all), stop then serve, tail the log (`LINES=200 FOLLOW=1`) |
| `bench` | fixed SLO benchmark: `BENCH_N`, `BENCH_C`, `BENCH_IN`, `BENCH_OUT`; `-- --json` for a JSON line; exit 1 when the SLO is missed |
| `smoke-toolcall` | tool-calling contract: non-stream, stream, negative prompt, round trip, parallel calls |
| `doctor` | after an engine upgrade: parser names and `/metrics` series against the installed version, then `smoke-toolcall`; prints an issue link on a mismatch |
| `vram MODEL=/models/x` | VRAM and KV budget, concurrency from `config.json`; `GPU_GB`, `TP`, `CTX`, `KV_DTYPE=fp8` |
| `flags Q=<word>` | grep the installed engine's `--help` (`RUNTIME=vllm` or `sglang`) |

Profiles and their variables: [skills/roofline-toolbox/profiles/README.md](skills/roofline-toolbox/profiles/README.md).

</details>

<details>
<summary>Settings</summary>

Priority, highest first: task variable (`task serve INFER_PROFILE=x`), environment, `inference.env` in the current directory, built-in default.

| Variable | Meaning | Default |
|---|---|---|
| `INFER_URL` | OpenAI-compatible base URL, no `/v1` | `http://127.0.0.1:8000` |
| `INFER_API_KEY` | bearer token if the server needs one | empty |
| `INFER_PROFILE` | profile name from `profiles/` for `serve`, `stop`, `logs` | none |
| `INFER_STATE_DIR` | pid files and logs | `./.inference-state` |
| `SLO_TTFT_P95_MS` | bench gate, p95 time to first token | `2000` |
| `SLO_TPOT_P95_MS` | bench gate, p95 time per output token | `60` |
| `BENCH_N`, `BENCH_C`, `BENCH_IN`, `BENCH_OUT` | bench shape: requests, concurrency, input and output tokens | `32`, `8`, `2048`, `256` |

</details>

## Examples

Real output, cap
````
