Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jax tensors are not correctly recognized if they are stored on GPUs #31

Merged
merged 2 commits into from
Apr 15, 2021

Conversation

zimmerrol
Copy link
Contributor

I noticed that the conversion of ndarrays in JAX to JAXTensors in eagerpy does not work on machines with GPUs, since here JAX will use the jaxlib namespace to represent the array s(as DeviceArrays) instead of the normal jax namespace. This PR adds jaxlib as an alias to detect JAX tensors.

@codecov
Copy link

codecov bot commented Apr 9, 2021

Codecov Report

Merging #31 (b2b48c9) into master (850a905) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #31   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        16           
  Lines         1753      1753           
=========================================
  Hits          1753      1753           
Impacted Files Coverage Δ
eagerpy/astensor.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 850a905...b2b48c9. Read the comment docs.

@jonasrauber
Copy link
Owner

jonasrauber commented Apr 10, 2021

Apparently, this was changed in a recent JAX version. In 0.1.70 it is jax.interpreters.xla.DeviceArray, in 0.2.12 it is jaxlib.xla_extension.DeviceArray.

But let's just add it to the existing if to simplify testing: if (name == "jax" or name == "jaxlib") and

@zimmerrol
Copy link
Contributor Author

@jonasrauber I think this doesn't work because of the isinstance check in the same line (

if name == "jax" and isinstance(x, m[name].numpy.ndarray): # type: ignore
)

This check only works if name="jax" since there is no class jaxlib.numpy.ndarray. So should we change this line to?:

if (name == "jax" or name == "jaxlib") and isinstance(x, m["jax"].numpy.ndarray):

@jonasrauber
Copy link
Owner

jonasrauber commented Apr 14, 2021

So should we change this line to?:

Yes 👍

@jonasrauber jonasrauber merged commit 4656839 into jonasrauber:master Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants