patrick-kidger / patrick-kidger/jaxtyping
Dimension changing
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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