Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions recml/core/utils/keras_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ def __init__(
checkpoint_dir: str,
max_to_keep: int = 5,
save_interval_epochs: int = 1,
choose_store_cell: bool = True,
):
"""Initializes a KerasOrbaxCheckpointManager.

Args:
checkpoint_dir: The directory to save checkpoints to.
max_to_keep: The maximum number of checkpoints to keep.
save_interval_epochs: The interval (in epochs) to save checkpoints.
choose_store_cell: Whether to dynamically select the CNS2 store cell.
"""
if keras.backend.backend() != "jax":
raise ValueError(
Expand All @@ -92,6 +94,11 @@ def __init__(
options=ocp.CheckpointManagerOptions(
save_interval_steps=save_interval_epochs,
max_to_keep=max_to_keep,
file_options=ocp.options.FileOptions(
cns2_storage_options=ocp.options.Cns2StorageOptions(
choose_store_cell=choose_store_cell,
),
),
),
)

Expand Down Expand Up @@ -430,20 +437,27 @@ def __init__(
checkpoint_dir: str,
max_to_keep: int = 5,
save_interval_epochs: int = 1,
choose_store_cell: bool = True,
):
"""Initializes a KerasOrbaxCheckpointManager.

Args:
checkpoint_dir: The directory to save checkpoints to.
max_to_keep: The maximum number of checkpoints to keep.
save_interval_epochs: The interval (in epochs) to save checkpoints.
choose_store_cell: Whether to dynamically select the CNS2 store cell.
"""
super().__init__(
directory=checkpoint_dir,
checkpointers=ocp.AsyncCheckpointer(ocp.PyTreeCheckpointHandler()),
options=ocp.CheckpointManagerOptions(
save_interval_steps=save_interval_epochs,
max_to_keep=max_to_keep,
file_options=ocp.options.FileOptions(
cns2_storage_options=ocp.options.Cns2StorageOptions(
choose_store_cell=choose_store_cell,
),
),
),
)

Expand Down
Loading