Repository navigation
[rl] Rollout turns as a tree: a turn's prompt is a delta on any earlier turn - #5303
Draft
felipemello1 wants to merge 1 commit into
Draft
felipemello1 wants to merge 1 commit into
felipemello1 wants to merge 1 commit into
Conversation
…er turn A RolloutTurn names its parent (parent_turn_id: any earlier turn, or None for a root) and stores only what its prompt adds to the parent's prompt + completion. Prompt messages become deltas the same way (prompt_message_prefix_len + prompt_delta_messages), so the recorder no longer repeats the whole conversation on every turn. Forks from older turns, resamples and interleaved subagents can store only their new tokens. - TokenEnv returns the message prefix next to the token split; its messages only grow, so the message delta is empty. RolloutWorker sets parent = the previous turn. - The builder extends a turn's parent sample when the prompt holds the parent's whole prompt + completion and the parent is still that sample's last turn. Otherwise it opens a sample with the parent's first prompt_prefix_len tokens as untrained context. Samples stay open until the rollout ends, so a turn can resume an earlier one. For the default Rollouter, packed batches are bitwise unchanged. - Verifiers: a turn's parent is the last turn before it on its branch, so a branch that resumes a turn continues that turn's sample. Turns still record only env replies. - Recorder: prompt_messages becomes parent_turn_id + prompt_message_prefix_len + prompt_delta_messages; _encode_turn documents the rebuild rule. - test_metrics: its RolloutTurn fixture still used the removed prompt_token_ids.
This was referenced Dec 1, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR: A
RolloutTurnnames its parent, any earlier turn, and stores its prompt (tokens and now messages) as a delta on it. Today this shrinks the recorded rollouts: one 30-turn rollout'srollout_samples.jsonlline drops from 3.38 MB to 0.22 MB, because prompt messages stop repeating the whole conversation. Forks (retries, resamples, subagents) store only their new tokens. No rollouter on main forks yet, so that part is headroom. The default Rollouter's packed batches are bitwise unchanged.Problem
Rollout.turns; itsprompt_messagesare stored in full.prompt_messagesrepeats the conversation on every turn: 3.38 MB for one 30-turn rollout's recorder line.Solution
RolloutTurn.parent_turn_id: any earlier turn, orNonefor a root. The prompt is the parent's firstprompt_prefix_lentokens of prompt + completion, thenprompt_delta_token_ids.prompt_message_prefix_len+prompt_delta_messages, measured against the parent's prompt messages + completion + env reply.TokenEnvreturns the prefix next to the token split.GenerateFn,TrainingSample, the batcher, rubrics and metrics.Results
Correctness:
TokenEnv+RolloutWorker, 618 rollouts including 18 edge cases): every turn, rollout metric, training sample and packed microbatch tensor is identical to main.You may ask:
parent_turn_idrequired? A default ofNonewould silently make every turn a root: one sample per turn and quadratic trainer compute.NOTE:
rollout_samples.jsonlkeys change:prompt_messagesbecomesparent_turn_id+prompt_message_prefix_len+prompt_delta_messages.RolloutSampleRecorder._encode_turndocuments how to rebuild a turn's full conversation and tokens.test_metrics.py'sRolloutTurnfixture, which still used the removedprompt_token_idsand fails on main today.Follow up
RolloutTurnand the builder.trace_to_rollout_turns).Test plan
New tests:
test_rollout_utils.py: fork from an older turn, fork from the middle of a sample, resample + branch inside a completion, interleaved subagent turns, a parent that is not an earlier turn.test_verifiers.py: the Terminus-2 fork shape (a new root), a resumed turn continuing its sample.test_rollout_worker.py: parent = the previous turn, and prompt messages rebuild from their deltas through the realTokenEnv.The correctness numbers above come from scripts outside the repo: the same seeded rollouts and traces run on main and on this branch, compared field by field (floats as bits), plus an independent check that every completion trains once after its full prompt with its own logprob.