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

Incorrect usage of PRNG #4

Open
pgenevski opened this issue Nov 22, 2022 · 1 comment
Open

Incorrect usage of PRNG #4

pgenevski opened this issue Nov 22, 2022 · 1 comment

Comments

@pgenevski
Copy link

pgenevski commented Nov 22, 2022

Hi,

I noticed that you are reusing the same key in e.g. cell 23 of main/src/notebooks/jax_tutorials/chapter_5_vmap_pmap.ipynb

key, subkey = random.split(key)
rotate = random.randint(key, shape=[batch_size], minval=0, maxval=2)

Looks like you shall be using the subkey in random.randint, not the original key. The way it is now subkey is never used.

@pgenevski
Copy link
Author

Another example is cell 24, where you are practically reusing the same key in the for loop, by doing this several times:

key=random.PRNGKey(0)

It would be better if you seed the PRNG once and split the key in every iteration as in :

key = random.PRNGKey(42)

for _ in range(3):
    key, subkey = random.split(key)
    a = random.normal(key=subkey)
    print(a)

Output:

1.3694694
-0.19947024
-2.2982783

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

No branches or pull requests

1 participant