nemo_automodel.components.loss.linear_ce
nemo_automodel.components.loss.linear_ce
Module Contents
Classes
Functions
Data
API
Bases: Module
Fused linear-projection and cross-entropy loss module.
Compute fused linear cross entropy matching PyTorch behavior.
Parameters:
Rank-local hidden states with shape
[batch, sequence, hidden].
Rank-local target token IDs with shape [batch, sequence].
LM-head weight with global shape [vocab, hidden].
It may be a regular tensor or an FSDP-sharded DTensor.
Global number of non-padding target tokens used to normalize a sum-reduced loss.
Group that contributes independent loss shards
when lm_weight is a sharded DTensor.
Returns: torch.Tensor
Scalar loss tensor on the same device as hidden_states. The
Materialize an LM-head DTensor with gradient-correct reduction semantics.
Fused linear CE consumes the LM-head weight outside the owning FSDP
module’s forward. Each data/context-parallel rank therefore computes a
rank-local full-weight gradient. A plain DTensor.full_tensor() marks
that gradient as replicated, so backward only slices the local result
into the owned shard instead of combining peer contributions.
Parameters:
LM-head weight with global shape [vocab, hidden]. A
regular tensor is returned unchanged. A DTensor may have any
FSDP sharding placement over its device mesh and is gathered to
a rank-local regular tensor with the global shape, device, and
dtype.
Process group whose ranks contribute independent token losses. Its size must match the LM-head DTensor mesh.
Returns: torch.Tensor
Regular tensor with shape [vocab, hidden]. For a DTensor input,
Raises:
ValueError: If a trainable sharded weight has no matching reduction group. This fails closed instead of producing rank-local shards.
Check if pytorch-triton/triton version is greater than or equal to the specified version.
Parameters:
Version string to check
Returns:
True if pytorch-triton/triton version >= specified version
Check if pytorch-triton/triton version is greater than or equal to 3.1.0.
Returns:
True if pytorch-triton/triton version >= 3.1.0