agentleFS
buddy-compilerbuddy-compiler/buddy-mlir/.agents/skills/llm-inference-optimization/SKILL.md

llm-inference-optimization

Skill773 starsChanged 32 days agoApache-2.0View on GitHub

Performance of LLM inference built by Buddy-MLIR (buddy-codegen models, .rax, buddy-cli) - prefill, decode, attention, KV cache, LM head, speculative decoding. Use when optimizing, profiling or benchmarking LLM inference, comparing it with llama.cpp, or evaluating the accuracy (perplexity) impact of an inference optimization. Not needed for correctness fixes that do not aim at speed.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. BejeweledMe/codex-pro-agent-skills★ 7same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository6 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Follow the performance-optimization workflow.

    line 8
  2. Distinctive:

    Read the platform's files before proposing an optimization: they list what was done, the measured results, and the ideas measured and …

    line 34
  3. Very specific:

    Add a file per platform and topic (<vendor>-<chip>-<topic>.md) when a new platform gets optimization work.

    line 43

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

LLM inference optimization

Follow the performance-optimization workflow; this skill adds what is specific to LLMs.

Know which phase you are optimizing

  • Decode (one token per step) reads every weight once per token: it is DRAM-bandwidth-bound once the matmul kernels are efficient. Floor = weight bytes / read bandwidth. Above the floor: attention (grows with the context), the LM head (a large share for small models), synchronization, per-token runtime overhead. references/decode.md.
  • Prefill (many tokens per step) is compute-bound: matrix units, tiling, activation reuse, data movement around the compute. references/prefill.md.
  • Measure each at several context lengths (e.g. 64, 458, 900 tokens): attention costs change with the position, matmul costs do not.

Validate

  • Same text as the baseline for bit-identical changes; perplexity for numerics changes: buddy-cli --model m.rax --perplexity wiki.test.ids --ppl-context 512 --ppl-chunks 40 (scored like llama-perplexity; ids from llama-tokenize --ids or one id per line). See docs/Runtime.md.
  • references/baselines.md: comparing against llama.cpp fairly (formats, LM head, thread placement, perplexity).

Platform history

Read the platform's files before proposing an optimization: they list what was done, the measured results, and the ideas measured and rejected (with why), so that they are not proposed again without new evidence.

PlatformFiles
SpacemiT K3 (w4g32, docs/K3DeepSeekR1.md)references/spacemit-k3-decode.md, references/spacemit-k3-moe-decode.md (Qwen3-VL-30B-A3B), references/spacemit-k3-prefill.md, references/spacemit-k3-rejected-ideas.md
Tenstorrentnone yet

Add a file per platform and topic (<vendor>-<chip>-<topic>.md) when a new platform gets optimization work.

Scripts

  • scripts/spacemit-k3-w4-kernel-bench.py: builds the w4g32 matmul kernels for 1..N rows and the decode attention for a board microbenchmark (template for other kernels and targets).
  • scripts/prompt-lookup-sim.py: estimates speculative decoding with prompt lookup from greedy outputs (tokens accepted per verification step, speedup for a given verification cost).
  • performance-optimization/scripts/ab_cli.py: model-level A/B.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.