patrick-kidger / patrick-kidger/jaxtyping

Dimension changing

Open
#264 2 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

import beartype
import torch

from jaxtyping import Float, jaxtyped
from torch import Tensor


@beartype.beartype
class Identity(torch.nn.Module):
    @jaxtyped(typechecker=beartype.beartype)
    def forward(self, x: Float[Tensor, "batch d_model"]):
        return x


@jaxtyped(typechecker=beartype.beartype)
def main():
    model = Identity()

    x = torch.ones((4, 1), dtype=torch.float)
    model(x)

    x = torch.ones((6, 1), dtype=torch.float)
    model(x)  # <- Throws an error about "batch" not matching.


if __name__ == "__main__":
    main()

Not sure why this is happening. But this second call to model.forward will complain because "batch" has changed between calls. How can I fix this?

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

Reproduce the provided Python example using the Identity.forward entry point, jaxtyped, beartype, and PyTorch tensors. Read the shape-checking behavior around the named dimensions and determine why changing the batch size across calls raises an error. Done means the intended batch-size change is either supported or clearly documented with a working fix or explanation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.