Skip to content

Commit

Permalink
[JAX] Replace uses of jax.devices("cpu") with jax.local_devices(backe…
Browse files Browse the repository at this point in the history
…nd="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
  • Loading branch information
hawkinsp authored and Copybara-Service committed Nov 16, 2023
1 parent 53eeda3 commit 1177501
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions acme/agents/jax/pwil/rewarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1177501

Please sign in to comment.