Example#

This is an example of installing and then using the benchtools for a simple benchmark

install from Source#

Installing from source means you can pull to update.

First, clone the repo:

git clone https://github.com/ml4sts/benchtools.git
Cloning into 'benchtools'...
remote: Enumerating objects: 908, done.
remote: Counting objects: 100% (277/277), done.
remote: Compressing objects: 100% (165/165), done.
remote: Total 908 (delta 145), reused 170 (delta 83), pack-reused 631 (from 2)
Receiving objects: 100% (908/908), 2.34 MiB | 405.00 KiB/s, done.
Resolving deltas: 100% (513/513), done.

See it creates a folder

ls
benchtools

Then install:

Important

the following command needs to specifically say benchtools/ for it to be the path; otherwise benchtools will try to pull from pypi. Alternatively, cd benchtools then pip install .

pip install benchtools/
Processing ./benchtools
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: click in /Users/brownsarahm/miniforge3/lib/python3.12/site-packages (from benchtools==0.2.0) (8.3.0)

Successfully built benchtools
Installing collected packages: benchtools
  Attempting uninstall: benchtools
    Found existing installation: benchtools 0.2.0
    Uninstalling benchtools-0.2.0:
      Successfully uninstalled benchtools-0.2.0
Successfully installed benchtools-0.2.0

Note

the above is truncated, but the last few lines are the most important

Exploring the Demo benchmarks#

Benchrools is packaged with two demos, you can install them to create a copy and explore

benchtool demo list
folderbench	
listbench

benchtools supports two formats for storing tasks:

  • a list of tasks in a single .yml file

  • a set of folders with each task having its own.

Let’s examine the folder-based example first:

benchtool demo install -n folderbench
cd folderbench
ls
README.md  bench_info.yml  custom_scorer.py  multiple_models.yml  runner.yml  tasks 

The tasks folder is the main content:

cd tasks/
:tags: ["skip-execution"]
ls

it has two tasks, one folder for each

add  multiply  symbols

We can look inside one:

cd add/
ls

it has two files: a template and values

template.txt	values.csv
what is {a} + {b}?
a,b,reference
2,3,5
4,5,9
8,9,17

Important

The columns in the csv match the variables in {} in the template, plus a reference column for the answer (this can be empty, but the heading should be there), and optionally an id if you have an alternative naming scheme for the subtasks (each row is a subtask)

we can look at the other task too:

what is the name for the following symbol? {symb}
symb, reference, exmeta
@, at, email
#, pound, number
$, dollar sign, currency

Running a benchmark#

let’s install the other benchmark to run it

benchtool demo install -n listbench

We can see the help for the command

benchtool run --help
Usage: benchtool run [OPTIONS] BENCHMARK_PATH

  Running the benchmark and generating logs , help="The path to the benchmark
  repository where all the task reside."

Options:
  -r, --runner-type [ollama|openai|aws]
                                  The engine that will run your LLM.
  -m, --model TEXT                The LLM to be benchmarked.
  -a, --api-url TEXT              The api call required to access the runner
                                  engine.
  -l, --log-path TEXT             The path to a log directory.
  --help                          Show this message and exit.

Warning

this will be filled in later

We can run a benchmark by name

Note

The default runner is ollama. Make sure ollama is running in advence.

benchtool run listbench/
Running list_bench now

Warning

When a run CLI command (or library method) is called for a benchmark. The status of the benchmark will be automatically commited and the commit hash will be included in the logs if the benchmark was a repository to ensure repeatability

cd listbench/
:tags: ["skip-execution"]
ls
bench_info.yml  custom_response.py  custom_scorer.py  logs  runner.yml  tasks.yml

it creates a logs folder if one does not already exist

Exploring a yaml benchmark#

- name: product
  template: "find the product of {a} and {b}"
  values:
     a: [2,3,5]
     b: [3,4,5]
  reference: calculated
  scorer: "calculated_answer"
  format: "IntAnswer"
- name: product_combination
  template: "find the product of {a} and {b}"
  values:
     a: [2,3,5]
     b: [3,4,5]
  reference: calculated
  value_combinations: combinations
  scorer: 
    - calculated_answer
    - add_justify
  format: "IntJustification"
- name: symbol
  template: "what is the name for the following symbol? {symb}"
  values: 
     symb: ["@","$","#"]
     exmeta: ['internet', 'world', 'internet']
  reference: ["at", "dollar sign", "pound"]
  scorer: "contains"
- name: symbol_dir
  template: "what direction does the {symb} symbol point? and what is its name "
  values: 
     symb: ["^","<",">"]
     name: [carat, less,greater]
     direction: ["up", "left", "right"]
  scorer: check_name_dir
  reference: calculated
  format: NameSource
ls logs/
task_product  task_product_combination  task_symbol  task_symbol_dir

there will be a folder per task

ls logs/task_product/
qwen.qwen3-32b-v1:0

then per LLM

ls logs/task_product/qwen.qwen3-32b-v1:0
1783715070_1783715082

then per run, named by the timestamp of the run start

ls logs/task_product/qwen.qwen3-32b-v1:0/1783715070_1783715082
product_2-3	product_3-4	product_5-5	run_info.yml
cat logs/task_product/qwen.qwen3-32b-v1:0/1783715070_1783715082/run_info.yml 
api: ''
bench_name: listbench
bench_path: listbench
bench_run_id: '1783715070'
commit_hash: null
commit_message: null
concept: simple example of a benchmark defined by a task list in a yaml file, includes
  custom scoring and reponse types
description: "a template based task with template: find the product of {a} and {b} and values like:\n\
  \n |    |   a |   b |   reference |\n|---:|----:|----:|------------:|\n|  0 |  \
  \ 2 |   3 |           6 |\n|  1 |   3 |   4 |           12 |\n|  2 |   5 |   5 |\
  \          25 |"
format: IntAnswer
id_generator: concatenator_id_generator
inference_parameters: null
log_path: listbench/logs/task_product
model: qwen.qwen3-32b-v1:0
name: product
reference:
  product_2-3: 6
  product_3-4: 12
  product_5-5: 25
  runner_type: bedrock
scorer: exact_match
task_run_id: '1783715070_1783715082'
task_timestamp: '1783715082'
template: find the product of {a} and {b}
values:
values:
- a: 2
  b: 3
  prompt_id: product_2-3
- a: 3
  b: 4
  prompt_id: product_3-4
- a: 5
  b: 5
  prompt_id: product_5-5

it stored overall information for the run

ls logs/task_product/qwen.qwen3-32b-v1:0/1783715070_1783715082/product_2-3/
log.json	log.txt

and a log for each prompt in both text and json format. The json file includes more details about the subtask and its metadata whereas the text file holds only a prompt and a response to simulate a conversation thread

cat logs/task_product/qwen.qwen3-32b-v1:0/1783715070_1783715082/product_2-3/log.txt 
response ------
{
  "answer": 6
}
cat logs/task_product/qwen.qwen3-32b-v1:0/1783715070_1783715082/product_2-3/log.json 
{
    "task_name": "product",
    "template": "find the product of {a} and {b}",
    "steps": {
        "0": {
            "prompt_id": "product_2-3",
            "prompt": "find the product of 2 and 3",
            "values": {
                "a": 2,
                "b": 3,
                "prompt_id": "product_2-3"
            },
            "format": {
                "properties": {
                    "answer": {
                        "title": "Answer",
                        "type": "integer"
                    }
                },
                "required": [
                    "answer"
                ],
                "title": "IntAnswer",
                "type": "object"
            },
            "response": "{\n  \"answer\": 6\n}",
            "error": null,
            "prompt_tokens": 21,
            "response_tokens": 10,
            "total_tokens": 31,
            "stop_reason": "end_turn"
        }
    }
}

Initializing a new benchmark#

benchtool
Usage: benchtool [OPTIONS] COMMAND [ARGS]...

  BenchTools is a tool that helps researchers set up benchmarks.

Options:
  --help  Show this message and exit.

Commands:
  add-task  Set up a new task.
  demo      demo benchmarks package with benchtools
  init      Initializes a new benchmark.
  run       Run the benchmark, generate logs, and optionally sore
  run-task  Running the tasks and generating logs
  score     Running the benchmark and generating logs Parameters:...
benchtool init --help
Usage: benchtool init [OPTIONS] [BENCHMARK_NAME]

  Initializes a new benchmark.

  Benchmark-name is required, if not provided, requested interactively.

  this command creates the folder for the benchmark.

Options:
  -p, --path TEXT   The path where the new benchmark repository will be placed
  -a, --about TEXT  Benchmark describtion. Content will go in the about.md
                    file
  --no-git          Don't make benchmark a git repository. Default is False
  --help            Show this message and exit.

it asks questions interactively

benchtool init example --about 'in class example benchmark'
Do you want to add any tasks now? [y/N]: y
Do you have task files already prepared? [y/N]: N
What type of template would you like to add? (csv, yaml): yaml
what is the name of your task?: animal
Do you want to add another? [y/N]: N
Creating example Benchmark in ./example
Created example benchmark successfully!
Do you want to go through the BetterBench checklist now? [Y/n]: n
Do you want to run the benchmark now? [Y/n]: n
ls
benchtools	example
cd example/

ls
about.md	info.yml	tasks
cat info.yml 
bench_name: example
concept: in class example benchmark
tasks:
- id: animal
  name: animal
  storage_type: yaml
cat tasks.yml 
- description: 'give your task a short description '
  id_generator: concatenator_id_generator
  name: animal
  reference: ''
  scorer: exact_match
  template: Your {noun} for the model here with values that should vary              denoted
    in brackets. {verb} matching  keys below
  values:
    noun:
    - text
    - task
    verb:
    - use
    - select

Let’s mannually edit the task to make a good example.

nano tasks.yml 
- description: 'animal identifcaiton '
  format: StringAnswer
  id_generator: concatenator_id_generator
  name: animal
  reference: ['zebra', 'tiger', "cheetah"]
  scorer: contains
  template: an animal has a {pattern}, {feet}, and {skin}. what kind of animal is it?
  values:
    pattern:
    - stripes
    - stripes
    - spots
    skin:
    - hairy
    - hairy
    - hairy
    feet: 
    - hooves
    - paws
    - paws
ls
about.md	info.yml	tasks.yml
benchtool run .

Let’s see what happened after running the benchmark

ls
about.md	info.yml	logs tasks.yml

Now we have a new logs/ folder. Let’s explore its contents

ls logs/
gemma3
ls logs/gemma3/
animal
ls logs/gemma3/animal
1780063281

1780063281 is the timestamp of when the benchmark was run which represents a single run of the benchmark

ls logs/gemma3/animal/1780063281
animal_spots-hairy-paws  animal_stripes-hairy-hooves  animal_stripes-hairy-paws  run_info.yml

Each run will have a folder for the different subtasks

Let’s run the scorer to score the LLM on the task at hand.

benchtool score .
Saved Eval: ./eval_1780069448
cat ./eval_1780069448.json
[{"task_name": "animal", "template": "an animal has a {pattern}, {feet}, and {skin}. what kind of animal is it?", "prompt_id": "animal_spots-hairy-paws", "error": "None", "values": {"pattern": "spots", "skin": "hairy", "feet": "paws", "prompt_id": "animal_spots-hairy-paws"}, "steps": {"0": {"prompt": "an animal has a spots, paws, and hairy. what kind of animal is it?", "response": "{\n    \"answer\": \"A dog\"\n}\n", "score": 0}}, "model": "gemma3", "task": "animal", "run": "1780063281"}, {"task_name": "animal", "template": "an animal has a {pattern}, {feet}, and {skin}. what kind of animal is it?", "prompt_id": "animal_stripes-hairy-hooves", "error": "None", "values": {"pattern": "stripes", "skin": "hairy", "feet": "hooves", "prompt_id": "animal_stripes-hairy-hooves"}, "steps": {"0": {"prompt": "an animal has a stripes, hooves, and hairy. what kind of animal is it?", "response": "{\n  \"answer\": \"A zebra!\"\n}", "score": 1}}, "model": "gemma3", "task": "animal", "run": "1780063281"}, {"task_name": "animal", "template": "an animal has a {pattern}, {feet}, and {skin}. what kind of animal is it?", "prompt_id": "animal_stripes-hairy-paws", "error": "None", "values": {"pattern": "stripes", "skin": "hairy", "feet": "paws", "prompt_id": "animal_stripes-hairy-paws"}, "steps": {"0": {"prompt": "an animal has a stripes, paws, and hairy. what kind of animal is it?", "response": "{\n  \"answer\": \"A zebra!\"\n}\n", "score": 0}}, "model": "gemma3", "task": "animal", "run": "1780063281"}]

Get updates#

Tip

Watch the repo to get notifications for important updates

Then update by pulling

cd benchtools/
git pull

and re-installing:

pip install .