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

Mypy error from next_rng_key type inconsistency with jax PRNGKeyArray #578

Open
hylkedonker opened this issue Nov 30, 2022 · 0 comments
Open

Comments

@hylkedonker
Copy link

Hi,

It seems that my mypy (version 0.942) is complaining that Haiku's random key generated by hk.next_rng_key() is not compatible with Jax's PRNGKeyArray type. The latter are the types of the key argument in various jax.random samplers.

Example

import jax
import haiku as hk

def sample_phi(alpha: float):
    phi = jax.random.gamma(hk.next_rng_key(), a=alpha)
    return phi

Error

example.py:5: error: Argument 1 to "gamma" has incompatible type "ndarray"; expected "Union[Array, PRNGKeyArray]"

Apart from explicitly silencing these errors in mypy, are there any other suggestions to fix these errors?

Thanks in advance,

Hylke

Environment

dm-haiku==0.0.9
jax==0.3.25
jaxlib==0.3.25
mypy==0.942
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