Skip to content

Commit d72bd65

Browse files
hawkinspcopybara-github
authored andcommitted
[JAX] Replace uses of jax.devices("cpu") with jax.local_devices(backend="cpu").
An upcoming change to JAX will include non-local (addressable) CPU devices in jax.devices() when JAX is used multicontroller-style, where there are multiple Python processes. This change preserves the current behavior by replacing uses of jax.devices("cpu"), which previously only returned local devices, with jax.local_devices("cpu"), which will return local devices both now and in the future. This change is always be safe (i.e., it should always preserve the previous behavior) but it may sometimes be unnecessary if code is never used in a multicontroller setting. PiperOrigin-RevId: 582544519
1 parent 38adb83 commit d72bd65

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

trax/layers/acceleration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def f(x):
208208
def _accelerate(f, n_devices):
209209
"""Returns an accelerated version of ``f`` running on ``n_devices``."""
210210
if n_devices == 0: # no accelerators - run on CPU
211-
return fastmath.jit(f, device=jax.devices('cpu')[0])
211+
return fastmath.jit(f, device=jax.local_devices(backend='cpu')[0])
212212

213213
if n_devices == 1:
214214
return fastmath.jit(f)
@@ -248,7 +248,7 @@ def f(x):
248248
def on_cpu(x):
249249
"""Puts ``x`` in CPU memory in JAX."""
250250
if fastmath.is_backend(fastmath.Backend.JAX):
251-
return jax.device_put(x, jax.devices('cpu')[0])
251+
return jax.device_put(x, jax.local_devices(backend='cpu')[0])
252252
else:
253253
return x
254254

0 commit comments

Comments
 (0)