nemo_automodel.components.training.model_output_utils#
Utilities for working with model output objects.
HuggingFace ModelOutput types typically store hidden_states as a tuple of tensors
(tuple[Tensor, ...]) when output_hidden_states=True.
However, some custom models may store the final hidden state tensor directly in the
hidden_states field (i.e., a single [B, T, H] tensor) to reduce memory/overhead.
Downstream training code should be robust to both representations.
Module Contents#
Functions#
Return the final hidden-states tensor from a HF-like model output. |
API#
- model_output: Any,
Return the final hidden-states tensor from a HF-like model output.
Supports both common layouts:
hidden_statesis a tuple/list of tensors (HF default) → return last non-None entryhidden_statesis a single tensor-like object → return it as-is
- Parameters:
model_output – A HF
ModelOutput-like object, or a plain dict with ahidden_stateskey.- Returns:
The final hidden states tensor-like object, or None if not present.