Git Product home page Git Product logo

Comments (3)

patrick-kidger avatar patrick-kidger commented on July 28, 2024

Hmm, this looks like an upstream bug in JAX. I'd suggest opening an issue over there.

Here's a minimal repro without using jaxtyping:

import beartype
import jax


# Fails at static type-checking time
def f(x: jax.Array):
    pass

f(jax.random.PRNGKey(0))
# pyright says:
# Argument of type "KeyArray" cannot be assigned to parameter "x" of type "Array" in function "f"


# Fails at runtime
@beartype.beartype
def g(x: jax.random.KeyArray):
    pass

g(jax.random.PRNGKey(0))
# beartype.roar.BeartypeCallHintParamViolation: @beartyped __main__.g() parameter x="Array([0, 0], dtype=uint32)" violates type hint <class 'jax._src.prng.PRNGKeyArray'>, as <protocol "jaxlib.xla_extension.ArrayImpl"> "Array([0, 0], dtype=uint32)" not instance of <class "jax._src.prng.PRNGKeyArray">

The problem being (as you've found) that neither annotation is correct in all cases.

from jaxtyping.

SalamanderXing avatar SalamanderXing commented on July 28, 2024

Thank you! It seems like the issue is already there in the JAX repo:
#google/jax#12706
and indeed it's recommended to use type union for now.

from jaxtyping.

patrick-kidger avatar patrick-kidger commented on July 28, 2024

For anyone else coming across this: use jaxtyping.PRNGKeyArray and you should be good-to-go.

from jaxtyping.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.