Skip to content

Commit

Permalink
Move Orbax path package under _src.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 693839844
  • Loading branch information
niketkumar authored and Orbax Authors committed Nov 6, 2024
1 parent b6a9dc2 commit 2ae4542
Show file tree
Hide file tree
Showing 29 changed files with 69 additions and 45 deletions.
3 changes: 2 additions & 1 deletion checkpoint/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Move `type_handlers` to `_src/serialization`
- Add notes to Barrier error `XlaRuntimeError(DEADLINE_EXCEEDED)` with
actionable info.
- Make `NameFormat.find_all` impls concurrent.
- Move `path` package under `_src` package.

## [0.8.0] - 2024-10-29

Expand All @@ -37,7 +39,6 @@ exported in the same way.
- De-duplicate `get_ts_context` usages and move to ts_utils.
- Move `logging` to `_src`.
- Move `metadata` to `_src`.
- Make `NameFormat.find_all` impls concurrent.

## [0.7.0] - 2024-10-07

Expand Down
2 changes: 1 addition & 1 deletion checkpoint/orbax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from orbax.checkpoint import version
# TODO(cpgaffney): Import the public multihost API.
from orbax.checkpoint._src.multihost import multihost
from orbax.checkpoint.path import step
from orbax.checkpoint._src.path import step

from orbax.checkpoint.future import Future

Expand Down
2 changes: 1 addition & 1 deletion checkpoint/orbax/checkpoint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from orbax.checkpoint import version
# TODO(cpgaffney): Import the public multihost API.
from orbax.checkpoint._src.multihost import multihost
from orbax.checkpoint.path import step
from orbax.checkpoint._src.path import step

from orbax.checkpoint.future import Future

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
from orbax.checkpoint._src.handlers import async_checkpoint_handler
from orbax.checkpoint._src.metadata import tree as tree_metadata
from orbax.checkpoint._src.multihost import multihost
from orbax.checkpoint._src.path import format_utils
from orbax.checkpoint._src.serialization import serialization
from orbax.checkpoint._src.serialization import tensorstore_utils as ts_utils
from orbax.checkpoint._src.serialization import type_handlers
from orbax.checkpoint._src.tree import utils as tree_utils
from orbax.checkpoint.path import format_utils
import tensorstore as ts


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
from orbax.checkpoint._src.handlers import checkpoint_handler
from orbax.checkpoint._src.handlers import handler_registration
from orbax.checkpoint._src.handlers import proto_checkpoint_handler
from orbax.checkpoint.path import atomicity
from orbax.checkpoint.path import utils as path_utils
from orbax.checkpoint._src.path import atomicity
from orbax.checkpoint._src.path import locking

CheckpointArgs = checkpoint_args.CheckpointArgs
Future = future.Future
Expand Down Expand Up @@ -721,7 +721,7 @@ def _existing_items(self, directory: epath.Path) -> List[str]:
return [
p.name
for p in directory.iterdir()
if p.is_dir() and p != path_utils.lockdir(directory)
if p.is_dir() and p != locking.lockdir(directory)
]

def restore(
Expand Down Expand Up @@ -883,7 +883,9 @@ def close(self):
)
class CompositeArgs(Composite, CheckpointArgs):
"""Args for wrapping multiple checkpoint items together."""

...


# Returned object of CompositeCheckpointHandler is an alias of CompositeArgs.
CompositeResults = CompositeArgs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from orbax.checkpoint._src.handlers import standard_checkpoint_handler
from orbax.checkpoint._src.metadata import value as value_metadata
from orbax.checkpoint._src.multihost import multihost
from orbax.checkpoint.path import step
from orbax.checkpoint._src.path import step

CompositeArgs = composite_checkpoint_handler.CompositeArgs
JsonCheckpointHandler = json_checkpoint_handler.JsonCheckpointHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from etils import epath
from orbax.checkpoint._src import asyncio_utils
from orbax.checkpoint.path import step as step_lib
from orbax.checkpoint._src.path import step as step_lib


# TODO(b/360190539): This functionality should be provided by either an external
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
from orbax.checkpoint._src.metadata import checkpoint as checkpoint_metadata
from orbax.checkpoint._src.multihost import counters
from orbax.checkpoint._src.multihost import multihost
from orbax.checkpoint._src.path import async_utils
from orbax.checkpoint._src.path import step as step_lib
from orbax.checkpoint._src.path import utils
from orbax.checkpoint.path import async_utils
from orbax.checkpoint.path import step as step_lib


TMP_DIR_SUFFIX = step_lib.TMP_DIR_SUFFIX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from etils import epath
from orbax.checkpoint import test_utils
from orbax.checkpoint._src.multihost import multihost
from orbax.checkpoint.path import atomicity
from orbax.checkpoint.path import step as step_lib
from orbax.checkpoint._src.path import atomicity
from orbax.checkpoint._src.path import step as step_lib

AtomicRenameTemporaryPath = atomicity.AtomicRenameTemporaryPath
CommitFileTemporaryPath = atomicity.CommitFileTemporaryPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from etils import epath
import jax
from orbax.checkpoint import utils
from orbax.checkpoint.path import step as step_lib
from orbax.checkpoint._src.path import step as step_lib

_THREADED_DELETE_DURATION = (
'/jax/orbax/checkpoint_manager/threaded_checkpoint_deleter/duration'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from absl.testing import absltest
from absl.testing import parameterized
from etils import epath
from orbax.checkpoint.path import deleter as deleter_lib
from orbax.checkpoint.path import step as step_lib
from orbax.checkpoint._src.path import deleter as deleter_lib
from orbax.checkpoint._src.path import step as step_lib


class CheckpointDeleterTest(parameterized.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from orbax.checkpoint._src.handlers import pytree_checkpoint_handler
from orbax.checkpoint._src.handlers import standard_checkpoint_handler
from orbax.checkpoint._src.metadata import checkpoint as checkpoint_metadata
from orbax.checkpoint.path import format_utils
from orbax.checkpoint._src.path import format_utils



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Path utility functions for Orbax."""
"""Manages locking of checkpoint step dirs."""

# TODO(b/337137764): Add unit tests.
# TODO(b/337137764): If needed, export the functions from
Expand All @@ -24,8 +24,8 @@

from etils import epath
from orbax.checkpoint._src import asyncio_utils
from orbax.checkpoint.path import async_utils
from orbax.checkpoint.path import step as step_lib
from orbax.checkpoint._src.path import async_utils
from orbax.checkpoint._src.path import step as step_lib


_LOCK_ITEM_NAME = 'LOCKED'
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from etils import epath
from orbax.checkpoint import test_utils
from orbax.checkpoint._src.metadata import checkpoint
from orbax.checkpoint.path import atomicity
from orbax.checkpoint.path import step as step_lib
from orbax.checkpoint._src.path import atomicity
from orbax.checkpoint._src.path import step as step_lib


class StandardNameFormatTest(parameterized.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion checkpoint/orbax/checkpoint/_src/path/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Utils for snapshotting."""
"""Utils for path constructs."""

import os
import time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
from orbax.checkpoint._src.metadata import value as value_metadata
from orbax.checkpoint._src.multihost import multihost
from orbax.checkpoint._src.multihost import multislice
from orbax.checkpoint._src.path import async_utils
from orbax.checkpoint._src.path import format_utils
from orbax.checkpoint._src.serialization import serialization
from orbax.checkpoint._src.serialization import tensorstore_utils as ts_utils
from orbax.checkpoint.path import async_utils
from orbax.checkpoint.path import format_utils
import tensorstore as ts


Expand Down
4 changes: 2 additions & 2 deletions checkpoint/orbax/checkpoint/async_checkpointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
from orbax.checkpoint._src.metadata import checkpoint
from orbax.checkpoint._src.multihost import counters
from orbax.checkpoint._src.multihost import multihost
from orbax.checkpoint.path import async_utils
from orbax.checkpoint.path import atomicity
from orbax.checkpoint._src.path import async_utils
from orbax.checkpoint._src.path import atomicity


BarrierSyncFn = multihost.BarrierSyncFn
Expand Down
6 changes: 3 additions & 3 deletions checkpoint/orbax/checkpoint/checkpoint_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
from orbax.checkpoint._src.handlers import proto_checkpoint_handler
from orbax.checkpoint._src.metadata import checkpoint
from orbax.checkpoint._src.multihost import multihost
from orbax.checkpoint._src.path import atomicity
from orbax.checkpoint._src.path import deleter
from orbax.checkpoint._src.path import step as step_lib
from orbax.checkpoint._src.path import utils as path_utils
from orbax.checkpoint.logging import abstract_logger
from orbax.checkpoint.logging import standard_logger
from orbax.checkpoint.logging import step_statistics
from orbax.checkpoint.path import atomicity
from orbax.checkpoint.path import deleter
from orbax.checkpoint.path import step as step_lib
from typing_extensions import Self # for Python version < 3.11


Expand Down
2 changes: 1 addition & 1 deletion checkpoint/orbax/checkpoint/checkpoint_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
from orbax.checkpoint import utils
from orbax.checkpoint._src.metadata import value as value_metadata
from orbax.checkpoint._src.multihost import multihost
from orbax.checkpoint._src.path import step as step_lib
from orbax.checkpoint._src.path.snapshot import snapshot as snapshot_lib
from orbax.checkpoint._src.serialization import type_handlers
from orbax.checkpoint.path import step as step_lib


PyTree = Any
Expand Down
2 changes: 1 addition & 1 deletion checkpoint/orbax/checkpoint/checkpoint_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from orbax.checkpoint import utils
from orbax.checkpoint._src.handlers import pytree_checkpoint_handler
from orbax.checkpoint._src.metadata import value as value_metadata
from orbax.checkpoint.path import step as step_lib
from orbax.checkpoint._src.path import step as step_lib


RestoreArgs = pytree_checkpoint_handler.RestoreArgs
Expand Down
2 changes: 1 addition & 1 deletion checkpoint/orbax/checkpoint/checkpointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from orbax.checkpoint._src.handlers import composite_checkpoint_handler
from orbax.checkpoint._src.metadata import checkpoint
from orbax.checkpoint._src.multihost import multihost
from orbax.checkpoint.path import atomicity
from orbax.checkpoint._src.path import atomicity
from typing_extensions import Self # for Python version < 3.11


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
from orbax.checkpoint._src.multihost import counters
from orbax.checkpoint._src.multihost import multihost
from orbax.checkpoint._src.multihost import multislice
from orbax.checkpoint._src.path import step as step_lib
from orbax.checkpoint._src.serialization import type_handlers
from orbax.checkpoint.experimental.emergency import multihost as emergency_multihost
from orbax.checkpoint.logging import abstract_logger
from orbax.checkpoint.logging import standard_logger
from orbax.checkpoint.logging import step_statistics
from orbax.checkpoint.path import step as step_lib
from typing_extensions import Self # for Python version < 3.11


Expand Down
23 changes: 23 additions & 0 deletions checkpoint/orbax/checkpoint/path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 The Orbax Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Defines exported symbols from orbax.checkpoint.path package."""

# pylint: disable=unused-import

from orbax.checkpoint._src.path import async_utils
from orbax.checkpoint._src.path import atomicity
from orbax.checkpoint._src.path import deleter
from orbax.checkpoint._src.path import format_utils
from orbax.checkpoint._src.path import step
2 changes: 1 addition & 1 deletion checkpoint/orbax/checkpoint/standard_checkpointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from orbax.checkpoint import options as options_lib
from orbax.checkpoint._src.handlers import standard_checkpoint_handler
from orbax.checkpoint._src.metadata import checkpoint
from orbax.checkpoint.path import atomicity
from orbax.checkpoint._src.path import atomicity


StandardCheckpointHandler = (
Expand Down
4 changes: 2 additions & 2 deletions checkpoint/orbax/checkpoint/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
from orbax.checkpoint._src.multihost import counters
from orbax.checkpoint._src.multihost import multihost
from orbax.checkpoint._src.multihost import multislice
from orbax.checkpoint._src.path import atomicity
from orbax.checkpoint._src.path import step as step_lib
from orbax.checkpoint._src.serialization import serialization
from orbax.checkpoint._src.serialization import tensorstore_utils as ts_utils
from orbax.checkpoint._src.serialization import type_handlers
from orbax.checkpoint._src.tree import utils as tree_utils
from orbax.checkpoint.path import atomicity
from orbax.checkpoint.path import step as step_lib


class MuNu(NamedTuple):
Expand Down
14 changes: 6 additions & 8 deletions checkpoint/orbax/checkpoint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import jax
import numpy as np
from orbax.checkpoint._src.multihost import multihost
from orbax.checkpoint._src.path import async_utils
from orbax.checkpoint._src.path import locking
from orbax.checkpoint._src.path import step as step_lib
from orbax.checkpoint._src.tree import utils as tree_utils
from orbax.checkpoint.path import async_utils
from orbax.checkpoint.path import step as step_lib
from orbax.checkpoint.path import utils as path_utils


TMP_DIR_SUFFIX = step_lib.TMP_DIR_SUFFIX
Expand All @@ -54,8 +54,8 @@
async_makedirs = async_utils.async_makedirs
async_write_bytes = async_utils.async_write_bytes
async_exists = async_utils.async_exists
lockdir = path_utils.lockdir
is_locked = path_utils.is_locked
lockdir = locking.lockdir
is_locked = locking.is_locked


is_gcs_path = step_lib.is_gcs_path
Expand Down Expand Up @@ -115,9 +115,7 @@ def name_from_leaf_placeholder(placeholder: str) -> str:

def all_leaves_are_placeholders(tree: PyTree) -> bool:
"""Determines if all leaves in `tree` are placeholders."""
return all(
leaf_is_placeholder(leaf) for leaf in jax.tree.leaves(tree)
)
return all(leaf_is_placeholder(leaf) for leaf in jax.tree.leaves(tree))


def pytree_structure(directory: epath.PathLike) -> PyTree:
Expand Down

0 comments on commit 2ae4542

Please sign in to comment.