kempnerforge.resilience.elastic¶
Elastic training and SLURM integration helpers.
Provides utilities for training jobs that may be preempted, requeued, or restarted with a different number of nodes:
SLURM job info detection
Requeue detection
Auto-resume path resolution
Functions
Read SLURM job information from environment variables. |
|
Check if we are running under SLURM. |
|
Check if this is a requeued SLURM job. |
|
Log SLURM job information (if running under SLURM). |
|
|
Find the latest checkpoint for auto-resume. |
Classes
Information about the current SLURM job. |
- class kempnerforge.resilience.elastic.SLURMInfo[source]¶
Bases:
objectInformation about the current SLURM job.
- kempnerforge.resilience.elastic.get_slurm_info()[source]¶
Read SLURM job information from environment variables.
- Returns:
SLURMInfo if running under SLURM, None otherwise.
- Return type:
SLURMInfo | None
- kempnerforge.resilience.elastic.is_slurm_job()[source]¶
Check if we are running under SLURM.
- Return type:
- kempnerforge.resilience.elastic.is_slurm_requeue()[source]¶
Check if this is a requeued SLURM job.
Uses
SLURM_RESTART_COUNT(set by SLURM on requeue).- Return type:
- kempnerforge.resilience.elastic.resolve_resume_path(checkpoint_dir, num_stages=None, *, require_train_state=True)[source]¶
Find the latest checkpoint for auto-resume.
- Checks:
{checkpoint_dir}/latestsymlinkMost recent
step_Ndirectory whose save completed
CheckpointManageronly ever pointslatestat a complete checkpoint, so (1) needs no further test; one that lost files since is returned as is, and the load reports it. Thestep_Nfallback has no such guarantee: an interrupted save leaves a directory that exists but holds no.metadata, and resuming into it fails indcp.loadwith “metadata is None”. A save that stopped after its DCP shards and beforetrain_state.ptleaves optimizer state without the step, LR schedule and data position that go with it, whichCheckpointManager.loadrefuses. Skipping both kinds turns an unrecoverable run into one that resumes from the last complete checkpoint, whatever left the partial directory behind. Whenstep_Ndirectories exist but none is complete, a run that meant to resume starts over, so that is logged at ERROR.- Parameters:
checkpoint_dir (str) – Base checkpoint directory.
num_stages (int | None) – The run’s pipeline degree. With it, a
step_Nin the per-stage layout counts only whenpp0throughpp{num_stages - 1}all hold.metadata, including stages that never created their directory; see_dcp_durable. When no step has every stage, the newest one that is otherwise complete is returned as before, after an error log, rather than the run starting over: a checkpoint saved with another pipeline degree looks the same, and resume does not support changing the degree.require_train_state (bool) – Skip a
step_Nwhose shards hold optimizer state but that has notrain_state.pt. A caller that loads the weights alone, which such a checkpoint still holds in full, passes False to keep the newest one.
- Returns:
Path to the latest usable checkpoint, or None if none found.
- Return type:
Path | None