ollama-test.py is a benchmark harness for local Ollama models. It runs each installed model against a task definition, captures the model output, retries failed generations with error feedback, and writes benchmark results plus optional Chrome/Perfetto trace data.
For each model returned by GET /api/tags on your Ollama server, the script:
- Sends the task prompt to
POST /api/chat. - Extracts the first fenced code block from the response.
- Optionally compiles and runs the generated code.
- Validates the program output against declarative rules from the task JSON.
- Retries up to 6 times if compilation or validation fails, feeding the previous error back to the model.
- Records runtime metrics, token usage, compile attempts, and hardware telemetry.
The harness also polls GPU temperature and power from nvidia-smi-webserver on the same host as Ollama.
- Ollama running locally and reachable through
OLLAMA_HOSTorhttp://localhost:11434 - Local models installed in Ollama
nvidia-smi-webserverfrom https://github.com/thematthew/nvidia-smi-webserver if you want to log GPU thermals and power- Python dependencies from this repo
Run the harness with the default task:
python3 ollama-test.pyUseful options:
python3 ollama-test.py --task tasks/rule90/rule90_c.json
python3 ollama-test.py --output results.json
python3 ollama-test.py --chrome-trace
python3 ollama-test.py --telemetry-interval 3Environment:
OLLAMA_HOSTsets the Ollama base URL.- The GPU telemetry endpoint is derived from
OLLAMA_HOSTand uses port28123.
ollama-test.py is task-driven. A task config defines:
- the prompt shown to the model
- the target language
- the source file extension to write
- optional build and run commands
- validation rules for program output
Tasks can either embed the prompt directly or point at a separate prompt file. This keeps the harness generic: changing the benchmark usually means adding or editing a task JSON, not modifying the script.
The script writes benchmark data to:
ollama_benchmark_results.jsonby defaultollama_benchmark_trace.jsonwhen--chrome-traceis enabled./output/YYYY-MM-DD/<model>/chat_history.jsonfor each model run
The results JSON includes per-model status, token counts, compile attempts, execution time, and captured output. The Chrome trace can be opened in chrome://tracing, Eclipse Trace Compass (with incubator) or Perfetto.
- Models are benchmarked in mostly paramater size order.
- The script unloads the previous model between runs with
ollama delete <model>. - If you run multiple task configs in one invocation, output files are suffixed with the task name to avoid overwriting.