Evaluate with Inspect
Run an eval on a Base model with Inspect, the UK AI Security Institute's framework for evals. Its provider openai-api-completions sends each sample's input as a raw prompt to POST /v1/completions, with no chat template. You need the two shell variables of the Quickstart. The commands on this page work with inspect-ai 0.3.286 and the openai SDK 3.41.0.
Point Inspect at the API
-
Install Inspect and the
openaiSDK:pip install inspect-ai openai -
Give Inspect the API's address. For a service named
acs, Inspect reads the key fromACS_API_KEY, which the Quickstart sets, and the address fromACS_BASE_URL:export ACS_BASE_URL="$ACS_API_BASE" -
Name the model as
openai-api-completions/acs/and the model's full id, such asopenai-api-completions/acs/llama-8b. Inspect takesacs/off and sends the rest asmodel. List the models gives each id.
Run a task
-
Download
capitals.py, or save this task ascapitals.py. Each sample is a prompt with two examples, which a Base model continues.includes()scores a sample 1 when the model's text contains its target:from inspect_ai import Task, task from inspect_ai.dataset import Sample from inspect_ai.scorer import includes from inspect_ai.solver import generate EXAMPLES = "The capital of Italy is Rome.\nThe capital of Japan is Tokyo.\n" @task def capitals(): return Task( dataset=[ Sample(input=EXAMPLES + "The capital of France is", target="Paris"), Sample(input=EXAMPLES + "The capital of Argentina is", target="Buenos Aires"), Sample(input=EXAMPLES + "The capital of Canada is", target="Ottawa"), ], solver=generate(), scorer=includes(), ) -
Run the eval on Llama 3.1 8B at temperature 0, with up to 4 tokens for each answer:
inspect eval capitals.py --model openai-api-completions/acs/llama-8b --temperature 0 --max-tokens 4Inspect prints the task's accuracy, and writes the log of the eval to
./logs.inspect viewshows the logs, with each sample's input and the model's text.
Always set --max-tokens. Without it, the provider asks for 1 token, and an answer such as Buenos Aires takes two.
Write prompts for a Base model
A Base model continues text, and it does not answer a question as a chat model does (What a Base model does). Write each input as the start of a text whose next words are the answer, as the examples in capitals.py do.
The provider sends one text. A sample's input must be a string or one user message. An input of several messages, or --system-message, stops the eval with a TypeError.
Set the request fields
The provider sends model, prompt, max_tokens, and temperature with each request. It sends max_tokens: 1 without --max-tokens, and temperature: 0 without --temperature. These options of inspect eval set the other fields:
| Option | Field |
|---|---|
--top-p | top_p |
--seed | seed |
--stop-seqs | stop |
--num-choices | n |
--logprobs, and --top-logprobs for more than 1 | logprobs |
--frequency-penalty and --presence-penalty | frequency_penalty and presence_penalty |
--prompt-logprobs | prompt_logprobs |
--extra-body | Each field of its JSON, such as '{"top_k": 5}' |
- The scorers read the first choice only, so
--num-choicesadds texts to the log and not to the score. --top-k,--best-of, and--logit-biassend nothing, and neither does--top-logprobswithout--logprobs. Sendtop_kin--extra-body.- The provider sends no request with a stream. So
max_tokensmust stay within the limit of a request without a stream (Tokens). - The API refuses a field that it does not know, such as vLLM's
return_token_ids, with 400invalid_request(Strict validation).
Run a large eval
- Set
--max-connections 16, the number of Completions that run at once for each API key (Traffic). Without it, Inspect opens 20 connections at first and up to 100. Past the key's line, the API answers 429rate_limited. - Set
--max-retries, such as--max-retries 3. Inspect tries each 429 again with no end. That includesbudget_exceededat the end of your tokens andspend_cap, which the API sends withx-should-retry: false. - Run the eval on a Warm model. The first request to a cold model waits for its start. A start of Llama 3.1 405B or Trinity Large takes longer than the API waits for Inference (Warm and cold models). Check whether a model is Warm shows the status route.
inspect eval capitals.py --model openai-api-completions/acs/llama-8b --temperature 0 --max-tokens 4 --max-connections 16 --max-retries 3If the eval fails
| Inspect says | Cause | What to do |
|---|---|---|
No ACS_BASE_URL defined in the environment. | Inspect reads ACS_BASE_URL, not ACS_API_BASE. | Export ACS_BASE_URL, as Point Inspect at the API shows. |
Server at <url> does not support /v1/completions. | Inspect says this for any 404, such as a wrong ACS_BASE_URL. | Check that ACS_BASE_URL ends in /v1. |
Error code: 400 - {'error': {'message': 'The model ... with model_not_found | The API does not serve the model. | Check the model's id in GET /v1/models. |
ValidationError: 1 validation error for ModelOutput | After 150 seconds, a request without a stream gets its 200, and a later error comes as the body. Inspect cannot read that body (Requests without a stream). A cold model's start can cause it. | Check that the model is Warm, then run the eval again. |
This API serves Base models, which have no chat format | The provider openai-api sends chat requests to /v1/chat/completions. | Use openai-api-completions. |
Next steps
Score a text gets the log-likelihood of a text, which an eval with several choices can compare. Run a Job sends many requests in the background. Limits lists each limit that an eval can meet.