Skip to content

Conversation

@Emmanuel-Arokiaraj
Copy link

@Emmanuel-Arokiaraj Emmanuel-Arokiaraj commented Nov 23, 2025

Summary

This PR fixes an issue where integer dict keys and array index keys in a
PyTree path were being converted to strings during metadata serialization
and could not be reconstructed accurately upon restore. This caused a
mismatch between saved and restored metadata, leading to failures when
loading checkpoints for structures containing numeric keys.

Related issue: #2587

Root Cause

NestedKeyMetadataEntry.from_json always interpreted nested_key_name
as a string. As a result, numeric key values like "0" or "1" were not
converted back into integers, even though they originated from numeric
PyTree paths.

Solution

  • Convert nested_key_name back to int when the JSON value is a digit-only string.
  • Updated KeyMetadataEntry.build to correctly preserve integer key types.
  • Added tests validating round-trip serialization and restoration of integer keys.

Testing

A new test was added:
orbax/checkpoint/tests/test_export_type_conversions.py

This integration test:

  • Builds a real JAX PyTree
  • Extracts key metadata
  • Serializes and deserializes it via JSON
  • Confirms that numeric indices are restored as integers

…oogle#2561)

Integer-based PyTree keys were being converted to strings during metadata
round-trip operations, causing incorrect key restoration on load.
This change ensures numeric key names are serialized and deserialized
correctly by converting digit-only strings back into integers.

Adds KeyMetadataEntry.build and NestedKeyMetadataEntry.from_json fixes
and corresponding tests verifying correct integer key reconstruction.
@google-cla
Copy link

google-cla bot commented Nov 23, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Emmanuel-Arokiaraj Emmanuel-Arokiaraj changed the title Fix integer dict key restoration in metadata serialization (#2561) Fix integer dict key restoration in metadata serialization (#2587) Nov 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant