question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Destructing DeviceArray produces Numpy arrays

See original GitHub issue

Don’t know if this is a new feature or a bug. Destructing a DeviceArray is resulting in its pieces being converted to Numpy arrays:

import jax
import jax.numpy as jnp

key = jax.random.PRNGKey(0)
key1, key2 = jax.random.split(key)

assert not isintance(key1, jnp.ndarray)
assert not isintance(key2, jnp.ndarray)

This is surprising given this pattern with split is used extensively in the docs. Now it seems you have to do this:

key = jax.random.PRNGKey(0)
splits = jax.random.split(key)
key1, key2 = splits[0], splits[1]

assert isintance(key1, jnp.ndarray)
assert isintance(key2, jnp.ndarray)

Which is less nice.

Versions:

name = "jax"
version = "0.2.21"

name = "jaxlib"
version = "0.1.71"

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jakevdpcommented, Sep 27, 2021

Yeah, the issue is much larger than split, unfortunately. We really need to get #3821 or something like it in, but it has been challenging for various reasons.

0reactions
cgarciaecommented, Sep 27, 2021

Alternatively, you can also replace jax.random.split with this:

def iter_split(key: jnp.ndarray, num: int = 2) -> tp.Tuple[jnp.ndarray, ...]:
    splits = jax.random.split(key, num)
    return tuple(splits[i] for i in range(num))
Read more comments on GitHub >

github_iconTop Results From Across the Web

List comprehensions and for-loops on xla.DeviceArrays return ...
Looping through a DeviceArray like in a list comprehension, for loop, or enumerate ... Destructing DeviceArray produces Numpy arrays #8017.
Read more >
jax.numpy package - JAX documentation - Read the Docs
Gives a new shape to an array without changing its data. resize (a, new_shape). Return a new array with the specified shape.
Read more >
Is there any way to delete the specific elements of an numpy ...
NumPy arrays are fixed-size, so there can't be an in-place version of np.delete . Any such function would have to change the array's...
Read more >
TF_JAX_tutorials - Part 4 (JAX and DeviceArray) | Kaggle
We will create two arrays, one with numpy and other with jax # to check ... dive into DeviceArray and see what makes...
Read more >
[SciPy-User] Memory Leak? Problems with deleting numpy ...
I am having some difficulty with memory management with numpy arrays. I have some c-code which creates a numpy array which is fairly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found