﻿# lm-eval likelihood adapters: preserve the context–continuation token boundary

Check context and continuation encoding, shifted logits and empty-context behavior before trusting likelihood scores from a custom lm-eval backend.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-lm-eval-continuation-token-boundary-likelihood/
Language: en

## Begin with the scored event

A custom inference backend can produce sensible text while returning incorrect benchmark likelihoods. Generation and conditional scoring exercise different interfaces. The [model guide](https://github.com/EleutherAI/lm-evaluation-harness/blob/main/docs/model_guide.md) defines a likelihood request using context and continuation, with the probability assigned to the continuation under that context. Before comparing GPUs or quantization formats, establish exactly which tokens contribute to this score; otherwise an adapter defect can resemble a model-quality regression.

## Preserve tokenization across the join

Encoding the context and continuation independently is not generally equivalent to encoding their concatenation for a causal model. Whitespace and subword boundaries can change the resulting token sequence. The [shared model implementation](https://github.com/EleutherAI/lm-evaluation-harness/blob/main/lm_eval/api/model.py) handles this boundary and moves trailing context spaces into the continuation before encoding. Follow the relevant backend contract rather than assuming that a character split always maps cleanly to a token split.

## Align predictions with their targets

Causal model logits at an input position predict the following token. A continuation score must therefore align the selected logits with the actual continuation token IDs, excluding context-only terms and unintended padding. The model guide illustrates this shift. Audit a short example where each scored token and its selected probability can be inspected. A plausible aggregate negative number is a weak diagnostic because several indexing mistakes still produce values in an apparently reasonable range.

## Make empty context and formatting explicit

An empty context needs the backend's declared prefix or end-of-text handling rather than an accidental empty tensor. Chat formatting adds another boundary: the [delimiter update](https://github.com/EleutherAI/lm-evaluation-harness/blob/main/docs/chat-template-readme.md) documents how an applied template changes target delimiter handling. Test base and chat configurations separately. Correctness for a plain completion does not automatically establish correctness when assistant markers, special tokens and template-provided spacing are involved in the scored sequence.

## Validate before measuring scale

Compare the adapter with a trusted implementation on short, inspectable cases containing leading whitespace, an empty context and a continuation spanning multiple tokens. Then test batched padding without changing the intended scores. The guides to [task configuration identity](/journal/data-guide-lm-eval-task-config-revisions/) and [request versus response caching](/journal/fg2-lm-eval-request-response-cache-experiment-identity/) provide surrounding controls. Treat successful token alignment as a prerequisite for throughput experiments, preserving the difference between a backend that generates text and one that implements the benchmark's probability measurement correctly.
