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

Sort devices explicitly by process index, then id (as opposed to IDs alone). IDs may be randomly generated, and are not guaranteed to be ordered based on their process index. #996

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion checkpoint/orbax/checkpoint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ def is_scalar(x):
return isinstance(x, (int, float, np.number))


def _shard_sort_device_key(shard_data):
d = list(shard_data.devices())[0]
return (d.process_index, d.id)


def fully_replicated_host_local_array_to_global_array(
arr: jax.Array,
) -> jax.Array:
Expand All @@ -184,7 +189,7 @@ def fully_replicated_host_local_array_to_global_array(
# pmap-produced Array has a "scrambled" device order.
dbs = sorted(
[shard.data for shard in arr.addressable_shards],
key=lambda x: list(x.devices())[0].id,
key=_shard_sort_device_key
)
return jax.make_array_from_single_device_arrays(
global_shape, jax.sharding.NamedSharding(mesh, partition_spec), dbs
Expand Down
Loading