llm-bench

Instrument contract

Every instrument under bench/tasks/ follows these rules so results from different lanes (model × quant × runtime × settings) can be joined item-by-item. Core lives in bench/core/ — lane.py, client.py, results.py, ledger.py, mockserver.py.

Requests

  • Get the lane with bench.core.lane.current(); send every request through client.call_model(...). Never build an HTTP request yourself.
  • Do not read sampler or thinking settings from the environment. The lane owns the sampler, max_tokens, thinking on/off and the no-think mechanism. Pass instrument defaults as max_tokens= / temperature= kwargs — the lane overrides them. Use override= only when the measurement itself requires a setting (e.g. greedy for a determinism probe), and record that.
  • Pass item_id= and run_id= to call_model so paid calls land in the spend ledger by item.
  • Message history: append the assistant message you got back (content + tool_calls) as-is. The client strips reasoning fields and repairs non-JSON tool arguments before sending. Never put reasoning text into content.
  • Catch client.CallError per item. Record it with **client.error_meta(e, dt) and move on. budget_stop means stop the run (write what you have, finish(complete=False)). results.call_attempt(...) does all of this for a single-call attempt.

Results

  • One results.RunStore(instrument, item_set=..., args=...) per run; results.run_attempts(...) opens or resumes it, schedules the (item, sample) attempts and writes the summary. item_set = "<name>@<sha256 of the item definitions>[:12]" so a changed task set never silently compares against an old one.
  • One store.add(...) per attempt: store.add(item_id=..., sample_idx=..., category=..., correct=..., score=..., **client.meta(resp, dt), **extra)
    • item_id: stable string, never positional, the same on every lane.
    • category: the capability-profile bucket (easy/go, hard/rust, judge/shell, rerank/logs, cs, needle/64k/decoy …).
    • correct: bool when graded; leave None when the attempt failed for infra reasons (RunStore.add forces this for infra statuses).
    • score: float in [0,1] for partial credit (e.g. agentic-multitask's fraction of gates passed), else omit.
    • Grade truncated answers (status: truncated) on whatever content exists — usually wrong — but keep the status; the report shows truncation rate separately.
    • status: empty with ≥16 answer tokens generated (completion − reported reasoning) becomes stripped (infra): the server ate the output. RunStore.add and the report both apply results.effective_status, so already-stored rows reclassify on read.
  • Large per-item artifacts (turn logs, raw answers) go in store.sidecar(name, obj); put the returned file name in the row.
  • store.finish(summary) at the end. A run without complete: true is ignored by reports.

CLI conventions

run accepts (results.add_run_args): --samples K (default 1), --concurrency N (≤ lane.max_concurrency), --items id1,id2 (filter), --resume RUN_DIR (skip store.done_keys(); the run keeps the args recorded in its run.json and refuses a changed item_set). validate checks the item set offline (no model).

Isolation

Work dirs live under work/<run_id>/<item_id>-<sample_idx>/. Subprocesses run in their own session (start_new_session=True) and are killed as a process group on timeout. Never bind a fixed port without checking it is free; release it before returning.

Testing

No instrument change is tested against a live endpoint first. Use bench.core.mockserver (MockServer, chat(), tool_call()) and put tests in tests/. Python 3.9, stdlib only. Run: python3 -m unittest discover -s tests.