Integrations
Hand FOCUS collections to a trainer. Every integration asks for the same thing: a CollectorFor that builds the collector for one Problem under the trainer’s current policy, plus a critic sink. focus.integrations.tinker supplies a loop you run; focus.integrations.slime supplies hooks Slime calls.
CollectorFor
Section titled “CollectorFor”What every trainer integration asks of you: a function from the trainer’s current policy and one Problem to the Collector that should collect it. The Tinker and Slime integrations take the same function.
Build a fresh environment per problem so concurrent problems never share a reference answer. The integration uses each collector once inside async with, so the collector’s own setting decides whether its execution services close afterwards; policies and critics stay with their owner.
Definition
CriticSink
Section titled “CriticSink”Where critic records go. Neither trainer trains the critic, so each collection’s critic records are handed to this callable; your value-model loop reads them back.
Definition
JsonlDirectory
Section titled “JsonlDirectory”A critic sink that writes each collection’s critic records to its own JSONL file in a directory. One file per call, so concurrent collectors and worker processes never interleave lines; a collection without critic records writes nothing.
Pass it as critic_sink= to the Tinker loop or the Slime generate hook. Each line is one checkpoint context and its direct-branch backup target.
Definition
JsonlDirectory.init
Section titled “JsonlDirectory.init”JsonlDirectory.call
Section titled “JsonlDirectory.call”Problem
Section titled “Problem”One training item: the prompt the policy sees, a label that stays out of the prompt (typically a reference answer the environment grades against), an id recorded in exported metadata, and free-form metadata. Both trainer integrations hand problems to your CollectorFor.
The Tinker loop takes a list of problems; the Slime hooks build one from each Slime sample, with prompt and label filled by Slime’s --input-key and --label-key.
Definition
Fields
collect_records
Section titled “collect_records”Collect one problem with one collector and return its (actor, critic) records. Both integrations call this; use it directly for a trainer FOCUS does not integrate yet. A collection with failed expansions or critic predictions raises unless allow_partial=True.
Definition
GenerateHook
Section titled “GenerateHook”The signature Slime calls a custom generate function with: (args, sample, sampling_params), returning the samples to train on. sampling_params is accepted but does not override FOCUS’s sampling settings.
Definition
GenerateHook.call
Section titled “GenerateHook.call”advantages
Section titled “advantages”Advantage hook: broadcast each segment’s FOCUS advantage over its response tokens, overriding the estimator Slime’s argument parser selected. Refuses advantage normalization; returns are zero because critic targets are exported separately. Name it with --custom-advantage-function-path focus.integrations.slime.advantages.
Definition
make_evaluate
Section titled “make_evaluate”Build Slime’s evaluation generate function from the same CollectorFor: one unbranched rollout of the collector’s agent, returned as a Slime sample whose reward is the outcome rather than a signed advantage.
Definition
make_generate
Section titled “make_generate”Build Slime’s custom generate function from your CollectorFor. For each sample it builds the router’s policy, wraps the sample as a Problem, collects one tree with a fresh collector, sends critic records to critic_sink, and returns the actor segments as Slime samples.
Point --custom-generate-function-path at the module attribute holding generate. One collector per sample keeps concurrent prompts’ reference answers apart. workspace_for gives each prompt its own workspace, min_abs_advantage drops near-zero actor edges after search, and allow_partial=True keeps a collection with failures.
Definition
preserve_advantages
Section titled “preserve_advantages”Reward post-process hook: return the FOCUS advantages unchanged, so Slime’s group centering does not alter them. Name it with --custom-reward-post-process-path focus.integrations.slime.preserve_advantages.
Definition
sum_policy_tokens
Section titled “sum_policy_tokens”Policy-loss reducer hook: sum masked token losses instead of averaging them, so each generated token contributes its segment’s advantage once. Requires context parallel size 1. Name it with --custom-pg-loss-reducer-function-path focus.integrations.slime.sum_policy_tokens.
Definition
to_sample
Section titled “to_sample”Turn one actor record into a response-aligned Slime sample. The response starts at the first generated token; conditioning tokens inside it, such as tool results, keep loss mask zero. reward carries the FOCUS advantage, and every segment of one tree shares the source prompt’s rollout_id.
Definition
PPO_CLIP
Section titled “PPO_CLIP”Tinker’s PPO loss configuration for the paper’s ratio clip, .
Definition
StepReport
Section titled “StepReport”What one actor update trained on: the batch index, the behavior step its sampler came from, the learner step, the policy lag between them, and Tinker’s metrics.
Definition
Fields
to_datum
Section titled “to_datum”Turn one actor record into a Tinker Datum: the model input is tokens[:-1], and targets, behavior log probabilities, and advantages are read one position later. Conditioning tokens get advantage zero.
Definition
Run the one-step asynchronous Tinker loop: collect one problem per update from a frozen sampler, train on it, and publish a new sampler, overlapping the next collection with the current update.
With async_depth=1 (the default) each batch is at most one update behind the learner and every batch trains exactly once; async_depth=0 publishes a fresh sampler before each collection. profile resolves the sampler’s format as for TinkerPolicy. Critic records reach the sink with their learner step, and on_step receives one StepReport per update. An outstanding collection is cancelled and joined if the loop stops early.
Definition
update_actor
Section titled “update_actor”Take one Tinker optimizer step on a batch’s actor lane. Gradients are awaited before the optimizer step is submitted, and the optimizer result before returning, so a sampler published afterwards holds the updated weights. The default loss is ppo with ratio clip .
Definition