Skip to content

feat: add chap benchmark to compare models under one evaluation setup - #969

Draft
knutdrand wants to merge 3 commits into
masterfrom
feat/benchmark-cli
Draft

knutdrand wants to merge 3 commits into
masterfrom
feat/benchmark-cli

Conversation

@knutdrand

Copy link
Copy Markdown
Contributor

Summary

Adds chap benchmark, a CLI command for comparing several models under one evaluation setup. A benchmark is a directory whose benchmark.yaml fixes a dataset (with its checksum), the backtest parameters and the evaluated org units, so every model evaluated on it is scored on the same forecasts.

  • chap benchmark init creates a benchmark after checking that the dataset can be evaluated with the backtest parameters.
  • chap benchmark run evaluates a model on it as chap eval does, writes a NetCDF file to evaluations/ and adds a line to evaluations.jsonl. It stops before running the model if the dataset file has changed since the benchmark was created.
  • chap benchmark show lists the registered evaluations with their main metrics.
  • chap benchmark selection-bias estimates how much of the best model's lead over a baseline is luck, with the same bootstrap over split points as the REST endpoint for backtest specifications.

To make the last one possible, the bootstrap estimate and the scoring per split point move from selection_bias_service to chap_core.assessment.selection_bias, with no database dependency. The service keeps reading the candidates and baseline of a stored specification and building the API response. origin_periods moves to flat_representations, since both the estimate and the prediction monitoring service use it.

Documented in docs/chap-cli/benchmarks.md.

Review needed

Review needed: full

Test plan

  • make test: 2926 passed, 95 skipped. New tests in tests/cli_endpoints/test_benchmark_cli.py.
  • ruff check, mypy, pyright and the alembic head check pass.

A benchmark is a directory with a benchmark.yaml naming a dataset, its checksum, the backtest parameters and the evaluated org units. chap benchmark init creates one, chap benchmark run evaluates a model on it and adds the evaluation to evaluations.jsonl, and chap benchmark show lists the registered evaluations with their main metrics. A run stops before the model starts when the dataset has changed since the benchmark was created.
The bootstrap estimate and the scoring per split point now live in chap_core.assessment.selection_bias, with no database dependency, so it can be used on evaluations read from files. The service keeps reading the candidates and the baseline of a stored specification and building the API response. origin_periods moves to flat_representations, since both the estimate and the prediction monitoring service use it.
chap benchmark selection-bias compares the newest evaluation of each model on a benchmark with a baseline model evaluated on it, and estimates how much of the best model's lead is luck, with the same bootstrap over the split points as the REST endpoint for backtest specifications.
@ivargr

ivargr commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Tried this out locally on laos_subset.csv with the three built-in models, and the whole flow works as documented.

One suggestion on ergonomics: could directory default to the current directory for run, show and selection-bias? Today chap benchmark show inside the benchmark directory fails with parameter --directory requires an argument, so you have to write chap benchmark show . each time.

Chap projects already work this way: chap init laos takes the directory, and after cd laos the commands chap eval, chap validate and so on pick up chap.yaml from the current directory. The benchmark docs compare the two directly, so it would be natural for chap benchmark run --model-name ... to work the same way inside a benchmark directory.

What I have in mind:

  • run, show and selection-bias use the current directory when none is given. Passing a directory works as it does now.
  • init keeps the directory required, so a benchmark is not created in the wrong place by accident.
  • Only the current directory is looked at, not the parents, as find_project() does for chap.yaml.
  • Without an argument and without a benchmark.yaml, the error says that the current directory is not a benchmark, instead of Could not read .../benchmark.yaml.

One thing to watch in run: directory would become an optional positional before the required model_name, so model_name probably has to be keyword-only. Otherwise chap benchmark run builtin:persistence would be read as a directory.

Minor: the created column in chap benchmark show is in UTC without saying so. A run at 20:44 local time shows as 19:44.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants