kempnerforge.resilience.elastic¶
SLURM job and auto-resume helpers.
Despite the module name, nothing here is elastic training: there is no elastic (torchelastic) rendezvous and no change of membership while a job runs. The helpers read the SLURM job’s environment and find the checkpoint a restarted run resumes from:
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
A checkpoint counts when
is_complete_checkpointaccepts it, with the samenum_stagesandrequire_train_state, so a reader of a run’s checkpoints that calls that function counts the same steps as saved. An interrupted save leaves astep_Nthat 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.ptandmetadata.jsonleaves 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.CheckpointManagerpointslatestonly at a complete save, but the save can lose files afterwards, solatestis checked like astep_N: when it is not complete, a warning names it and why, and the scan below picks the checkpoint to resume. Alatestwhose shards are all there but that losttrain_state.ptormetadata.jsonis still returned when no checkpoint is complete, after an error log, instead of the run starting over from step 0; the load then refuses one withouttrain_state.pt, and the optimizer state of one withoutmetadata.json, the only record of the weight-decay scope that state was saved under. Otherwise, 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 that records no degree counts only whenpp0throughpp{num_stages - 1}all hold.metadata, including stages that never created their directory. 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 before the degree was recorded looks the same. One that records its degree is complete at that degree, so a checkpoint of any layout is returned as it is, and loading it refuses what the run cannot load with an error that names both layouts.require_train_state (bool) – Skip a checkpoint whose shards hold optimizer state, or that has a
train_state.pt, unless it has bothtrain_state.ptandmetadata.json. A caller that loads the weights alone, which such a checkpoint still holds in full, passes False to keep the newest one whose shards are complete.
- Returns:
Path to the latest usable checkpoint, or None if none found.
- Return type:
Path | None