patrick-kidger / patrick-kidger/jaxtyping

Type hinting for `eqx.Module` created under `vmap`

Open
#320 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hello, I have something like the following pattern

import equinox as eqx
from jaxtyping import Array, Float

#
# Library code
#
class TestModule(eqx.Module):

    a: Float[Array, ""]
    b: Float[Array, "2"]

    def __init__(self, a, b):
        ...

def compute_something(vmapped_module: TestModule):
    """Specifically takes in TestModule with a batch dimension. How to type hint?"""
    ....

#
# Runtime code
#
import jax.random as jr

@eqx.filter_vmap
def make_module(a, b):
    return TestModule(a, b)

dim = 10
key = jr.key(1234)
a = jr.random.normal(key, shape=(dim,))
b = jr.random.normal(key, shape=(dim, 2))

vmapped_module  = make_module(a, b)
compute_something(vmapped_module)

How would I type hint the compute_something function, which specifically takes in a TestModule with particular batch dimensions?

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 with the TestModule, compute_something, and eqx.filter_vmap examples in the issue, then review existing jaxtyping guidance for shaped arrays and JAX or Equinox integration. Done means establishing whether a supported annotation can express the vmapped TestModule's batch dimensions and documenting or implementing the agreed approach.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.