Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate Orbax emergency replicator checkpoint manager #1117

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
30 changes: 27 additions & 3 deletions MaxText/checkpointing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import numpy as np
import orbax.checkpoint as ocp
import orbax.checkpoint.experimental.emergency.checkpoint_manager as emergency_checkpoint_manager
import orbax.checkpoint.experimental.emergency.replicator_checkpoint_manager as emergency_replicator_checkpoint_manager

# pylint: disable=too-many-positional-arguments

Expand Down Expand Up @@ -91,15 +92,15 @@ def create_orbax_emergency_checkpoint_manager(
persistent_save_interval_steps: int,
orbax_logger: Optional[abstract_logger.AbstractLogger] = None,
):
"""Returns an emergency checkpoint."""
"""Returns an emergency checkpoint manager."""
flags.FLAGS.experimental_orbax_use_distributed_process_id = True
max_logging.log("Creating emergency checkpoint manager...")

options = emergency_checkpoint_manager.CheckpointManagerOptions(
local=LocalCheckpointOptions(save_interval_steps=local_save_interval_steps),
persistent=PersistentCheckpointOptions(save_interval_steps=persistent_save_interval_steps),
)
emergency_mngr = emergency_checkpoint_manager.CheckpointManager(
manager = emergency_checkpoint_manager.CheckpointManager(
local_checkpoint_dir,
epath.Path(persistent_checkpoint_dir),
global_mesh=global_mesh,
Expand All @@ -109,7 +110,30 @@ def create_orbax_emergency_checkpoint_manager(
)

max_logging.log("Emergency checkpoint manager created!")
return emergency_mngr
return manager


def create_orbax_emergency_replicator_checkpoint_manager(
local_checkpoint_dir: str,
save_interval_steps: int,
global_mesh: jax.sharding.Mesh,
):
"""Returns an emergency replicator checkpoint manager."""
flags.FLAGS.experimental_orbax_use_distributed_process_id = True
max_logging.log("Creating emergency replicator checkpoint manager...")

options = emergency_replicator_checkpoint_manager.ReplicatorCheckpointManagerOptions(
save_interval_steps=save_interval_steps,
)
manager = emergency_replicator_checkpoint_manager.ReplicatorCheckpointManager(
local_checkpoint_dir,
options,
global_mesh=global_mesh,
)

max_logging.log("Emergency replicator checkpoint manager created!")
return manager



def _find_idx(array: np.ndarray, replica_axis_idx: int):
Expand Down
27 changes: 17 additions & 10 deletions MaxText/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,16 +648,23 @@ def setup_mesh_and_model(config):
tx = optimizers.get_optimizer(config, learning_rate_schedule)
logger = checkpointing.setup_checkpoint_logger(config)
if config.enable_emergency_checkpoint:
abstract_state, _, _ = max_utils.get_abstract_state(model, tx, config, init_rng, mesh, is_training=True)
checkpoint_manager = checkpointing.create_orbax_emergency_checkpoint_manager(
config.local_checkpoint_directory,
config.checkpoint_dir,
mesh,
abstract_state,
config.local_checkpoint_period,
config.checkpoint_period,
logger,
)
if config.use_replicator_service:
checkpoint_manager = checkpointing.create_orbax_emergency_replicator_checkpoint_manager(
config.local_checkpoint_directory,
config.local_checkpoint_period,
mesh,
)
else:
abstract_state, _, _ = max_utils.get_abstract_state(model, tx, config, init_rng, mesh, is_training=True)
checkpoint_manager = checkpointing.create_orbax_emergency_checkpoint_manager(
config.local_checkpoint_directory,
config.checkpoint_dir,
mesh,
abstract_state,
config.local_checkpoint_period,
config.checkpoint_period,
logger,
)
else:
# TODO(b/368121306): Remove this once zarr3 support is plumbed on the backend
use_ocdbt = config.checkpoint_storage_use_ocdbt
Expand Down
Loading