nemo_rl.algorithms.single_controller_utils.utils#
Helpers used by SingleControllerActor.
Module Contents#
Functions#
Reduce per-microbatch metric lists into step-level scalars. |
|
Reduce per-step accumulators from _advantage_stage into step scalars. |
|
Reduce sequence-error metrics across streaming chunks. |
|
Read a tensor column from a TensorDict, depadding if nested. |
|
Drop a trailing dim of size 1 if present. |
|
Pack tensors for DataPlane put, re-nesting jagged rows when needed. |
Data#
API#
- nemo_rl.algorithms.single_controller_utils.utils._MB_METRIC_MIN: frozenset[str]#
‘frozenset(…)’
- nemo_rl.algorithms.single_controller_utils.utils._MB_METRIC_MAX: frozenset[str]#
‘frozenset(…)’
- nemo_rl.algorithms.single_controller_utils.utils._MB_METRIC_MEAN: frozenset[str]#
‘frozenset(…)’
- nemo_rl.algorithms.single_controller_utils.utils.aggregate_step_metrics(
- train_result: dict[str, Any],
Reduce per-microbatch metric lists into step-level scalars.
- Parameters:
train_result – Output of TQPolicy.finish_train_step.
- Returns:
Flat dict of step-level scalars ready for logging.
- nemo_rl.algorithms.single_controller_utils.utils.reduce_advantage_pump_metrics(
- rewards: list[torch.Tensor],
- masked_advantages: list[torch.Tensor],
- sequence_lengths: list[int],
- seq_logprob_error_metrics: list[dict[str, float]] | None = None,
Reduce per-step accumulators from _advantage_stage into step scalars.
- Parameters:
rewards – One tensor per advantage_stage call; each row a sample reward.
masked_advantages – Token-masked advantages, one tensor per call.
sequence_lengths – All input_lengths trained on this step.
seq_logprob_error_metrics – Sequence-error metrics and their aggregation counts, one record per streaming chunk.
- Returns:
Step-level reward, advantage, token-count, and optional sequence log-probability error metrics.
- nemo_rl.algorithms.single_controller_utils.utils._reduce_seq_logprob_error_metrics(
- records: list[dict[str, float]],
Reduce sequence-error metrics across streaming chunks.
- nemo_rl.algorithms.single_controller_utils.utils.tensor_field(
- data: tensordict.TensorDict,
- field_name: str,
Read a tensor column from a TensorDict, depadding if nested.
- Parameters:
data – TensorDict returned by the data plane.
field_name – Column name to fetch.
- Returns:
Dense tensor (nested columns are padded with zeros).
- nemo_rl.algorithms.single_controller_utils.utils.squeeze_trailing_unit_dim(value: torch.Tensor) torch.Tensor#
Drop a trailing dim of size 1 if present.
- Parameters:
value – Input tensor.
- Returns:
Tensor without the trailing unit dim.
- nemo_rl.algorithms.single_controller_utils.utils.fields_for_put(
- meta: nemo_rl.data_plane.KVBatchMeta,
- fields: dict[str, torch.Tensor],
Pack tensors for DataPlane put, re-nesting jagged rows when needed.
- Parameters:
meta – Batch meta whose sequence_lengths drive the nesting.
fields – Field name to dense tensor.
- Returns:
TensorDict shaped for dp_client.put_samples.