unilab.utils.checkpoint

Pure-filesystem log root and checkpoint resolution helpers.

Functions

get_latest_checkpoint(run_dir, *[, suffix])

Return the latest model checkpoint inside a run directory.

get_latest_run(log_dir)

Return the lexicographically latest run directory under a task log root.

normalize_checkpoint_value(value)

Normalize a raw checkpoint selector value; sentinel values map to None.

normalize_load_run(load_run)

resolve_checkpoint_path(task_log_root, ...)

Resolve a checkpoint from a task log root.

unilab.utils.checkpoint.get_latest_run(log_dir)[source]

Return the lexicographically latest run directory under a task log root.

Parameters:

log_dir (str | Path)

Return type:

Path | None

unilab.utils.checkpoint.get_latest_checkpoint(run_dir, *, suffix='.pt')[source]

Return the latest model checkpoint inside a run directory.

Parameters:
Return type:

Path | None

unilab.utils.checkpoint.normalize_load_run(load_run)[source]
Parameters:

load_run (str | int | PathLike[str])

Return type:

str

unilab.utils.checkpoint.normalize_checkpoint_value(value)[source]

Normalize a raw checkpoint selector value; sentinel values map to None.

Parameters:

value (object)

Return type:

str | None

unilab.utils.checkpoint.resolve_checkpoint_path(task_log_root, load_run, *, checkpoint=None, suffix='.pt')[source]

Resolve a checkpoint from a task log root.

load_run selects the run: "-1" picks the latest run under task_log_root; any other value is first tried as a direct path and then relative to task_log_root, and may name either a run directory or a checkpoint file. checkpoint optionally selects one checkpoint inside the resolved run (an iteration number or a filename).

Returns (checkpoint_path, run_dir). A resolved run that lacks the requested (or any) checkpoint yields (None, run_dir); an unresolvable run yields (None, None).

Parameters:
Return type:

tuple[Path | None, Path | None]