KatInterview

Designing an Evaluation Framework for Local Language Models

System DesignModel answer
MediumModel answerSystem Designsystem designmachine learningpython

Last updated

Design and implement a robust, extensible evaluation harness for local LLM endpoints with metrics, concurrency control, and fault tolerance.

Engineers and researchers frequently need to evaluate language model performance on custom offline datasets. Relying on cloud APIs can become expensive and introduce external privacy concerns, leading many teams to serve models locally (e.g., via Ollama, vLLM, or TGI).

Design and implement a lightweight, production-grade evaluation harness capable of testing a locally served language model.

Requirements

  1. Data Ingestion & Processing: Read test cases containing at least an id, a prompt, and an optional reference_answer.
  2. Execution & Metadata Capture: Execute prompts against a local inference endpoint (such as Ollama). Record status (ok or error), response content, latency, retry counts, token usage, and system configuration.
  3. Metrics & Aggregation: Compute standard system and accuracy metrics, such as exact match rate, overall pass rate, response latency percentiles ($P_{50}$, $P_{95}$), and infra error rates.
  4. Reliability & Resilience: Handle hardware timeouts, transient server failures, and out-of-memory events gracefully using retries with backoff, concurrency limits, and stateful checkpointing/resumability.
  5. Extensibility: Architect the solution cleanly so that alternative inference backends (e.g., OpenAI, vLLM) and custom metric evaluation functions (e.g., regex extraction, BLEU, LLM-as-judge) can be swapped in with minimal code changes.

Explain your architecture, metric definitions, concurrency trade-offs, and failure mitigation strategies. Provide a runnable Python implementation illustrating the core runner, backend abstraction, and scoring mechanism.

Hints

Hint 1

Distinguish clearly between infrastructure error rate, accuracy on valid responses (Exact Match), and total end-to-end task success (Pass Rate).

Hint 2

Consider how local server parallel settings (like OLLAMA_NUM_PARALLEL) interact with client-side concurrency controls.

Hint 3

Ensure the evaluation harness persists state per-example to enable resuming an evaluation run after an unexpected crash or system reset.