nemo_rl.utils.tensor_ops#
Module Contents#
Functions#
Right-pad each tensor along dim 1 to |
|
Computes the mean of a microbatch, using a global statistic as the normalization factor. |
|
Min of the entries of values where mask is set. |
|
Max of the entries of values where mask is set. |
API#
- nemo_rl.utils.tensor_ops.pad_and_concat(
- tensors: list[torch.Tensor],
- *,
- target_len: int,
- pad_value: float = 0.0,
Right-pad each tensor along dim 1 to
target_len, then concatenate along dim 0.- Parameters:
tensors – Tensors with the sequence on dim 1.
target_len – Sequence length every tensor is padded up to.
pad_value – Fill value for the padded positions.
- Returns:
The padded tensors concatenated along dim 0.
- nemo_rl.utils.tensor_ops.masked_mean(
- values: torch.Tensor,
- mask: torch.Tensor,
- dim: Optional[int] = None,
- global_normalization_factor: Optional[torch.Tensor | float] = None,
Computes the mean of a microbatch, using a global statistic as the normalization factor.
- nemo_rl.utils.tensor_ops.masked_var(
- values: torch.Tensor,
- mask: torch.Tensor,
- mean: Optional[torch.Tensor | float] = None,
- unbiased: bool = True,
- nemo_rl.utils.tensor_ops.masked_min(values: torch.Tensor, mask: torch.Tensor) torch.Tensor#
Min of the entries of values where mask is set.
- Parameters:
values – Tensor to reduce.
mask – Mask broadcastable to values; nonzero entries are kept.
- Returns:
A 0-dim tensor in the dtype of values; +inf when mask selects nothing.
- nemo_rl.utils.tensor_ops.masked_max(values: torch.Tensor, mask: torch.Tensor) torch.Tensor#
Max of the entries of values where mask is set.
- Parameters:
values – Tensor to reduce.
mask – Mask broadcastable to values; nonzero entries are kept.
- Returns:
A 0-dim tensor in the dtype of values; -inf when mask selects nothing.