ray.train.lightning.LightningCheckpoint#

class ray.train.lightning.LightningCheckpoint(*args, **kwargs)[source]#

Bases: ray.train.torch.torch_checkpoint.TorchCheckpoint

A Checkpoint with Lightning-specific functionality.

LightningCheckpoint only support file based checkpoint loading. Create this by calling LightningCheckpoint.from_directory(ckpt_dir), LightningCheckpoint.from_uri(uri) or LightningCheckpoint.from_path(path)

LightningCheckpoint loads file named model under the specified directory.

Examples:

from ray.train.lightning import LightningCheckpoint

# Suppose we saved a checkpoint in "./checkpoint_000000/model":
# Option 1 (Preferred): Load from the checkpoint file
checkpoint = LightningCheckpoint.from_path(
    path="./checkpoint_00000/model"
)

# Option 2: Load from a directory
checkpoint = LightningCheckpoint.from_directory(
    path="./checkpoint_00000/"
)

# Suppose we saved a checkpoint in an S3 bucket:
# Option 3: Load from URI
checkpoint = LightningCheckpoint.from_uri(
    path="s3://path/to/checkpoint/directory/"
)

PublicAPI (alpha): This API is in alpha and may change before becoming stable.

Methods

as_directory()

Return checkpoint directory path in a context.

from_bytes(data)

Create a checkpoint from the given byte string.

from_checkpoint(other)

Create a checkpoint from a generic ray.air.checkpoint.Checkpoint.

from_dict(data)

Create checkpoint object from dictionary.

from_directory(path)

Create checkpoint object from directory.

from_model(model, *[, preprocessor])

Create a Checkpoint that stores a Torch model.

from_path(path, *[, preprocessor])

Create a ray.air.lightning.LightningCheckpoint from a checkpoint file.

from_state_dict(state_dict, *[, preprocessor])

Create a Checkpoint that stores a model state dictionary.

from_uri(uri)

Create checkpoint object from location URI (e.g.

get_internal_representation()

Return tuple of (type, data) for the internal representation.

get_model(model_class, ...)

Retrieve the model stored in this checkpoint.

get_preprocessor()

Return the saved preprocessor, if one exists.

set_preprocessor(preprocessor)

Saves the provided preprocessor to this Checkpoint.

to_bytes()

Return Checkpoint serialized as bytes object.

to_dict()

Return checkpoint data as dictionary.

to_directory([path])

Write checkpoint data to directory.

to_uri(uri)

Write checkpoint data to location URI (e.g.

Attributes

path

Return path to checkpoint, if available.

uri

Return checkpoint URI, if available.