nemo_automodel.components.checkpoint.utils
nemo_automodel.components.checkpoint.utils
Module Contents
Functions
Data
API
Return whether target points at or inside checkpoint.
Return the trailing checkpoint step number, or -1 when the name is not a checkpoint.
Inspect checkpoint tensors and return their exact dtypes by key.
This reads checkpoint metadata only by loading tensors on the meta
device, so it preserves the per-tensor dtype information without
materializing full checkpoint weights in memory.
Return whether path looks like a symlink fallback checkpoint pointer.
Return existing checkpoint directories whose names end in step_<N>.
Resolve a checkpoint pointer target relative to ckpt_root.
Clear the marker written by mark_checkpoint_incomplete.
Parameters:
Directory of the checkpoint that finished writing.
Estimate logical bytes in a state dict without materializing tensors.
Estimate logical bytes in a tensor without materializing it.
Resolve the most recent checkpoint directory.
Preference order
- Valid LATEST symlink or txt file under checkpoint_dir
- Highest step directory under checkpoint_dir whose name ends in
step_<N>
Directories left behind by an interrupted save are skipped at both steps. The LATEST target needs the same filter as the step scan: re-saving a step whose directory LATEST already points at leaves the pointer aimed at a directory that is being rewritten, so an interruption there would otherwise resume from a partially written checkpoint.
Returns: str | Path | None
Path (or str) of the latest checkpoint directory, or None.
Return checkpoints targeted by top-level symlinks or symlink fallback text files.
Format bytes as a human-readable GiB value.
Format a helpful error message for a missing checkpoint directory.
Format the output shard count for user-facing log messages.
Return the current distributed rank, defaulting to 0 when not initialized.
Return the total checkpoint size recorded in a Hugging Face safetensors index.
Return candidate checkpoint keys that can source a tied LM head.
Parameters:
Model or pipeline stage to inspect.
Optional normalized LM head FQN.
Returns: list[str]
Ordered list of possible source FQNs.
Return the current distributed world size, defaulting to 1 when not initialized.
Return whether a checkpoint directory was left behind by an interrupted save.
Parameters:
Directory to inspect.
Returns: bool
True when the in-progress marker is still present.
Check if path is a cloud storage path (MSC).
Return True on the main rank.
Return canonical AutoModel epoch_<E>_step_<S> checkpoint directories.
Mark a checkpoint directory as still being written.
A save that is interrupted (wall-clock limit, preemption, OOM) leaves the
directory behind with only some of its components written. The marker makes
that state observable so a resumed run neither loads nor retains it; it is
removed by clear_checkpoint_incomplete once the checkpoint is
published.
Parameters:
Directory of the checkpoint being written.
Populate a missing tied lm_head.weight from its embedding source.
Hugging Face checkpoints for tied-embedding models often omit
lm_head.weight entirely. That is fine for unsplit models where
tie_weights() can restore the alias, but it breaks pipeline-parallel last
stages which own lm_head but not embed_tokens.
Parameters:
Checkpoint state dict to mutate in place.
Target model or pipeline stage.
If True, fall back to the current
lm_head tensor when the tied source cannot be found in
state_dict. This preserves legacy resume behavior for older
checkpoints that were saved without a local lm_head.weight.
Returns: bool
True if a missing lm_head.weight was materialized, else False.
Read a validation metric from checkpoint loss metadata.
Resolve a checkpoint pointer symlink or fallback text file.
Resolve restore_from to a checkpoint directory.
Returns: str | None
- str: resolved checkpoint directory
Raises:
RuntimeError: If restore_from selects a checkpoint that an interrupted save left incomplete.
Whitelist NVIDIA models to allow remote code execution.
Parameters:
The name or path of the pretrained model.
Returns:
True if the model should be loaded with trust_remote_code, False otherwise.