You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that, even if a function is JITed with backend="cpu", I can pass an array in gpu to it, and vice versa. I have questions on this behavior.
Let me call the device specified at JIT A and the device of the input B. What happens when A and B are different? It seems like returned values are in A, not in B. Is the input copied to A? Does the actual computation of the function happen in A?
This behavior is unexpected to me. Are there any performance-related concerns when this happens? Is there a way to detect when this happens or prevent it?
importjaxprint(jax.__version__, jax.default_backend())
deff(x):
returnx**2fc=jax.jit(f, backend="cpu")
fg=jax.jit(f, backend="gpu")
xc=jax.device_put(jnp.arange(3), device=jax.devices("cpu")[0])
xg=jax.device_put(jnp.arange(3), device=jax.devices("gpu")[0])
# must be okfcxc=fc(xc)
print(fcxc, fcxc.device())
fgxg=fg(xg)
print(fgxg, fgxg.device())
# run without error, but what is happening?fcxg=fc(xg)
print(fcxg, fcxg.device())
fgxc=fg(xc)
print(fgxc, fgxc.device())
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I noticed that, even if a function is JITed with backend="cpu", I can pass an array in gpu to it, and vice versa. I have questions on this behavior.
Beta Was this translation helpful? Give feedback.
All reactions