No description
  • Python 56.4%
  • Shell 43.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
alesha-pro a94c144c3c Make depth_bench.py executable
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-04 23:11:40 +03:00
results Initial commit: context-depth benchmark harness for llama.cpp 2026-08-04 23:10:40 +03:00
.gitignore Initial commit: context-depth benchmark harness for llama.cpp 2026-08-04 23:10:40 +03:00
AGENTS.md Initial commit: context-depth benchmark harness for llama.cpp 2026-08-04 23:10:40 +03:00
CLAUDE.md Initial commit: context-depth benchmark harness for llama.cpp 2026-08-04 23:10:40 +03:00
depth_bench.py Make depth_bench.py executable 2026-08-04 23:11:40 +03:00
EXAMPLE-RESULTS.md Initial commit: context-depth benchmark harness for llama.cpp 2026-08-04 23:10:40 +03:00
make_corpus.sh Initial commit: context-depth benchmark harness for llama.cpp 2026-08-04 23:10:40 +03:00
queue.example.sh Initial commit: context-depth benchmark harness for llama.cpp 2026-08-04 23:10:40 +03:00
README.md Initial commit: context-depth benchmark harness for llama.cpp 2026-08-04 23:10:40 +03:00
report.py Initial commit: context-depth benchmark harness for llama.cpp 2026-08-04 23:10:40 +03:00
run_recipe.sh Initial commit: context-depth benchmark harness for llama.cpp 2026-08-04 23:10:40 +03:00
serve.sh Initial commit: context-depth benchmark harness for llama.cpp 2026-08-04 23:10:40 +03:00

depth-harness

I wrote this to measure llama.cpp prefill and decode speed at real context depth instead of on an empty context. These are the exact scripts I used to profile Qwen3.6-27B on 1x and 2x RTX 3090.

Dependencies are bash, python3 stdlib, curl and nvidia-smi.

What is in here

File What it does
serve.sh starts llama-server for one config (ctx, ubatch, KV type, spec decode, number of GPUs)
depth_bench.py sends requests at a list of depths and collects the timings block from the native /completion
run_recipe.sh server plus health wait plus benchmark plus shutdown, one config end to end
report.py folds the json files into markdown tables: decode, prefill, acceptance, retention vs empty context
make_corpus.sh builds the text corpus whose prefixes fill the context
queue.example.sh example queue of several configs
EXAMPLE-RESULTS.md what the output looks like, with my Qwen3.6-27B numbers

Usage

# 1. corpus (any pile of source files, take it with headroom)
./make_corpus.sh ~/src/llama.cpp 2

# 2. one config
export BIN=/path/to/llama.cpp/build/bin/llama-server
export MODEL=/path/to/model.gguf
./run_recipe.sh my-run 0 131072 1024 q4_0 draft-mtp 2 "0,16384,32768,65536,98304,131072"

# 3. tables
python3 report.py

run_recipe.sh arguments: <label> <gpus> <ctx> <ubatch> <kv type> <spec> <n_max> <depths>. GPUs are listed the way CUDA_VISIBLE_DEVICES wants them (0 or 0,1), and more than one adds --split-mode layer. Pass none as spec to turn speculative decoding off. Depths are token counts, comma separated, where 0 means empty context.

How the measurement works

Depth is filled with a prefix of one corpus file. The script tokenizes the file through /tokenize, takes the first N tokens, sends them back through /detokenize and uses that as the prompt. Points on the curve then differ only in length and not in content, which is what makes them comparable.

Numbers come from the timings block of the native /completion endpoint: prompt_per_second for prefill, predicted_per_second for decode, draft_n and draft_n_accepted for speculative decode acceptance. The OpenAI-compatible /v1 does not return timings, which is why the harness does not use it.

Things I got wrong first

Check the power limit before anything else. My cards sat at 220 W with a factory ceiling of 350 W, and that cost close to half the speed: decode went up 78 to 86 percent across the whole depth range once the limit was lifted. I checked the mechanism separately. The limit halves the SM clock (1432 MHz against 690 MHz) and leaves memory clock untouched. One card at 350 W beat two cards at 220 W. Look at nvidia-smi -q -d POWER, and at SW Power Cap as the throttle reason.

cache_prompt: false is mandatory. Otherwise the second point on the curve measures a prefix cache hit and not prefill.

ignore_eos plus temperature 0 plus top_k 1. This pins the output length and makes the run deterministic. Without it the points on the curve are not comparable to each other.

The corpus has to be coherent text, not random tokens. Random-token synthetics tank speculative decode acceptance. On a different run I measured 19 to 24 percent on random tokens against 47 percent on real code, which is enough to invert the conclusion.

Short generations understate speculative decode. At 128 output tokens I saw 75 percent acceptance and 31.5 t/s, at 512 tokens the same config gave 86 percent and 34.0 t/s. The draft needs a few rounds to warm up. Set NPREDICT=512 if spec decode is what you are measuring.

Every config gets a fresh server process. I do not reuse a server between configs, because caches and memory fragmentation leak from one run into the next.

Throw away truncated generations. report.py drops rows with predicted_n < 64. If the server hits the context limit or dies, the decode rate on that stub is inflated.

Always measure a no-spec baseline. Without it there is nothing to compare the MTP delta against, and on this model it was the cheapest win available: 69 percent on empty context and 55 percent at 64K for 1.1 GB of VRAM.

Limits

Right now the harness targets llama-server. vLLM needs a different client because it does not return the same timings, so a vLLM lane is what I plan to add here next. One iteration per point by default, so for error bars pass --repeat 3 to depth_bench.py and look at the spread.

--spec-type draft-mtp uses a model's built-in MTP head. A separate draft model uses different llama.cpp flags (--model-draft and friends) and you have to add them to serve.sh yourself.

All the numbers here came off my own 4x RTX 3090 box. If you run this on different hardware I would like to see the tables, ping me on X: @superalesha.