patrick-kidger / patrick-kidger/jaxtyping

will runtime type checking go beyond function parameters and return type?

Open
#153 16 comments 1 reaction 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

Great project, helps me understand DL code a lot.

I used it like this:

Patch_embed = Float32[torch.Tensor, f"B {PATCH_H} {PATCH_W} {PATCH_EMBED_DIM}"] 
Mlp_mid = Float32[torch.Tensor, f"B {PATCH_H} {PATCH_W} {MLP_HIDDEN}"]

...

    @jaxtyped(typechecker=beartype)
    def forward(self, x: Patch_embed) -> Patch_embed:
        x: Mlp_mid = self.act(self.lin1(x))
        return self.lin2(x)

but turns out, it doesn't do runtime type check on this x: Mlp_mid = self.act(self.lin1(x)) line. And this makes me feel insecure.
So, my question is, will this feature be added in the future? Or is it in confilct with some design intention?

BTW, I mainly use it when I am trying to understand others code. But can I include it in production? How much does it slow down the training and inference?

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

The report names @jaxtyped(typechecker=beartype), local variable annotations, and PyTorch examples, but no source file or test. Start by reviewing the runtime-checking behavior around that decorator and local assignments. Done would require a clear decision on whether local annotations should be checked, plus documented production overhead and design intent.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.