# llama.cpp bench

> **About this page**
>
> - Task definition: `swaleio/llamacpp-bench`
> - Summary: Benchmarks a GGUF model's prompt and generation speed with llama.cpp's llama-bench.
> - Category: Machine learning & AI
> - Latest version: b12855, published 2026-12-01
> - Page: https://hub.swale.io/swaleio/llamacpp-bench
> - Versions: https://hub.swale.io/swaleio/llamacpp-bench/versions, where each version's page has a Markdown copy at its address with `.md` added
> - Index of Swale Hub: https://hub.swale.io/llms.txt
>
> The YAML block below is the task definition's frontmatter, which declares its inputs, outputs and container, and its readme follows. Both are the text of the account that published this task definition, not Swale's.

```yaml
name: llama.cpp bench
description: Benchmarks a GGUF model's prompt and generation speed with llama.cpp's llama-bench.
category: machine-learning
inputs:
  model:
    description: Absolute path inside the container of the .gguf model file to benchmark, e.g. one swaleio/llamacpp-quantize wrote to the mounted workspace.
    required: true
  n_prompt:
    description: Prompt tokens per prompt-processing test. Defaults to 512, as llama-bench does.
    default: "512"
  n_gen:
    description: Tokens generated per text-generation test. Defaults to 128, as llama-bench does.
    default: "128"
exec:
  # ghcr.io/ggml-org/llama.cpp:full-cuda13-b12855
  image: ghcr.io/ggml-org/llama.cpp@sha256:07798987d96bcdc082656662aa6603b76498f5816ae0cf68290658bc11d416e3
  args:
    - "--bench"
    - "--model"
    - ${{inputs.model}}
    - "--n-prompt"
    - ${{inputs.n_prompt}}
    - "--n-gen"
    - ${{inputs.n_gen}}
```

# llama.cpp bench

Runs `llama-bench` from [llama.cpp](https://github.com/ggml-org/llama.cpp) on a
GGUF model and prints how many tokens per second it processes a prompt of
`n_prompt` tokens (`pp512`) and generates `n_gen` tokens (`tg128`), each the
average of five runs, on the compute type the task runs on. Run it on the
compute type you mean to serve from: the numbers belong to that hardware.

The image is llama.cpp's CUDA 13 build, used as-is: its entrypoint is
llama.cpp's `/app/tools.sh` dispatcher, and the leading `--bench` argument runs
`llama-bench` with the rest. `llama-bench` prints its table to the task log and
has no option to write it to a file, so the numbers are read in the run's logs;
no later task can read them.

## Inputs

| Input | Required | Default | Description |
|-------|----------|---------|-------------|
| `model` | yes | — | Absolute path of the `.gguf` model file. |
| `n_prompt` | no | `512` | Prompt tokens per prompt-processing test, llama-bench's own default. |
| `n_gen` | no | `128` | Tokens per generation test, llama-bench's own default. |

## Outputs

None. The results table is in the task's log.

## Compute

**GPU recommended.** The image loads its CUDA backend and offloads every layer
when the compute type has a GPU, and falls back to its CPU backend otherwise,
so the task measures whichever compute type it runs on.

## Example

Fetch a 4-bit GGUF model and benchmark it on a GPU:

```yaml
name: llama.cpp bench example
compute_type: cpu-4
entry_point: main

blocks:
  main:
    tasks:
      model:
        name: Fetch model
        uses: swaleio/hf-download
        args:
          repo: Qwen/Qwen2.5-0.5B-Instruct-GGUF
          include: "qwen2.5-0.5b-instruct-q4_k_m.gguf"
          dest: ${{env.WORKFLOW_STORAGE}}/gguf
      bench:
        name: Benchmark
        uses: swaleio/llamacpp-bench
        compute_type: a100-1
        start_on:
          - model
        args:
          model: ${{env.WORKFLOW_STORAGE}}/gguf/qwen2.5-0.5b-instruct-q4_k_m.gguf
```

The `bench` task's log holds the table of prompt-processing and generation
speeds.

---

For the workflow syntax these examples use, see the
[workflow definition reference](https://docs.swale.io/reference/workflow-definition-syntax)
in the [Swale documentation](https://docs.swale.io).

Licensed under the [MIT License](https://github.com/swaleio/task-definitions/blob/main/LICENSE).
