Skip to content

Critic

Predict the remaining return from a checkpoint. The search uses these predictions to choose where to continue, and preparation exports the observed backups as the critic’s training targets.

Predict the remaining return from each checkpoint context. Selective search uses these predictions to choose continuations; preparation pairs scored contexts with backup targets for critic training.

from focus import Critic

critic = Critic.from_fn(
    lambda contexts: [0.5 for _ in contexts],
    timeout=30.0,
)

from_fn wraps a synchronous or asynchronous batch function; constant(v) predicts v everywhere. Pass context= to either factory to choose how a rollout becomes input text. The default is a transcript with role labels. The exact text sent for prediction is also saved in critic training records. To implement a backend, subclass Critic and define predict(); override context() for custom rendering. A prediction batch that exceeds timeout counts as a scoring failure.

Definition

class Critic(ABC)

Fields

timeout: float | None = None
render: Callable[[AnyRollout], str] | None = None

Required implementation.

@abstractmethod
async def predict(self, contexts: Sequence[str]) -> Sequence[float]

Return one predicted remaining return for each context, in order.

def context(self, rollout: AnyRollout) -> str

Render a checkpoint as the critic’s input text. The default renders the conversation; the same text becomes the critic training record’s context.

async def aclose(self) -> None

Release resources the critic owns. The default does nothing.

@staticmethod
def constant(value: float, *, context: Callable[[AnyRollout], str] | None=None, timeout: float | None=None) -> Critic

A critic that predicts value everywhere: the starting point before a value model is trained.

@staticmethod
def from_fn(fn: PredictFn, *, context: Callable[[AnyRollout], str] | None=None, timeout: float | None=None) -> Critic

Wrap a function from a batch of contexts to a batch of predictions. The function may be synchronous or asynchronous.

A batch prediction function for Critic.from_fn: contexts in, one predicted return per context out, synchronously or as an awaitable.

from focus.critic import PredictFn

Definition

type PredictFn = Callable[[Sequence[str]], Sequence[float] | Awaitable[Sequence[float]]]

A value model served by vLLM as a pooling model. Each context is sent to the server’s pooling endpoint and reduced to one predicted return.

from focus.backends import VLLMCritic

critic = VLLMCritic(
    base_url="http://127.0.0.1:8001",
    model="focus-critic",
    reduce="last",
)

reduce chooses how per-token outputs become one value: the last token (default), the first, their sum, or their mean. timeout bounds one prediction batch for the search. Close the critic when training ends.

Definition

class VLLMCritic(Critic)
def __init__(self, *, base_url: str, model: str, api_key: str='EMPTY', reduce: str='last', http_timeout: float=60.0, timeout: float | None=None, context: Callable[[AnyRollout], str] | None=None, client: Any=None) -> None
async def predict(self, contexts: Sequence[str]) -> list[float]

Send the contexts to the pooling endpoint and return one value per context.

async def aclose(self) -> None

Close the HTTP client the critic created.