Skip to content
Closed
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: 2 additions & 4 deletions drjax/_src/impls.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ def call_jaxpr(fn, arg):

# TODO(b/366437841): Remove use of pxla.thread_resources.env.physical_mesh,
# which is a JAX internal API.
def _global_mesh() -> jax.sharding.Mesh | jax.sharding.AbstractMesh | None:
def _global_mesh() -> jax.sharding.Mesh | None:
"""Returns the JAX global mesh if installed, or `None` otherwise."""
jax_global_mesh = jax.sharding.get_abstract_mesh()
if jax_global_mesh is None or jax_global_mesh.empty:
jax_global_mesh = pxla.thread_resources.env.physical_mesh
jax_global_mesh = pxla.thread_resources.env.physical_mesh
return None if jax_global_mesh.empty else jax_global_mesh


Expand Down
23 changes: 0 additions & 23 deletions drjax/_src/impls_sharding_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,6 @@ def test_broadcast_with_1x1_fully_replicates(self, mesh_as_context):
# replicated.
self.assertTrue(sharding.is_fully_replicated)

def test_broadcast_clients_with_jax_use_mesh(self):
global_mesh = create_global_mesh(
[_CLIENTS_AXIS_SIZE, _DATA_AXIS_SIZE], [_CLIENTS_AXIS, _DATA_AXIS]
)
arg = jnp.zeros(shape=[_DATA_SIZE])
with jax.sharding.use_mesh(global_mesh):
result = self._comp_factory.broadcast_to_placement(
arg,
_CLIENTS_AXIS,
)
self.assertEqual(result.shape, (_NUM_CLIENTS, _DATA_SIZE))
sharding = result.sharding
# If this sharding were fully replicated, we would be *replicating* the data
# on each chip, rather than putting half of the clients' broadcasted arrays
# on one set of client chips and half on the other.
self.assertFalse(sharding.is_fully_replicated)
# Each shard should host half the clients, but the arg's original dimension
# should be replicated.
self.assertEqual(
sharding.shard_shape(result.shape),
(_NUM_CLIENTS // _CLIENTS_AXIS_SIZE, _DATA_SIZE),
)

@parameterized.parameters(True, False)
def test_broadcast_clients_shards_along_clients(self, mesh_as_context):
global_mesh = create_global_mesh(
Expand Down
Loading