Skip to content

Commit 218da6d

Browse files
SujeethJineshOrbax Authors
authored andcommitted
Move MTC files to multi_tier_checkpointing and use local checkpoint engine
PiperOrigin-RevId: 908412104
1 parent f222ff5 commit 218da6d

10 files changed

Lines changed: 1191 additions & 958 deletions

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
--ignore=orbax/checkpoint/experimental/emergency/local_checkpoint_data_debugging_test.py \
7373
--ignore=orbax/checkpoint/experimental/emergency/local_checkpoint_manager_test.py \
7474
--ignore=orbax/checkpoint/experimental/emergency/multihost_test.py \
75-
--ignore=orbax/checkpoint/experimental/emergency/replicator_checkpoint_manager_test.py \
75+
--ignore=orbax/checkpoint/experimental/emergency/multi_tier_checkpointing/replicator_checkpoint_manager_test.py \
7676
--ignore=orbax/checkpoint/_src/testing/multiprocess_test.py \
7777
--ignore=orbax/checkpoint/_src/testing/oss/multiprocess_test.py \
7878
$(python3 -c "import yaml; d=yaml.safe_load(open('orbax/checkpoint/_src/testing/oss/tagged_tests.yaml')); print(' '.join(['--ignore=' + t.replace(':', '/') + '.py' for k,v in d.items() if k.startswith('processes') and v for t in v]))")

checkpoint/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ merging.
1818
- Add Colocated Python Orchestration handling
1919
- #v1 Add `LeafHandler` as a `CheckpointableHandler`, so that ordinary PyTree
2020
leaves can also be saved as individual checkpointables.
21+
- Move MTC files to multi_tier_checkpointing and use local checkpoint engine
2122

2223
## [0.11.36] - 2026-04-14
2324

checkpoint/orbax/checkpoint/_src/testing/oss/generate_multiprocess_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
'orbax/checkpoint/experimental/v1',
3535
'orbax/checkpoint/experimental/emergency/p2p',
3636
'orbax/checkpoint/experimental/emergency/checkpoint_manager_test.py',
37-
'orbax/checkpoint/experimental/emergency/replicator_checkpoint_manager_test.py',
37+
'orbax/checkpoint/experimental/emergency/multi_tier_checkpointing/replicator_checkpoint_manager_test.py',
3838
'orbax/checkpoint/google',
3939
]
4040

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Copyright 2026 The Orbax Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""ProcessMetadataCheckpointHandler class.
16+
17+
Implementation of CheckpointHandler interface.
18+
"""
19+
20+
from __future__ import annotations
21+
22+
import dataclasses
23+
from typing import Callable, List, Tuple
24+
25+
from absl import logging
26+
from etils import epath
27+
import jax
28+
from orbax.checkpoint import checkpoint_args
29+
from orbax.checkpoint import options as options_lib
30+
from orbax.checkpoint._src import asyncio_utils
31+
from orbax.checkpoint._src.futures import future
32+
from orbax.checkpoint._src.handlers import async_checkpoint_handler
33+
from orbax.checkpoint._src.multihost import multihost
34+
from orbax.checkpoint.experimental.emergency import mesh_consistency
35+
36+
37+
CheckpointArgs = checkpoint_args.CheckpointArgs
38+
PreviousDistributedToDeviceIds = List[List[int]]
39+
PreviousDeviceIds = List[int]
40+
register_with_handler = checkpoint_args.register_with_handler
41+
42+
43+
class ProcessMetadataCheckpointHandler(
44+
async_checkpoint_handler.AsyncCheckpointHandler
45+
):
46+
"""Saves process metadata."""
47+
48+
def __init__(
49+
self,
50+
multiprocessing_options: options_lib.MultiprocessingOptions = (
51+
options_lib.MultiprocessingOptions()
52+
),
53+
distributed_to_device_ids_fn: Callable[[], List[List[int]]] | None = None,
54+
) -> None:
55+
"""Initializes ProcessMetadataCheckpointHandler."""
56+
self._distributed_to_device_ids_fn = (
57+
distributed_to_device_ids_fn or multihost.distributed_to_device_ids
58+
)
59+
60+
async def async_save(
61+
self,
62+
directory: epath.Path,
63+
args: ProcessMetadataSaveArgs,
64+
) -> List[future.Future] | None:
65+
"""Saves the given process metadata.
66+
67+
Args:
68+
directory: save location directory.
69+
args: ProcessMetadataSaveArgs (see below).
70+
71+
Returns:
72+
A list of commit futures.
73+
"""
74+
logging.info('Saving process metadata to %s', directory)
75+
return [
76+
future.CommitFutureAwaitingContractedSignals(
77+
mesh_consistency.save_process_metadata(
78+
directory,
79+
args.global_mesh,
80+
self._distributed_to_device_ids_fn(),
81+
),
82+
name='process_metadata_ch_save',
83+
)
84+
]
85+
86+
def save(
87+
self,
88+
directory: epath.Path,
89+
args: ProcessMetadataSaveArgs,
90+
) -> None:
91+
async def async_save(
92+
directory: epath.Path,
93+
args: ProcessMetadataSaveArgs,
94+
) -> None:
95+
commit_futures = await self.async_save(directory, args)
96+
if commit_futures:
97+
for f in commit_futures:
98+
f.result()
99+
100+
asyncio_utils.run_sync(async_save(directory, args))
101+
102+
def restore(
103+
self,
104+
directory: epath.Path,
105+
args: ProcessMetadataRestoreArgs,
106+
) -> Tuple[PreviousDistributedToDeviceIds, PreviousDeviceIds]:
107+
"""Restores metadata from directory.
108+
109+
Args:
110+
directory: restore location directory.
111+
args: ProcessMetadataRestoreArgs (see below).
112+
113+
Returns:
114+
A tuple of previous distributed to device ids and previous device ids.
115+
"""
116+
logging.info('Restoring process metadata from %s', directory)
117+
return mesh_consistency.read_process_metadata(directory)
118+
119+
120+
@register_with_handler(ProcessMetadataCheckpointHandler, for_save=True)
121+
@dataclasses.dataclass
122+
class ProcessMetadataSaveArgs(CheckpointArgs):
123+
"""Parameters for saving process metadata.
124+
125+
Attributes:
126+
global_mesh: the global mesh.
127+
"""
128+
129+
global_mesh: jax.sharding.Mesh
130+
131+
132+
@register_with_handler(ProcessMetadataCheckpointHandler, for_restore=True)
133+
@dataclasses.dataclass
134+
class ProcessMetadataRestoreArgs(CheckpointArgs):
135+
"""Parameters for restoring process metadata."""

0 commit comments

Comments
 (0)