Evaluator

Compare a base NIM with the LoRA fine-tune on a held-out question set, and record both scores with NeMo Evaluator.

Updated CompTech Team

A fine-tune that sounds better in one chat session can be worse on the questions you actually care about, and it can be worse at everything else. Evaluation is the same question set, sent to both models, with the result written down next to the model names.

This lab scores the base model and the company-policy@v1 adapter from Customizer on the held-out file from Curator. NeMo Evaluator is where that run is stored, so the next training job can be compared with this one rather than with a memory of it.

Prerequisites

  • Two OpenAI-compatible endpoints: the base NIM, and the fine-tuned NIM or the base NIM with the LoRA adapter loaded
  • valid.jsonl, which was not part of training
  • NeMo Evaluator reachable at EVALUATOR_BASE_URL if you want the run stored as a job

valid.jsonl uses the same messages shape as training. Add the fact you expect the answer to contain, so a person and a script can agree on what "right" means:

{"messages": [
  {"role": "user", "content": "How do I reset my password?"},
  {"role": "assistant", "content": "Request the reset in the IT portal."}
], "expect": ["IT portal", "employee id"]}

Ask both models the same questions

score.py calls each endpoint, checks whether every expected phrase is in the reply, and writes a row per question. It does not call an LLM to judge. A phrase check is blunt and repeatable. Add a judge only after this number is stable.

import json, os, urllib.request
ENDPOINTS = {
    "base": os.environ["BASE_URL"],
    "tuned": os.environ["TUNED_URL"],
}
MODELS = {"base": os.environ["BASE_MODEL"], "tuned": "company-policy@v1"}

def chat(url, model, question):
    body = json.dumps({"model": model, "messages": [{"role": "user", "content": question}]}).encode()
    req = urllib.request.Request(url + "/v1/chat/completions", data=body, headers={"Content-Type": "application/json"})
    with urllib.request.urlopen(req, timeout=120) as resp:
        return json.load(resp)["choices"][0]["message"]["content"]

hits = {name: 0 for name in ENDPOINTS}
rows = list(open("valid.jsonl"))
for line in rows:
    row = json.loads(line)
    question = row["messages"][0]["content"]
    for name, url in ENDPOINTS.items():
        answer = chat(url, MODELS[name], question)
        ok = all(phrase.lower() in answer.lower() for phrase in row["expect"])
        hits[name] += int(ok)
        print(f"{name}\t{ok}\t{question}")
n = len(rows)
for name, count in hits.items():
    print(f"{name} {count}/{n}")
BASE_URL=http://llama-nim:8000 BASE_MODEL=meta/llama-3.1-8b-instruct \
TUNED_URL=http://company-policy-nim:8000 python3 score.py

Record the two count/n lines the script prints, with the date, the dataset file name and the Customizer output_model. Do not round two runs from different question sets into one story. If you change a prompt, that is a new run.

Catch forgetting

The policy score can rise while the model gets worse at general questions. Run one general task you did not train on, against both endpoints, and keep that number too. A short set of ordinary instruction-following questions is enough in the lab. NeMo Evaluator runs the standard academic tasks when you need a result someone else can reproduce.

A custom evaluation job names the model and the task and stays attached to that model version:

curl -s -X POST "$EVALUATOR_BASE_URL/v1/evaluation/jobs" \
  -H 'Content-Type: application/json' \
  -d '{
    "namespace": "default",
    "target": {"type": "model", "model": "company-policy@v1"},
    "config": {"type": "custom", "tasks": {"policy": {"type": "chat-completion"}}}
  }'

Read the job back when its status is completed and keep the result payload with the phrase-check output. The academic task and the company task answer different questions. Ship only when you have looked at both.

How to read a bad score

What you see What to check first
Tuned and base scores match The adapter is not loaded. The model field is still the base name
Tuned score is worse on the policy set Too few examples, the wrong answer text, or epochs high enough to overfit noise
Policy score is up, general score is down The adapter is too large or trained too long. Try a smaller adapter_dim
Both fail the same questions The expected phrase is not in the source policy. Fix the data, not the model
Answers are fluent and wrong The fact was never in training. It belongs in Retriever, not in a larger LoRA

Re-run Curator and Customizer from the same files if you change the data. An evaluation of a model whose training file you no longer have is a number you cannot act on.

What's next

  1. If the policy score did not move, the data is still the first place to look, in Curator.
  2. If it did, put the endpoint behind Guardrails before it faces users.
  3. Questions the model should answer from documents, not from weights, go through Retriever.