> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nika.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Model bench

> T2 diamond · engineering: the same question, three local models, one MEASURED table. Zero keys, zero cloud, zero spend.

> **T2 diamond · engineering / model selection**: three `infer.model:`
> seats fan out the SAME question in parallel; a `nika:jq` fan-in builds
> a markdown table from measured facts — each answer's latency comes
> from `tasks.X.duration_ms`, the run's own clock. No judge model, no
> scores: the table states facts, the quality call stays yours.

## The job

Picking a default model by vibes is how you end up paying for quality
you don't need — or shipping answers a smaller model would have matched.
This workflow is the bench you run BEFORE deciding: same prompt, three
seats, one report on disk that you can diff run over run.

## The shape

```mermaid theme={"system"}
flowchart LR
  ask_incumbent["ask_incumbent"]:::infer
  ask_challenger["ask_challenger"]:::infer
  ask_tiny["ask_tiny"]:::infer
  tabulate["tabulate · nika:jq"]:::invoke
  persist["persist · nika:write"]:::invoke
  ask_incumbent --> tabulate
  ask_challenger --> tabulate
  ask_tiny --> tabulate
  tabulate --> persist
  classDef infer fill:#5b8cff22,stroke:#5b8cff,color:#5b8cff
  classDef invoke fill:#22d3ee22,stroke:#22d3ee,color:#22d3ee
```

## The file

```yaml model-bench.nika theme={"system"}
nika: model-bench

# NO envelope `model:` on purpose — a default seat would be the one model
# this file never calls: every contender pins its own `infer.model:` below,
# and the bench IS the seats. The absence is load-bearing honesty: with no
# default to override, nothing can claim the mock rehearsal previews this
# file (measured · the mock-preview rescue tip fires only for a file that HAS
# an envelope model to swap).

const:
  question:
    # A TYPED constant is `{ type, value }` — both keys, exactly those two.
    # `{ type, default }` is not a declaration at all (01-envelope.md §const:
    # an object missing either key is a bare literal object), so the prompt
    # below would receive the whole `{type, default}` map instead of the
    # question. Measured: the model gets a JSON blob and the bench is junk.
    type: string
    value: "Explain, in five lines, why a workflow should be audited before it runs."
permits:
  tools: ["nika:jq", "nika:write"]
  fs: { write: ["out/model-bench.md"] }

tasks:
  ask_incumbent:
    infer:
      model: ollama/qwen2.5:14b # the quality bar · the seat to beat
      prompt: "${{ const.question }}"
      # a reasoning model needs 16384 here, or a documented run.reasoning.effort: low
      max_tokens: 600

  ask_challenger:
    infer:
      model: ollama/llama3.2:3b # another family · same size class
      prompt: "${{ const.question }}"
      # a reasoning model needs 16384 here, or a documented run.reasoning.effort: low
      max_tokens: 600

  ask_tiny:
    infer:
      model: ollama/qwen2.5:0.5b # the "is small enough?" probe
      prompt: "${{ const.question }}"
      # a reasoning model needs 16384 here, or a documented run.reasoning.effort: low
      max_tokens: 600

  tabulate:
    with:
      ask_incumbent_duration_ms: ${{ tasks.ask_incumbent.duration_ms }}
      ask_incumbent: ${{ tasks.ask_incumbent.output }}
      ask_challenger_duration_ms: ${{ tasks.ask_challenger.duration_ms }}
      ask_challenger: ${{ tasks.ask_challenger.output }}
      ask_tiny_duration_ms: ${{ tasks.ask_tiny.duration_ms }}
      ask_tiny: ${{ tasks.ask_tiny.output }}
    invoke:
      tool: "nika:jq"
      args:
        input:
          - model: "ollama/qwen2.5:14b"
            ms: "${{ with.ask_incumbent_duration_ms }}"
            answer: "${{ with.ask_incumbent }}"
          - model: "ollama/llama3.2:3b"
            ms: "${{ with.ask_challenger_duration_ms }}"
            answer: "${{ with.ask_challenger }}"
          - model: "ollama/qwen2.5:0.5b"
            ms: "${{ with.ask_tiny_duration_ms }}"
            answer: "${{ with.ask_tiny }}"
        expression: >-
          "| model | latency | chars | answer (first 160) |\n|---|---|---|---|\n"
          + (map("| " + .model + " | "
               + (if .ms == null then "cached" else (.ms | tostring) + "ms" end) + " | "
               + (.answer | length | tostring) + " | "
               + (.answer | gsub("\n"; " ") | .[0:160]) + " |")
             | join("\n"))

  persist:
    with:
      tabulate: ${{ tasks.tabulate.output }}
    invoke:
      tool: "nika:write"
      args:
        path: out/model-bench.md
        create_dirs: true
        content: |
          # Model bench — same question, measured

          ${{ with.tabulate }}

          Facts only: latency from the run's clock, length in characters.
          The answers are side by side — the quality call is yours.

outputs:
  table:
    value: ${{ tasks.tabulate.output }}
    description: "The measured comparison table · latency + length per seat"
```

## Two findings the bench surfaced on its own authoring run

Both were caught live while writing this example — they are what the
bench is FOR:

1. **A thinking model with a bounded `max_tokens` can return an empty
   answer** — it spends the whole budget reasoning before a single
   output token. The row reads `0 chars`: that is a bench *result*, not
   a bug. Seat `ollama/qwen3.5:4b` and reproduce it on your machine.
2. **On a `--resume`, rehydrated rows say `cached`** — a latency that
   was not re-measured is never re-printed as a fresh number. The
   report stays honest across resumes.

## Run it

> [!NOTE]
>
> **What it needs:** [Ollama](https://ollama.com) with the three contenders pulled (`qwen2.5:14b`, `llama3.2:3b`, `qwen2.5:0.5b`). There is no mock rehearsal: each task pins its own model, `--model` replaces only a workflow's default model, and this file has none, so `nika try model-bench` needs the same three models.

**1. Rehearse it**

```bash theme={"system"}
nika try model-bench
```

It runs the same three pinned models: pull them first (next step), or the rehearsal fails on each one that is missing (`NIKA-INFER-001`).

**2. Get your own copy**

Save the file above as `model-bench.nika` in a new folder. It reads no sample file.

**3. Check it, then run it**

```bash theme={"system"}
ollama pull qwen2.5:14b
ollama pull llama3.2:3b
ollama pull qwen2.5:0.5b
nika check model-bench.nika
nika run model-bench.nika
```

The run writes `out/model-bench.md`.

The first call to each model pays its load time: run the bench twice and read the warm numbers. Swap any seat for a cloud model (`mistral/…`, `anthropic/…`, `openai/…`) to bench it against your local models, with its key and `--max-cost-usd`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.