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

Allow pluggable PRNG implementations #5081

Closed
hawkinsp opened this issue Dec 2, 2020 · 6 comments · Fixed by #6899
Closed

Allow pluggable PRNG implementations #5081

hawkinsp opened this issue Dec 2, 2020 · 6 comments · Fixed by #6899
Assignees
Labels
enhancement New feature or request P1 (soon) Assignee is working on this now, among other tasks. (Assignee required)

Comments

@hawkinsp
Copy link
Collaborator

hawkinsp commented Dec 2, 2020

Currently we use ThreeFry2x32 as our PRNG, but it has an uncomfortably small key space (2^64).

An easy way to improve this would be to use the 4x32 variant of ThreeFry instead which has a key space of size 2^128.

@hawkinsp hawkinsp added the enhancement New feature or request label Dec 2, 2020
@jakevdp
Copy link
Collaborator

jakevdp commented Dec 2, 2020

This sounds fun...

For backward compatibility, do you think it might make sense to implement this beside the current approach (e.g. with jax.random.PRNGKey4() or something similar?)

@jakevdp
Copy link
Collaborator

jakevdp commented Dec 2, 2020

Or maybe better, a keysize keyword to PRNGKey that defaults to 2, and can optionally be set to 4, with the intention of eventually changing the default?

@hawkinsp
Copy link
Collaborator Author

hawkinsp commented Dec 2, 2020

I was thinking that perhaps we would do something like PRNGKey(..., algorithm=THREEFRY4x32) to allow for the possiblity we might want to support other PRNGs.

@NeilGirdhar
Copy link
Contributor

#2294 might be related? It would allow you to make this change more transparently since no code would assume a key size; it would be hidden behind the opaque object.

@hawkinsp hawkinsp changed the title Switch default PRNG to ThreeFry4x32 Allow pluggable PRNG implementations May 7, 2021
@hawkinsp
Copy link
Collaborator Author

hawkinsp commented May 7, 2021

Generalizing this issue: we should allow pluggable PRNG bit generators (e.g., Philox on GPU).

@froystig froystig self-assigned this May 18, 2021
@froystig froystig added the P1 (soon) Assignee is working on this now, among other tasks. (Assignee required) label Jun 8, 2021
@froystig
Copy link
Member

froystig commented Aug 20, 2021

#6899 allows for custom PRNG implementations. Filed #7676 to follow up and use it to add a wide PRNG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P1 (soon) Assignee is working on this now, among other tasks. (Assignee required)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants