nemo_automodel.components.training.embedding_row_repair
nemo_automodel.components.training.embedding_row_repair
Repair near-zero input-embedding rows before optimizer construction.
Module Contents
Classes
Functions
Data
API
Configuration for detecting and repairing damaged input embeddings.
A row is repaired when its L2 norm is non-finite or no larger than
min_norm. Its replacement uses the corresponding output-embedding
direction, scaled to the RMS norm of the checkpoint’s healthy input rows.
This preserves a token-specific direction while restoring the magnitude
expected by the pretrained model.
The operation runs once after base-checkpoint loading and model sharding, before optimizer construction. It supports regular tensors and DTensors whose two matrix dimensions are sharded or replicated.
Repair damaged input-embedding rows in model when enabled.
Summary of a completed input-embedding repair.
Local tensor view and DTensor metadata for an embedding matrix.
Validate that input and output embedding shards can be repaired rowwise.
Parameters:
Input embedding matrix view with global shape [vocab, hidden] and local tensor shape [local_vocab, local_hidden].
Output embedding matrix view with global shape [vocab, hidden] and local tensor shape [local_vocab, local_hidden].
Compute complete row squared norms for the local vocabulary shard.
Parameters:
Embedding matrix view with global shape [vocab, hidden] and local tensor shape [local_vocab, local_hidden].
Returns: torch.Tensor
Tensor of shape [local_vocab] containing each local vocabulary row’s squared L2 norm over the full
Gather sorted global vocabulary row IDs across all ranks.
Map local vocabulary-row selections to global token IDs.
Parameters:
Embedding matrix view with global shape [vocab, hidden] and local tensor shape [local_vocab, local_hidden].
Boolean tensor of shape [local_vocab] selecting rows from view.local.
Returns: list[int]
Global vocabulary row IDs selected by local_mask.
Compute the global minimum of a scalar tensor.
Parameters:
Scalar tensor of shape [] containing this rank’s local minimum.
Returns: float
Minimum scalar value across all distributed ranks.
Compute the RMS norm of healthy input-embedding rows.
Parameters:
Tensor of shape [local_vocab] containing each local vocabulary row’s squared L2 norm over the full hidden axis.
Boolean tensor of shape [local_vocab] selecting healthy rows from row_squared_norms.
Returns: float
RMS L2 norm over all healthy global vocabulary rows.
Create a local view for a regular tensor or DTensor embedding matrix.
Parameters:
Embedding matrix of shape [vocab, hidden]. For DTensor inputs, the global shape is [vocab, hidden] and each placement must replicate or shard axis 0 (vocab) or axis 1 (hidden).
Parameter name used in validation errors.
Returns: _WeightView
View whose local tensor has shape [local_vocab, local_hidden] and whose shape and offset metadata
Detect and repair near-zero input-embedding rows.
Parameters:
Loaded and optionally DTensor-sharded causal language model whose input and output embedding weights have shape [vocab, hidden].
Inclusive L2-norm threshold identifying a damaged row.
Safety bound; abort instead of mutating a broadly damaged checkpoint.
Returns: EmbeddingRowRepairReport
A report containing every repaired global vocabulary row ID.