Basic LM Evaluation Harness Example
The LM Evaluation Harness from EleutherAI is a widely used
framework for benchmarking language models against academic tasks.
The Workflow below runs a small slice of the gsm8k math benchmark against an OpenAI model through the
harness's API model interface, uploads the results as artifacts and exports the scores as metrics.
You can paste this directly into the YAML of an existing or new Workflow, just make sure to update the
name and namespace for your environment if needed.
- The
spec.configproperty defines two configuration parameters:model, the OpenAI model to benchmark, andlimit, the number of benchmark samples to run. The default of 5 keeps the example fast and inexpensive; raise it for a more meaningful score. - The
spec.content.filesproperty defines an inlinerequirements.txtwith the harness and its API support. - The
spec.containerproperty defines the working directory, Python image, and environment variables for the Workflow; theOPENAI_API_KEYis resolved using the credential expression so the key is never stored in the Workflow definition itself. - The Install and run lm-eval step installs the harness and runs the
gsm8ktask. Itscacheblock keeps the pip download cache between executions, so later runs install the packages from the cache instead of downloading them again; see Dependency Caching. - The Export metrics step runs the
testkube-ai-metrics-parserimage, which converts the harness results into ametrics.lpfile with one series per task, tagged with the model. - The Save results step uploads the JSON result files and the metrics file as artifacts; the
alwayscondition makes sure they are uploaded even if the benchmark fails.
kind: TestWorkflow
apiVersion: testworkflows.testkube.io/v1
metadata:
name: lm-eval-harness-getting-started
namespace: testkube
labels:
docs: example
type: ai
spec:
config:
model:
type: string
default: gpt-4o-mini
limit:
type: integer
default: 5
content:
files:
- path: /data/requirements.txt
content: |
lm-eval[api]
container:
workingDir: /data
image: python:3.12-slim
env:
- name: HOME
value: /data
- name: PIP_CACHE_DIR
value: /root/.cache/pip
- name: HF_HOME
value: /data/hf
- name: HF_HUB_DISABLE_TELEMETRY
value: "1"
- name: OPENAI_API_KEY
value: '{{credential("OPENAI_API_KEY")}}'
resources:
requests:
cpu: "1"
memory: 2Gi
steps:
- name: Install and run lm-eval
cache:
key: 'pip-{{ hash_files("requirements.txt") }}'
restoreKeys:
- "pip-"
paths:
- /root/.cache/pip
shell: |
set -e
pip install -r requirements.txt
lm_eval --model local-chat-completions \
--model_args model={{config.model}},base_url=https://api.openai.com/v1/chat/completions,num_concurrent=1 \
--tasks gsm8k \
--apply_chat_template \
--num_fewshot 0 \
--limit {{config.limit}} \
--output_path ./results
- name: Export metrics
condition: always
container:
image: docker.io/kubeshop/testkube-ai-metrics-parser:latest
shell: testkube-ai-metrics-parser lm-eval -i 'results/**/*.json' -o results/metrics.lp --tag model={{config.model}} --stdout
- name: Save results
condition: always
artifacts:
paths:
- results/**/*.json
- results/metrics.lp
After execution, the benchmark scores are shown in the Log Output tab, and the result files are available
under the Artifacts tab of the execution. Testkube ingests the metrics.lp file as
custom metrics under the lm_eval measurement, so you can follow the
benchmark scores of each model across executions in Insights.