patrick-kidger / patrick-kidger/jaxtyping

TypeCheckError: argument "<arg name>" (jaxlib.xla_extension.ArrayImpl) is not an instance of jax._src.prng.PRNGKeyArray

Open
#78 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
1.9k
Forks
96
PR merge metrics
No merged PRs in 30d

Description

Hi, I'm having this issue in my JAX project. I'm using pyright as a static type checker and jaxtyping + typeguard for the runtime. The problem is that it seems like these two don't agree on what's the type of a random.PRNGKey. Pyright is ok if I annotate it as random.PRNGKeyArray (or random.KeyArray), but this falls at runtime due to jaxtyping. On the other hand, jaxtyping seems to be ok only if I annotate it as UInt[Array, "2"] (but pyright is not).

Right now I solved it by defining:

Key = UInt[Array, "2"] | KeyArray

But I was wondering if there is a better way.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the mismatch between pyright and jaxtyping/typeguard for JAX random.PRNGKey annotations described in the issue. Compare random.PRNGKeyArray or random.KeyArray with UInt[Array, "2"] and define done as a type annotation that satisfies both static checking and runtime checking without the reported TypeCheckError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.