Skip to content

[shard-map] in eager shmap, handle all rep rule output cases #27797

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

Merged
merged 1 commit into from
Apr 7, 2025
Merged
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
3 changes: 2 additions & 1 deletion jax/experimental/shard_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,8 @@ def process_primitive(self, prim, tracers, params):
rep_rule = _check_rules.get(prim, partial(_rule_missing, prim))
out_rep = rep_rule(self.mesh, *in_rep, **params) if self.check else set()
if prim.multiple_results:
out_rep = [out_rep] * len(out_vals) if type(out_rep) is set else out_rep
out_rep = (out_rep if isinstance(out_rep, (list, tuple))
else [out_rep] * len(out_vals))
return map(partial(ShardMapTracer, self), out_rep, out_vals)
return ShardMapTracer(self, out_rep, out_vals)

Expand Down
13 changes: 13 additions & 0 deletions tests/shard_map_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,19 @@ def f3():
f3()
jax.jit(f3)()

def test_multiple_result_primitive_with_none_sharding(self):
# https://github.com/jax-ml/jax/issues/27673
xs = jnp.arange(20).reshape(2, 10)
mesh = jtu.create_mesh((2,), ("i",))
y = shard_map(
lambda x: jnp.split(x.squeeze(), 2),
mesh=mesh,
in_specs=(None,),
out_specs=P("i"),
)(xs)
expected = jnp.repeat(xs, 2, axis=0).reshape(2, 2, 10)
self.assertArraysEqual(y, expected)

def test_vmap_spmd_axis_name(self):
mesh = jtu.create_mesh((2, 2), ('x', 'y'))

Expand Down
Loading