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: 582427794
  • Loading branch information
hawkinsp authored and copybara-github committed Nov 14, 2023
1 parent 2b3c7a1 commit 704f9f6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion baselines/jft/active_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ def compute_batch_outputs(params, images):
batch_output = compute_batch_outputs(opt_repl.target, batch['image'])

# This moves the batch_output from TPU to CPU right away.
batch_output = jax.device_put(batch_output, jax.devices('cpu')[0])
batch_output = jax.device_put(
batch_output, jax.local_devices(backend='cpu')[0]
)

# TODO(joost,andreas): if we run on multi host, we need to index
# batch_outputs: batch_outputs[0]
Expand Down

0 comments on commit 704f9f6

Please sign in to comment.