kempnerforge.checkpoint.ownership

One training run per checkpoint directory.

Before a training run resumes or saves, rank 0 records the run in <checkpoint.dir>/.owner, and it marks the record released when the run ends cleanly. Two live runs in one directory would overwrite each other’s checkpoints, prune them and resume from them, so a run is refused a directory that another run still owns.

Functions

claim_checkpoint_dir(directory)

Record this run as the owner of directory unless another run owns it.

release_checkpoint_dir(directory, claim)

Mark directory's owner record released when it is the record of claim.

this_run()

A new owner record for this process.

Exceptions

CheckpointDirInUseError

Another run that is alive, or not known to have ended, owns the checkpoint directory.

exception kempnerforge.checkpoint.ownership.CheckpointDirInUseError[source]

Bases: RuntimeError

Another run that is alive, or not known to have ended, owns the checkpoint directory.

kempnerforge.checkpoint.ownership.this_run()[source]

A new owner record for this process.

claim is new for every record. process is a random id of this process, by which it knows its own records. pid_ns is the pid namespace pid is numbered in, since containers that share the host name but not that namespace reuse pids. slurm_job is the SLURM job, or job array element (<array job>_<task>), that runs the process, and slurm_restart counts the times SLURM requeued it.

Return type:

dict[str, Any]

kempnerforge.checkpoint.ownership.claim_checkpoint_dir(directory)[source]

Record this run as the owner of directory unless another run owns it.

The record is written to a temp file of its own and linked into place, so it appears whole and only one claimer creates it. A record this process wrote is replaced, unless it released it, since another claimer may be taking a released record over. A record of a run that has ended is replaced by one claimer alone (see _take_over), which reads the record back before it counts the claim; the replacement is logged as a warning unless the record was released. Claims and releases in one process run one at a time.

Returns:

The new record’s claim id, for release_checkpoint_dir.

Raises:

CheckpointDirInUseError – A run that is alive, or whose state this host cannot check, owns directory, or another claimer is taking it over.

Parameters:

directory (Path)

Return type:

str

kempnerforge.checkpoint.ownership.release_checkpoint_dir(directory, claim)[source]

Mark directory’s owner record released when it is the record of claim.

The record is replaced, through the same token as a takeover (see _take_over), by a released record with a claim id of its own; nothing removes .owner, so a removal that NFS replays cannot remove a later run’s record. An error marking it is logged rather than raised, so the rest of the run’s teardown still runs.

Parameters:
Return type:

None