What's the role of PRNGKey in Haiku transforms? #8252
-
I have seen Haiku transforms where we have the provision of adding an optional PRNGKey. I wonder what job does it serve? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
In JAX prng keys are used to create random samples. You can find out more about them in this guide. In Haiku, You can haiku given rng keys for any purpose you prefer, but typically rng keys are required for PS feel free to open haiku specific questions on the dm-haiku github page. |
Beta Was this translation helpful? Give feedback.
In JAX prng keys are used to create random samples. You can find out more about them in this guide.
In Haiku,
hk.transform
(and the variants of it) produce two functions:init
andapply
. Both of these functions accept random keys, and Haiku then makes new keys available inside your function viahk.next_rng_key()
.You can haiku given rng keys for any purpose you prefer, but typically rng keys are required for
init
since initial parameter values are random samples, and occasionally needed inapply
when you need random samples as part of your forward pass (e.g. for dropout layers).PS feel free to open haiku specific questions on the dm-haiku github page.