# LM evaluation harness

> **About this page**
>
> - Task definition: `swaleio/lm-eval`
> - Summary: Evaluates a model on lm-evaluation-harness benchmarks using the vLLM backend, writing JSON.
> - Category: Machine learning & AI
> - Latest version: 0.4.13-r1, published 2026-11-30
> - Page: https://hub.swale.io/swaleio/lm-eval
> - Versions: https://hub.swale.io/swaleio/lm-eval/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: LM evaluation harness
description: Evaluates a model on lm-evaluation-harness benchmarks using the vLLM backend, writing JSON.
category: machine-learning
inputs:
  model_dir:
    description: The model to evaluate — the full path of a local model directory such as one fetched by hf-download, or a Hugging Face repo id.
    required: true
  tasks:
    description: Comma-separated lm-eval task names to run, e.g. "mmlu,gsm8k". The list is passed as a single value, so commas are safe.
    required: true
  output_path:
    description: Absolute path inside the container under which lm-eval writes its results JSON. Point it at the mounted workspace (e.g. ${{env.WORKFLOW_STORAGE}}/eval) to share the results with later tasks, or any other container-local path.
    required: true
  token:
    description: Hugging Face access token for gated or private models (pass a secret). Omit for public models and local model directories.
    default: ""
  prefix_caching:
    description: Whether vLLM reuses the prompt text it already processed across requests. "false" keeps repeated runs' scores close to identical; "true" can be faster on multiple-choice tasks, but scores can vary slightly between runs.
    default: "false"
exec:
  # docker.io/swaleio/lm-eval:0.4.13-r1
  image: docker.io/swaleio/lm-eval@sha256:555e02c5f50f126d08ca7f31fe6e3164785aa7979f842fdc6dc63b300bce191e
  env:
    HF_TOKEN: ${{inputs.token}}
  args:
    - lm_eval
    - "--model"
    - vllm
    - "--model_args"
    - pretrained=${{inputs.model_dir}},enable_prefix_caching=${{inputs.prefix_caching}}
    - "--tasks"
    - ${{inputs.tasks}}
    - "--batch_size"
    - auto
    - "--output_path"
    - ${{inputs.output_path}}
```

# LM evaluation harness

Runs the EleutherAI
[lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness)
(`lm_eval`) against a model, using the bundled **vLLM** engine as the inference
backend with `--batch_size auto`. Evaluate a checkpoint fine-tuned earlier in
the run, or a base model straight off the Hub, on standard benchmarks such as
`mmlu`, `gsm8k`, `hellaswag`, `arc_challenge`, or `winogrande`. Benchmark
datasets are downloaded from the Hub at run time.

## Inputs

| Input | Required | Default | Description |
|-------|----------|---------|-------------|
| `model_dir` | yes | — | Full path of a local model directory (e.g. from `hf-download`), or a Hugging Face repo id. |
| `tasks` | yes | — | Comma-separated lm-eval task names, e.g. `mmlu,gsm8k` — passed as one value, no word-splitting. |
| `output_path` | yes | — | Absolute path the results are written under. Point it at the mounted workspace (e.g. `${{env.WORKFLOW_STORAGE}}/eval`) to share them with later tasks. |
| `token` | no | — | HF access token for gated/private models (pass a secret). |
| `prefix_caching` | no | `false` | Whether vLLM reuses prompt text it already processed. `false` keeps repeated runs' scores close to identical; `true` can be faster on multiple-choice tasks, but scores can vary slightly between runs. |

`prefix_caching` stays `false` so that evaluating the same model twice gives
the same scores. With it on, vLLM reuses prompt text it has already processed,
which can speed up multiple-choice tasks, since they repeat each question for
every answer option. The cost is small numeric differences that can change a
close answer, and with it the score.

## Outputs

None declared. `lm_eval` writes its results under `output_path`: current
harness versions create a per-model subdirectory there containing
`results_<timestamp>.json`. Pass a workspace path so a later task can parse,
compare, or publish the results.

## Compute

**GPU required.** The model is loaded through vLLM, so the GPU's VRAM must fit
it: roughly 2 GB per billion parameters for bf16 weights plus KV-cache
headroom, so a 7–8B model wants a 24 GB+ GPU. This task's fixed command line
keeps vLLM's default engine settings (no tensor parallelism), so size the
compute type so that one GPU fits the model. The workflow selects the compute
type via `compute_type`; on a CPU compute type the task fails at runtime with
CUDA errors.

## Reusing downloaded weights

`model_dir` accepts the full path of a local model directory. Point it at the
output of an `hf-download` task (e.g. `${{tasks.<id>.outputs.path}}`) to avoid
re-downloading multi-gigabyte weights from the Hub on every run.

## Gated and private models

When `model_dir` is a gated or private Hub repo id, pass a Hugging Face access
token via `token` (as a secret) — the definition's `exec.env` delivers it to
the harness as `HF_TOKEN` (an omitted token resolves to an empty value, which
the Hugging Face stack treats as no token).

## Example

```yaml
name: LM evaluation harness example
compute_type: cpu-4
entry_point: main

blocks:
  main:
    tasks:
      weights:
        name: Fetch weights
        uses: swaleio/hf-download
        args:
          repo: Qwen/Qwen2.5-7B-Instruct
          include: "*.safetensors,*.json,tokenizer.*"
          dest: ${{env.WORKFLOW_STORAGE}}/qwen
      eval:
        name: Evaluate
        uses: swaleio/lm-eval
        start_on:
          - weights
        compute_type: a100-1   # any GPU compute type whose VRAM fits the model
        args:
          model_dir: ${{tasks.weights.outputs.path}}
          tasks: "mmlu,gsm8k"
          output_path: ${{env.WORKFLOW_STORAGE}}/eval
```

The harness evaluates the downloaded checkpoint without re-fetching it and
writes the results JSON under `${{env.WORKFLOW_STORAGE}}/eval`, where a later task can
read it — for example to gate a deployment on a minimum benchmark score.

---

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).
