nemo_rl.data_plane.adapters.tq_controller_patch#

Cheaper kv_retrieve_meta and FieldMeta.remove_samples for the TransferQueue controller.

The stock kv_retrieve_meta reads a torch tensor once per field, about a quarter of a put+get cycle on the single-threaded controller. kv_retrieve_meta below is the stock method with one .all(dim=0).tolist() instead; results are identical.

Stock FieldMeta.remove_samples re-checks every nested field’s label on every clear: it scans all live rows and, if they share one shape, relabels the field from nested to regular. That costs O(live rows) on the controller’s only request thread. The situation that triggers a relabel does happen in NeMo-RL (for example, one row left), but nothing in NeMo-RL reads the label. Readers of row shapes (TQ storage, and the Mooncake read path patched in transfer_queue.py) get them from BatchMeta.get_shapes, which serves the same shape for every row under either label, so skipping the relabel changes no data a run sees. remove_samples below skips it, so a clear costs O(cleared rows).

test_remove_samples_serves_the_same_shapes_as_stock and test_rows_survive_a_clear_that_stock_would_collapse pin that. Only nemo_rl/data_plane may import transfer_queue (test_only_the_data_plane_imports_transfer_queue), so no other code can read the label. TQ’s own test_clear_data_nested_field_becomes_regular fails under this override by design.

The controller is a Ray actor, so both are applied in a subclass started by tq.init.

Delete this module once the pinned TransferQueue includes both changes.

Module Contents#

Functions#

kv_retrieve_meta

Stock TransferQueueController.kv_retrieve_meta with one field-mask read.

remove_samples

Stock FieldMeta.remove_samples without the nested-to-regular relabel.

patch_field_meta

Install remove_samples on FieldMeta in this process; the controller calls it on start.

assert_stock_tq_version

Check that the installed TransferQueue is the version the overrides were copied from.

make_patched_controller

Return a Ray actor class that runs the controller with both overrides.

configure_controller_patch

Make tq.init start the patched controller; call before it.

Data#

API#

nemo_rl.data_plane.adapters.tq_controller_patch.logger#

‘get_logger(…)’

nemo_rl.data_plane.adapters.tq_controller_patch.STOCK_TQ_VERSION#

‘0.1.11’

nemo_rl.data_plane.adapters.tq_controller_patch.kv_retrieve_meta(
self,
keys: list[str],
partition_id: str,
create: bool = False,
) → transfer_queue.metadata.BatchMeta#

Stock TransferQueueController.kv_retrieve_meta with one field-mask read.

nemo_rl.data_plane.adapters.tq_controller_patch.remove_samples(
self: transfer_queue.controller.FieldMeta,
indexes: list[int],
) → None#

Stock FieldMeta.remove_samples without the nested-to-regular relabel.

nemo_rl.data_plane.adapters.tq_controller_patch.patch_field_meta() → None#

Install remove_samples on FieldMeta in this process; the controller calls it on start.

nemo_rl.data_plane.adapters.tq_controller_patch.assert_stock_tq_version() → None#

Check that the installed TransferQueue is the version the overrides were copied from.

Raises:

RuntimeError – If the version differs, which means the TQ pin moved.

nemo_rl.data_plane.adapters.tq_controller_patch.make_patched_controller(actor_class: Any) → Any#

Return a Ray actor class that runs the controller with both overrides.

nemo_rl.data_plane.adapters.tq_controller_patch.configure_controller_patch() → None#

Make tq.init start the patched controller; call before it.