nemo_automodel.components.loss.utils
nemo_automodel.components.loss.utils
Module Contents
Functions
Data
API
Count supervised entries in an integer target tensor of any shape.
Both the dataset’s -100 padding and the configured ignore_index
are excluded. The return value is a Python integer.
Return the final hidden-states tensor from an HF-like model output.
Local copy of components.training.model_output_utils.get_final_hidden_states
to keep components/loss/ import-independent from components/training/.
Return the model’s LM-head module, if one can be found.
Local copy of components.utils.model_utils.get_lm_head_module to keep
components/loss/ import-independent from components/utils/ (see the
Components must not import each other import-linter contract).
Return the model’s LM-head weight without changing its distributed layout.
Return the label sentinel consumed by loss_fn.
Align KD supervision with the main loss mask.
Parameters:
Integer target tensor of any shape.
Label sentinel consumed by the main loss.
Label sentinel consumed by the KD loss.
Returns: torch.Tensor
Target tensor with the same shape, dtype, and device as labels.
Map dataset padding to a loss’s configured ignore index.
Parameters:
Integer target tensor of any shape.
Label sentinel consumed by the loss.
Returns: torch.Tensor
Target tensor with the same shape, dtype, and device as labels.
Calculate a logit-based or fused linear cross-entropy loss.
Parameters:
Loss module. FusedLinearCrossEntropy consumes
hidden_states with shape [batch, sequence, hidden], labels
with shape [batch, sequence], and an LM-head weight with global
shape [vocab, hidden]. Other loss modules consume logits with
shape [batch, sequence, vocab] and labels.
Loss inputs. Rank-local tensors keep their existing layout;
grad_reduce_group describes the ranks contributing independent
fused-loss shards. The caller’s mapping and tensors are not mutated.
Returns: torch.Tensor
Scalar loss tensor that does not alias an input.