as_directory#

Checkpoint.as_directory() → Iterator[str][source]#

Returns checkpoint contents in a local directory as a context.

If the checkpoint is stored in a local directory, this method just returns the checkpoint path without making a copy, and nothing is cleaned up.

If the checkpoint is stored remotely, this method will download the checkpoint to a local temporary directory and return the path. Additionally, if multiple workers on the same node call this method simultaneously, only a single worker will perform the download. Meanwhile, the other workers will wait for the download to finish and return the shared checkpoint path. Once all workers have left this function’s context, the temporary directory will be deleted and future workers will need to redownload the checkpoint.

Examples

>>> from pathlib import Path
>>> import tempfile
>>> from ray.train import Checkpoint
>>> temp_dir = tempfile.mkdtemp()
>>> (Path(temp_dir) / "example.txt").write_text("example checkpoint data")
23
>>> checkpoint = Checkpoint.from_directory(temp_dir)
>>> with checkpoint.as_directory() as checkpoint_dir:
...     # Do some read-only processing of files within checkpoint_dir
...     pass
>>> # At this point, if a temporary directory was created, it will have
>>> # been deleted.
Yields:

str – The local path to the checkpoint directory.