Understand the Trajectory Collector#
Use this page to trace embodied rollout data from one action chunk to the Actor-facing training batch. Focus on the fields your algorithm produces and consumes; the Collector owns routing, matching, and completion state.
Core Model#
One action chunk is split into two independently produced parts:
Part |
Owner |
Core Data |
|---|---|---|
|
Policy inference |
Observation, action, log-probability, value, model version, and retained forward inputs. |
|
Environment interaction |
Reward, termination state, intervention result, and optional boundary observation or compact RLT features. |
Both parts carry the same TrajectoryKey:
(step_id, epoch_id, env_rank, stage_id, chunk_id)
The key identifies the chunk. TrajectorySource adds batch size and offset
when routing splits or merges a source batch.
The Actor Channel sees this flow:
PolicyPart -----------+
|
v
join by key
|
v
EnvPart --------------+----> accumulate ----> flush ----> Actor output
The Environment does not write the Actor Channel directly. It attaches an
EnvPart to the next PolicyInput. Rollout adds optional terminal
inference data and publishes that same EnvPart so the Actor Channel has one
producer and one ordering boundary.
Complete One Action Chunk#
Follow one normal inferred chunk:
Env sends
PolicyInputwith the current observation and a newTrajectoryKey.Rollout runs policy inference, returns the action tensor to Env, and immediately publishes a
PolicyPartcontaining the fullPolicyOutputto the Actor Channel.Env executes the action chunk and records rewards, boundary flags, the post-action observation, and intervention data.
Env stores that
EnvTransitioninEnvPart. The accompanyingPolicyInput.obsnormally carries the same post-action observation, soEnvPart.next_obsis set only when a terminal or decoupled boundary needs an explicit override. Chunk zero also carriesinitial_transition.Rollout resolves the effective next observation from the request or its override and completes the
EnvPart. When requested, it runs terminal inference and adds the final value. RLT keeps only the next-state features required by the algorithm, not the complete next forward-input dictionary.ChunkJoinermatches both parts by key. Arrival order does not matter.TrajectoryCollectorpasses the joined chunk to the output strategy selected byTrajectoryPlan.
The temporal meaning is:
initial_transition EnvPart.transition
| |
v v
state_t ---- PolicyPart.action ----> state_t+1
Only chunk zero owns initial_transition. This keeps boundary sequences
aligned without a separate start event.
From Chunks to Actor Output#
The Collector performs three core operations.
Join#
ChunkJoiner restores routed source fragments and stores policy and
environment parts until both sides of a key are present. A joined chunk contains
one source id, one PolicyPart, and one EnvPart.
Accumulate#
TrajectoryStep.from_parts converts each joined pair into one complete
training step. The embodied data types own reward composition, intervention
updates, transition extraction, and CPU conversion. TrajectoryAccumulator
only retains these complete steps in rollout order.
Trajectory.from_steps later materializes the temporal layout. Action-owned
fields normally have one entry per chunk. Boundary fields include the state
before the first action, and value fields may include the final bootstrap value:
actions: [a0, a1, ...]
rewards: [r0, r1, ...]
dones: [d_before, d0, d1, ...]
prev_values: [V(s0), V(s1), ..., V(s_final)]
This separation keeps field-specific behavior next to EnvTransition,
TrajectoryStep, and Trajectory instead of embedding it in Collector or
accumulator control flow.
Flush#
An output strategy defines the smallest completion scope that can be emitted. After a scope completes, it materializes contiguous tensors, removes its accumulator state, and returns queue-ready items.
Output Modes#
Mode |
Completion Scope |
Actor Output |
|---|---|---|
|
One training step for one logical source |
|
|
One |
Preprocessed, advantage-ready micro-batches keyed to Actor ranks. |
|
One training step for one logical source |
Completed episode shards. In-progress episode state persists across training steps. |
Synchronous, asynchronous, and decoupled runners use the same two parts and the same Collector. Their service loops differ, but the chunk data contract does not.
What Algorithm Developers Need to Own#
Start from the training tensor your algorithm needs, then follow its ownership path.
Algorithm Need |
Produce It In |
Data-Type Path |
|---|---|---|
Policy statistic such as log-probability or value |
|
Resolve it in |
Environment or reward-model signal |
|
Combine sources in |
Current and next observation |
|
Rollout resolves the effective next observation before publishing
|
Executed intervention action |
|
Apply it through |
RLT transition feature |
|
Rollout extracts only |
Pipeline training target |
Algorithm advantage/loss configuration |
Compute advantages and returns before Actor-specific micro-batch packing. |
For a new algorithm, check these five points:
Add the field to
PolicyOutputorEnvTransitionaccording to who owns it.Populate it in Rollout or Env and update that type’s
split/mergemethods when the field follows the batch dimension.Resolve cross-part semantics in
TrajectoryStep.from_parts.Materialize temporal fields in
Trajectory.from_stepsor the mode-specific Actor output.Keep pipeline preprocessing aligned with the non-pipeline Actor path.
Most algorithms do not need to change TrajectoryKey, TrajectorySource,
fragment restoration, dispatcher selection, or completion scopes. Change those
only when the algorithm changes data ownership or when a batch is allowed to
flush.
Minimal End-to-End Flow#
With one Env source, one chunk, one rollout epoch, and one Actor:
Bootstrap produces the pre-action observation and boundary state.
Rollout publishes one
PolicyPartand sends its action to Env.Env executes the action and attaches one
EnvPartto the next request.Rollout completes and publishes that
EnvPartwith the same key.The Joiner creates one complete chunk.
TrajectoryStepresolves the pair; the Accumulator retains that complete step without inspecting its fields.The rollout scope is complete, so the Collector emits one
Trajectoryon the default queue key.Actor converts the received trajectory into a training batch, then computes advantages and returns in the non-pipeline path.
With more chunks, steps 2–6 repeat before flush. With more independent sources, rollout mode may flush each source as soon as it completes. Pipeline mode waits for every source in the epoch because routing and optional advantage normalization operate on Actor-specific batches.
Read the Interfaces#
Use Use Channel for Communication to understand Collector and Dispatcher execution. Use
Embodied Data Interface for exact data-class and Collector APIs.
The complete collector and accumulation implementation lives in
rlinf/data/schema/embodied_trajectory.py.