Skip to content

Commit 25e83aa

Browse files
angel-coreOrbax Authors
authored andcommitted
#v1 Refactor logic for handler resolution and loading checkpointables + additional fallback capabilities for non-standard checkpoint formats.
PiperOrigin-RevId: 869904948
1 parent cf5a1ce commit 25e83aa

File tree

14 files changed

+598
-509
lines changed

14 files changed

+598
-509
lines changed

checkpoint/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2626
`load_checkpointables()` each with their own dedicated loading logic
2727
- Refactor v0 Pytree validation and metadata resolution and add `OrbaxV0Layout`
2828
tests
29+
- Refactor `CompositeHandler` logic into the orbax layout objects and handler
30+
resolution utility, deprecating and deleting the `CompositeHandler` class.
2931

3032
## [0.11.32] - 2026-01-20
3133

checkpoint/orbax/checkpoint/experimental/v1/_src/handlers/composite_handler.py

Lines changed: 0 additions & 325 deletions
This file was deleted.

checkpoint/orbax/checkpoint/experimental/v1/_src/handlers/registration.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def resolve_handler_for_load(
444444
abstract_checkpointable: Any | None,
445445
*,
446446
name: str,
447-
handler_typestr: str,
447+
handler_typestr: str | None = None,
448448
) -> CheckpointableHandler:
449449
"""Resolves a :py:class:`~.v1.handlers.CheckpointableHandler` for loading.
450450
@@ -492,15 +492,16 @@ def is_handleable_fn(
492492
handler_types.typestr(type(handler)) for handler in possible_handlers
493493
]
494494

495-
try:
496-
idx = possible_handler_typestrs.index(handler_typestr)
497-
return possible_handlers[idx]
498-
except ValueError:
499-
logging.warning(
500-
'No handler found for typestr %s. The checkpointable may be restored'
501-
' with different handler logic than was used for saving.',
502-
handler_typestr,
503-
)
495+
if handler_typestr:
496+
try:
497+
idx = possible_handler_typestrs.index(handler_typestr)
498+
return possible_handlers[idx]
499+
except ValueError:
500+
logging.warning(
501+
'No handler found for typestr %s. The checkpointable may be restored'
502+
' with different handler logic than was used for saving.',
503+
handler_typestr,
504+
)
504505

505506
# Prefer the first handler in the absence of any other information.
506507
return possible_handlers[-1]

checkpoint/orbax/checkpoint/experimental/v1/_src/handlers/registration_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,17 @@ def test_resolve_handler_for_load_checkpointable(self):
284284
handler_typestr='unused',
285285
)
286286

287+
def test_resolve_handler_for_load_no_handler_typestr(self):
288+
local_registry = registration.local_registry()
289+
local_registry.add(handler_utils.FooHandler)
290+
with self.assertRaises(registration.NoEntryError):
291+
registration.resolve_handler_for_load(
292+
local_registry,
293+
handler_utils.Foo(1, 'hi'),
294+
name='unregistered_name',
295+
handler_typestr=None,
296+
)
297+
287298

288299
if __name__ == '__main__':
289300
absltest.main()

0 commit comments

Comments
 (0)