kempnerforge.checkpoint.layout¶
Where a checkpoint keeps its DCP shards, and whether a step directory holds a whole save.
A save without pipeline parallelism writes one DCP index, .metadata, at the top of its
step_N directory: the flat layout. A save under pipeline parallelism writes one per stage,
in pp0/ to pp{n-1}/, and records n as pp in the checkpoint’s metadata.json.
A checkpoint saved before that record existed shows its degree only by the stage directories it
holds.
Beside the shards, a save’s rank 0 writes train_state.pt and then metadata.json.
is_complete_checkpoint says whether a step directory holds every file of a save, by the
rule auto-resume applies, so code that reads a run’s checkpoints while the run saves them
agrees with it.
Functions
|
Whether |
|
How |
|
The directory that holds pipeline stage |
|
The stage directories of |
Classes
How a checkpoint lays out its DCP shards. |
- class kempnerforge.checkpoint.layout.SavedLayout[source]¶
Bases:
objectHow a checkpoint lays out its DCP shards.
stagesis 0 for the flat layout, and otherwise the number of pipeline stages, each with its own DCP index inpp{k}/.recordedis whether the checkpoint’smetadata.jsonrecordsstages; when it does not,stagesis the number of stage directories the checkpoint holds.
- kempnerforge.checkpoint.layout.stage_dir(ckpt_dir, stage)[source]¶
The directory that holds pipeline stage
stage’s DCP shards inckpt_dir.
- kempnerforge.checkpoint.layout.saved_layout(ckpt_dir, meta=None)[source]¶
How
ckpt_dirlays out its DCP shards, None when it holds no DCP index.The degree
metadata.jsonrecords comes first. Without one, a.metadataat the top makes the layout flat, andpp{k}/directories make it a stage layout of as many stages, whether or not each holds its index yet. A record of something other than a positive integer is logged and counts as none.- Parameters:
- Return type:
SavedLayout | None
- kempnerforge.checkpoint.layout.stage_dirs(ckpt_dir, layout)[source]¶
The stage directories of
layoutinckpt_dir, in stage order.These are
pp0/topp{n-1}/whenmetadata.jsonrecordsn, whether or not each exists, and otherwise thepp{k}/directoriesckpt_dirholds.- Parameters:
ckpt_dir (Path)
layout (SavedLayout)
- Return type:
- kempnerforge.checkpoint.layout.is_complete_checkpoint(ckpt_dir, num_stages=None, *, require_train_state=True)[source]¶
Whether
ckpt_dirholds a complete save, by the rule auto-resume applies.resolve_resume_pathpicks a checkpoint this accepts whenever there is one, and so does the fallback of an exact resume inCheckpointManager.load. Code that reads a run’s checkpoints while the run saves them, such as a process that evaluates each saved step, calls it to count the same steps as saved.A save is complete when every DCP index of its layout is there (see
saved_layout):.metadataat the top of a checkpoint saved without pipeline parallelism, and in each ofpp0/topp{n-1}/of one that records its pipeline degreen. A stage checkpoint saved before the degree was recorded needs an index in everypp{k}/it holds and, withnum_stages, inpp0/topp{num_stages - 1}/, since a stage that stopped before its save began leaves no directory.With
require_train_state, a checkpoint whose shards hold optimizer state, or that has atrain_state.pt, also needstrain_state.ptandmetadata.json. A save’s rank 0 writes the two,metadata.jsonaftertrain_state.pt: after every stage’s shards when the save is synchronous, and while they flush when it is asynchronous, so either may land first. A checkpoint with neither optimizer state nortrain_state.pt, such as anhf-to-dcpimport, needs neither file. To tell which it is, the DCP index is read only whentrain_state.ptis absent; reading it unpickles it, as a load does. An index that cannot be read is logged and counted as holding no optimizer state, which leaves the load to report it.With
require_train_stateandnum_stages, a process that polls a live run gets a step only once its save has written every file, except a save made before the optimizer’s first step: its shards hold no optimizer state, so, like an import, it counts once its DCP indexes are there, before rank 0 writestrain_state.ptandmetadata.json. It then drops out whiletrain_state.ptis there withoutmetadata.json, and counts again oncemetadata.jsonlands, so a poller counts a step the first time this accepts it. Withoutnum_stages, a pipeline-parallel save can count early too: it records its degree only inmetadata.json, which can land after the first stage’s index, so it counts once the stage directories that exist hold their indexes, before a later stage has created its own.- Parameters:
ckpt_dir (str | PathLike[str]) – A
step_Ndirectory, or a link to one such aslatest.num_stages (int | None) – The pipeline degree of the run that reads the checkpoint, or None. It counts only for a stage checkpoint that records no degree, as a live save does until its
metadata.jsonlands: one that records it is complete at its own degree, and a load refuses a degree the run cannot load.require_train_state (bool) – True for a resume, which restores the step, LR schedule and data position from
train_state.pt; False for a reader of the weights alone, such asscripts/eval.py, which needs only the DCP shards.
- Returns:
Whether the save is complete; False for a path that is no directory, or one that holds no DCP index.
- Return type: