Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions pathwaysutils/reshard.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ def reshard_generic(
for index, (arr, dst_sharding) in enumerate(zip(flat_x, flat_sharding)):
if not isinstance(dst_sharding, jax.sharding.Sharding):
raise ValueError("`sharding` must contain only `jax.sharding.Sharding`")
if not isinstance(arr, jax.Array) or (
hasattr(arr, "dtype")
and jax.dtypes.issubdtype(arr.dtype, jax.dtypes.prng_key)
if not isinstance(arr, jax.Array) or jax.dtypes.issubdtype(
arr.dtype, jax.dtypes.prng_key
):
non_reshardable_arrays["arrays"].append(arr)
non_reshardable_arrays["indices"].append(index)
Expand Down Expand Up @@ -212,6 +211,7 @@ def _get_split_candidates(
if (
gcd_shards[i] == 1
and src_dims[i] > dst_dims[i]
and src_dims[i] % dst_dims[i] == 0
and isinstance(spec, str)
):
split_candidates.append((i, spec))
Expand Down
13 changes: 13 additions & 0 deletions pathwaysutils/test/reshard_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,18 @@ def test_ifrt_reshard_pytree(self):
self.assertLen(args[0], 2)
self.assertLen(args[1], 2)

def test_find_intermediate_sharding_rejects_indivisible_candidate(self):
# src_dims=[8, 3], dst_dims=[3, 4], gcd_shards=[1, 1] -> src_dims[0] % dst_dims[0] != 0
in_sharding = mock.MagicMock(spec=jax.sharding.NamedSharding)
in_sharding.spec = jax.sharding.PartitionSpec("x", "y")
with self.assertRaises(reshard.NoIntermediateShardingError):
reshard._get_split_candidates(
in_sharding,
src_dims=[8, 3],
dst_dims=[3, 4],
gcd_shards=[1, 1],
)


if __name__ == "__main__":
absltest.main()
Loading