koboldcpp/examples
Piotr Wilkin (ilintar) f3363593f4
Add more benchmarks to llama-eval (#26174)
* llama-eval : add sandboxed execution for code suites

Adds a lightweight replacement for the Docker containers usually used to run
generated code, so a benchmark can be executed without a daemon, an image or
root.

A cached venv is provisioned per suite and reused; candidate programs run in a
throwaway working directory as their own process group, under the strongest
isolation the host offers:

  bwrap    read-only root, tmpfs /tmp and $HOME, no network
  unshare  no network, via --map-current-user
  rlimit   cpu/memory/file-size/process caps only

Candidate code must not run as uid 0, which is why "unshare -r" is a
last-resort tier that warns: root bypasses file permission bits, so a test
asserting that a write to a chmod 0444 file fails would instead see it succeed.

Two details worth noting for the bwrap tier. Only paths hidden by the $HOME
tmpfs are bound back, because bwrap cannot mount onto a symlink and
version-manager alias directories usually are one. And the venv's base
interpreter tree is resolved by walking the symlink chain, since a
version-managed interpreter is commonly reached through an unversioned alias
that startup resolves through.

Suites can declare provisioning steps, which run once at build time while the
network is still up, so test time never needs it.

Assisted-by: Claude Opus 4.8 <noreply@anthropic.com>

* llama-eval : add HumanEval and ClassEval code suites

Adds two execution-graded suites alongside the existing text-graded ones. The
model's reply is parsed for a python code block, combined with the task's own
unit tests, and run in the sandbox.

  --dataset humaneval   164 function-level problems, scored pass@k
  --dataset classeval   100 class-level tasks, scored at class level (feeding
                        pass@k) and method level, matching upstream

pass@k reuses the existing chunk mechanism: --n_cases at a multiple of the
dataset size gives that many samples per problem, aggregated with the unbiased
estimator from the Codex paper.

Program construction and result interpretation are dataset-owned hooks, because
the two suites differ: one HumanEval problem is a function judged by a single
assert, whereas one ClassEval task is a class judged by many independent test
methods, and reducing that to pass/fail would throw away partial credit. Suites
also declare their own package set, provisioning steps, interpreter and timeout.

The package set is derived from the dataset's own imports rather than a
requirements file. HumanEval turns out to need no third-party packages at all;
ClassEval needs thirteen, two of which must be declared because no import
mentions them -- lxml is selected by string in ClassEval_44, and scipy is a
gensim requirement.

Notes on ClassEval specifically:

* gensim publishes no wheel past cp313, so 3.13 is preferred; on 3.14+ the two
  pure-Python APIs it uses are provided by a small shim instead.
* The three nltk corpora it needs are pre-seeded at venv build time. These are
  the modern names -- the dataset asks for the since-renamed punkt and
  averaged_perceptron_tagger.
* It defaults to a patched fork, ilintar/ClassEval, because three upstream
  tests cannot be passed by anything: a hard-coded 2024 date checked against
  datetime.now(), an assertion on the dataset author's own hostname, and an
  exact float comparison. Reference solutions go from 96/100 to 100/100 classes
  and 2182/2196 to 2196/2196 test methods. No skeleton is touched, so what the
  model is asked to write is unchanged; --dataset-source selects the original.

--exec-seed (default 0) seeds the RNG before each test, so suites whose tests
draw random inputs score reproducibly. ClassEval_58 fails its own reference
solution about 30% of the time without it.

The simulator gains both suites, so the harness can be exercised without a
model.

Assisted-by: Claude Opus 4.8 <noreply@anthropic.com>

* llama-eval : fix silent isolation downgrade, generalise the sandbox runner

The isolation probe ran the interpreter without binding it back, so whenever
this tool is itself started from a venv under $HOME -- the usual case, since it
needs `datasets` -- bwrap's tmpfs hid the interpreter, the probe failed, and the
sandbox quietly fell back to a tier that does not hide $HOME at all. Nothing in
the output looked wrong when that happened, and the existing suites have been
running that way. The probe now uses the same interpreter and the same binds the
suite will actually get.

Two additions the agentic suite needs, neither of which changes the existing
suites:

* run_argv() runs an arbitrary command in a caller-owned directory that survives
  the call. run() is now a thin wrapper over it, so HumanEval and ClassEval take
  exactly the same path as before. A multi-step agent needs its edits to persist
  across many invocations, and a suite for a language other than Python needs to
  drive a linter and a test runner rather than a single source string.

* RLIMIT_AS is now per-sandbox, defaulting to what it was. It caps reserved
  address space rather than resident memory, which is the wrong instrument for a
  runtime that reserves a large region and commits little of it: node's
  TypeScript type-stripping goes through WebAssembly, reserves gigabytes per
  instance, and aborts at 4 GiB with an out-of-memory error that reads like a
  fault in the code under test.

HumanEval stays at 164/164 and ClassEval at 100/100.

Assisted-by: Claude Opus 5 <noreply@anthropic.com>

* llama-eval : add SACB, a multi-turn agentic coding suite

`--dataset agentic` is a different shape from the other code suites. Rather than
answering a single prompt, the model is given a small but real repository, a
narrow tool set and a bug report, drives its own multi-turn conversation, and is
graded by running a test suite it was never allowed to see.

The corpus is SACB (Simple Agent Coding Benchmark), 60 tasks over three
hand-written repositories in Python and TypeScript, hosted at ilintar/SACB.
Grading needs no container: a cached venv gives ruff and mypy for Python, and
node's own test runner plus tsc for TypeScript, so the whole dependency set is
four packages.

Three constraints are deliberate:

* No shell, and no way to run the tests. The only feedback channel is `lint`. A
  syntax or type error can be driven out mechanically; a logic error has to be
  reasoned about. A harness that lets an agent iterate against the test suite
  measures something closer to search than to understanding.
* Two edit tools, one line-addressed and one content-addressed. Which one a
  model reaches for, and whether it keeps line numbers straight after its own
  earlier edit, is itself a signal.
* The tests never touch the working tree. They are held outside it and copied
  into a throwaway copy only once the agent has stopped, so they can be neither
  read nor edited. Every tool path is resolved and confinement-checked against
  the repository root, so a symlink planted inside the tree cannot reach out of
  it.

A task counts as resolved when every test that was failing passes and nothing
that already passed broke. Both sets are derived by running the tests against
the defective tree and against the reference fix, never written by hand, so a
task whose defect no test exercises cannot enter the corpus. Many tasks carry
several independent defects, so the fraction of target tests passed is reported
alongside, separating "fixed two of the three faults" from "changed nothing".

An episode that arrives with no tool call and no `finish` is nudged rather than
ended. Models routinely narrate their analysis mid-task, and treating that as
completion ends the episode with no edits and scores a reasoning failure that
never happened; about one episode in four exits that way.

Nothing here is installed unless this suite is selected, and then only for the
language being run: agentic_eval is imported lazily and each toolchain is keyed
per language.

Assisted-by: Claude Opus 5 <noreply@anthropic.com>

* llama-eval : make the agentic hooks typed rather than discovered

`ty` flagged nine unresolved attributes, of which the seven in main() predate
the agentic suite: `EvalState.dataset` is Optional and was dereferenced without
narrowing.

* `loaded_dataset` turns the Optional into a value in one place, raising rather
  than handing back None, so callers do not each have to narrow it.
* `is_agentic`, `prepare()` and `run()` are declared on BaseDataset. They were
  reached through getattr with a default at three call sites, which no checker
  can see through; `run()` now raises a clear error naming the suite instead of
  failing as a missing attribute.
* The sandbox setup is one branch on `is_agentic` rather than two tests of
  `grader_type`, which also drops a duplicated condition.

No behaviour change: HumanEval stays at 164/164, and `ty check` on
examples/llama-eval is clean.

Assisted-by: Claude Opus 5 <noreply@anthropic.com>

* feat: API key

* fix reasoning and response length for agentic runs, add option to save entire transcripts

* llama-eval : fix ty unresolved-attribute on loaded_dataset.ae

Assisted-by: AI coding agent

* llama-eval : trim comments and remove non-ASCII from README

Assisted-by: AI coding agent
2026-10-16 11:52:18 +02:00
..
batched batch: migrate the rest of examples to llama_batch_ext (#29601) 2026-09-30 18:08:43 +02:00
batched.swift examples : remove references to make in examples [no ci] (#15457) 2025-08-21 06:12:28 +02:00
convert-llama2c-to-ggml cmake : fix build when GGML_CPU=OFF and GGML_CUDA=ON (#29026) 2026-09-18 11:44:03 +03:00
debug batch: migrate the rest of examples to llama_batch_ext (#29601) 2026-09-30 18:08:43 +02:00
deprecation-warning Fix locale-dependent float printing in GGUF metadata (#17331) 2026-03-04 09:30:40 +01:00
diffusion chat: replace output string with parts (#30389) 2026-10-14 01:03:56 +02:00
embedding batch: migrate the rest of examples to llama_batch_ext (#29601) 2026-09-30 18:08:43 +02:00
eval-callback batch: migrate the rest of examples to llama_batch_ext (#29601) 2026-09-30 18:08:43 +02:00
gen-docs server: add get_info tool (#26522) 2026-08-03 18:51:02 +02:00
gguf Fix locale-dependent float printing in GGUF metadata (#17331) 2026-03-04 09:30:40 +01:00
gguf-hash build : fix xcframework + cmake clean-up (#27304) 2026-08-18 11:16:51 +03:00
idle batch: migrate the rest of examples to llama_batch_ext (#29601) 2026-09-30 18:08:43 +02:00
llama-eval Add more benchmarks to llama-eval (#26174) 2026-10-16 11:52:18 +02:00
llama.android batch: migrate the rest of examples to llama_batch_ext (#29601) 2026-09-30 18:08:43 +02:00
llama.swiftui llama : deprecate llama_kv_self_ API (#14030) 2025-06-06 14:11:15 +03:00
lookahead batch: migrate the rest of examples to llama_batch_ext (#29601) 2026-09-30 18:08:43 +02:00
lookup batch: migrate the rest of examples to llama_batch_ext (#29601) 2026-09-30 18:08:43 +02:00
model-conversion server: use port 9931 by default (#30159) 2026-10-09 10:40:03 +02:00
parallel batch: migrate the rest of examples to llama_batch_ext (#29601) 2026-09-30 18:08:43 +02:00
passkey batch: migrate the rest of examples to llama_batch_ext (#29601) 2026-09-30 18:08:43 +02:00
retrieval batch: migrate the rest of examples to llama_batch_ext (#29601) 2026-09-30 18:08:43 +02:00
simple batch: migrate the rest of examples to llama_batch_ext (#29601) 2026-09-30 18:08:43 +02:00
simple-chat batch: migrate the rest of examples to llama_batch_ext (#29601) 2026-09-30 18:08:43 +02:00
simple-cmake-pkg cmake : allow repeated find_package calls for llama (#29228) 2026-09-22 13:58:42 +02:00
speculative examples : fix draft sampling and rejection handling (#30095) 2026-10-12 12:02:24 +02:00
speculative-simple server : preserve context checkpoints across slot save/restore (#26004) 2026-10-08 13:18:20 +03:00
sycl [SYCL] Enable ssl in build script and CI (#30456) 2026-10-15 21:58:07 -04:00
test-cmake cmake : use PROJECT_SOURCE_DIR instead of CMAKE_SOURCE_DIR (#28771) 2026-09-15 05:26:09 +02:00
training finetune: fix no KV cache (#27199) 2026-09-02 23:53:32 +02:00
CMakeLists.txt tests : move save-load-state from examples to tests (#23336) 2026-05-21 14:41:50 +03:00
convert_legacy_llama.py convert : minor fixes for numpy 2.x (#23571) 2026-05-24 09:51:31 +02:00
json_schema_pydantic_example.py server: use port 9931 by default (#30159) 2026-10-09 10:40:03 +02:00
llama.vim chore : correct typos [no ci] (#20041) 2026-03-05 08:50:21 +01:00
pydantic_models_to_grammar.py ci : bump ty to 0.0.78 (#28548) 2026-09-07 21:10:06 +02:00
pydantic_models_to_grammar_examples.py server: use port 9931 by default (#30159) 2026-10-09 10:40:03 +02:00
reason-act.sh scripts : make the shell scripts cross-platform (#14341) 2025-06-30 10:17:18 +02:00
server-llama2-13B.sh scripts : make the shell scripts cross-platform (#14341) 2025-06-30 10:17:18 +02:00
server_embd.py llama : fix FA when KV cache is not used (i.e. embeddings) (#12825) 2025-04-08 19:54:51 +03:00