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: 582591010
  • Loading branch information
hawkinsp authored and copybara-github committed Nov 15, 2023
1 parent 218bead commit 70f26ec
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion chirp/train/train_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def compute(self):
A dictionary mapping metric names to compute values, which can either
be scalars/arrays or another dictionary of computed metrics.
"""
with jax.default_device(jax.devices('cpu')[0]):
with jax.default_device(jax.local_devices(backend='cpu')[0]):
values = super().compute()
return {
metric_name: metric[1](*(values[name] for name in metric[0]))
Expand Down

0 comments on commit 70f26ec

Please sign in to comment.