nemo_rl.data_plane.tq_token_sink#
TransferQueue implementations of NeMo-Gym’s token staging protocols.
TQTokenSink/TQTokenSource are NeMo-RL’s providers for the
ledger-authoritative capture design:
the sink is the worker-side write of one model call’s token delta to the
rollout_staging partition — the design’s only heavy token hop — and the
source is the finalizer’s read-back of those rows by staging key. This module
is the only hot-path file that knows tokens live in TQ; Gym sees opaque
staging keys.
Each staged row carries three jagged columns (token_ids_delta,
token_mask_delta, generation_logprobs_delta), the complete receipt
identity/lineage metadata, and all digest inputs so it round-trips to a
normally validated StagedCallBaseSnapshot. Masks/logprobs are float32 on
the wire, matching compute_staging_digest’s float32-bit-pattern scheme, so
digest recomputation over fetched values is byte-exact. Route payloads never
ride inside snapshots: the source returns them as separate RouteFragment
values keyed by staging key, digest-verified by the plan executor at point of
use.
Module Contents#
Classes#
One explicitly identified small-column finalization fetch result. |
|
Gym |
|
Gym |
Functions#
Encode non-empty bytes as one jagged TQ row. |
|
Call a DataPlaneClient method on a local client or a Ray actor handle. |
|
Slice one row out of a batched fetch, restoring single-row shapes. |
|
Rebuild one normally validated base snapshot; route bytes never enter it. |
|
Extract one staged route payload beside (never inside) the snapshot. |
|
Read one required scalar from a single-row TQ result. |
Data#
API#
- nemo_rl.data_plane.tq_token_sink.STAGING_FIELDS#
None
- nemo_rl.data_plane.tq_token_sink._MODE_TO_CODE#
None
- nemo_rl.data_plane.tq_token_sink._CODE_TO_MODE#
None
- nemo_rl.data_plane.tq_token_sink._bytes_tensor(value: bytes) torch.Tensor#
Encode non-empty bytes as one jagged TQ row.
- nemo_rl.data_plane.tq_token_sink._optional_digest_fields(
- value: str | None,
- class nemo_rl.data_plane.tq_token_sink.FetchedStagedCall#
One explicitly identified small-column finalization fetch result.
fragmentis populated only when the fetch requested route payloads (direct mode); deferred finalization leaves route bytes in TQ and carries onlyrouted_lentransport metadata.- staging_key: str#
None
- snapshot: nemo_gym.token_id_capture.staging.records.StagedCallBaseSnapshot#
None
- routed_len: int#
None
- fragment: nemo_rl.experience.route_assembly.RouteFragment | None#
None
- nemo_rl.data_plane.tq_token_sink._call_dp(
- dp_client: Any,
- method_name: str,
- **kwargs: Any,
Call a DataPlaneClient method on a local client or a Ray actor handle.
- class nemo_rl.data_plane.tq_token_sink.TQTokenSink(dp_client: Any, *, staging_partition: str)#
Gym
StagingSinkoverDataPlaneClient.put_samples.stageis synchronous and returns only after TQ acknowledged the write, so the capture layer’s fail-closed ordering (bytes durable before the model call is acked) holds by construction. Failures are reported in theStageResult; the finalizer turns a poisoned rollout into a placeholder row (seeRolloutReassembler.finalize_group).stageis thread-safe per theStagingSinkcontract: it holds no per-call mutable state, so the capture host may run writes for unrelated calls concurrently.Initialization
- stage(
- record: nemo_gym.token_id_capture.staging.records.StagedCallRecord,
- clear(staging_keys: list[str]) None#
Drop staged rows (finalizer / eviction cleanup).
- class nemo_rl.data_plane.tq_token_sink.TQTokenSource(dp_client: Any, *, staging_partition: str)#
Gym
StagingSourceoverDataPlaneClient.get_samples.All requested rows are fetched in a single batched
get_samplescall (TQ returns jagged delta columns as nested tensors;_from_wirepreserves the raggedness), in the order requested. A missing or unreadable row raisesKeyErrorper the protocol — the finalizer maps that to a placeholder, never a silent skip. TQ’s field-readiness check is all-or-nothing across a batch, so the extras fallback is batch-level: extras-free runs land in the base schema exactly like the old per-key probe, but a batch with mixed extras presence degrades every row to the base schema (worker feature-gating makes presence uniform per run).Initialization
- fetch(
- staging_keys: list[str],
Gym
StagingSourceconformance: base snapshots only, in order.
- fetch_prefix_token_ids(staging_keys: list[str]) list[int]#
Bulk-fetch ordered delta chain and concatenate token_ids_delta into a prefix.
- fetch_for_finalization(
- staging_keys: list[str],
- *,
- include_route_fragments: bool = False,
Fetch digest-covered base columns, plus route payloads when requested.
Deferred mode (the default) never selects
routed_experts— route bytes stay in TQ for the policy worker. Direct mode passesinclude_route_fragments=Trueto pull the payloads in the same batched read and receives them asRouteFragmentvalues beside the base snapshots, never inside them.
- nemo_rl.data_plane.tq_token_sink._select_row(
- rows: tensordict.TensorDict,
- index: int,
Slice one row out of a batched fetch, restoring single-row shapes.
_row_to_base_snapshotpredates batching and expects each field with a leading batch dim of 1 (the shape a single-keyget_samplesreturns), so re-add it after indexing. Indexing a nested tensor yields that row’s dense component, which is exactly the jagged-row payload.
- nemo_rl.data_plane.tq_token_sink._row_leaf(row: Any, name: str) torch.Tensor#
- nemo_rl.data_plane.tq_token_sink._row_text(row: Any, name: str) str#
- nemo_rl.data_plane.tq_token_sink._row_to_base_snapshot(
- row: Any,
Rebuild one normally validated base snapshot; route bytes never enter it.
- nemo_rl.data_plane.tq_token_sink._row_to_route_fragment(
- row: Any,
Extract one staged route payload beside (never inside) the snapshot.
- nemo_rl.data_plane.tq_token_sink._row_scalar_int(row: Any, field_name: str) int#
Read one required scalar from a single-row TQ result.