From 1177501df180edadd9f125cf5ee960f74bff64af Mon Sep 17 00:00:00 2001 From: Peter Hawkins Date: Thu, 16 Nov 2023 09:33:29 -0800 Subject: [PATCH] [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: 583072300 Change-Id: I128aa11d48a8dd89103dbec6f273e19963820b77 --- acme/agents/jax/pwil/rewarder.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/acme/agents/jax/pwil/rewarder.py b/acme/agents/jax/pwil/rewarder.py index b94a41bdfc..e12a4edabc 100644 --- a/acme/agents/jax/pwil/rewarder.py +++ b/acme/agents/jax/pwil/rewarder.py @@ -63,8 +63,10 @@ def __init__(self, self._std = (self._std < 1e-6) + self._std self.expert_atoms = self._vectorized_demonstrations / self._std - self._compute_norm = jax.jit(lambda a, b: jnp.linalg.norm(a - b, axis=1), - device=jax.devices('cpu')[0]) + self._compute_norm = jax.jit( + lambda a, b: jnp.linalg.norm(a - b, axis=1), + device=jax.local_devices(backend='cpu')[0], + ) def _vectorize(self, demonstrations_it: Iterator[types.Transition]) -> np.ndarray: