[Documentation] Push `jaxtyping` over `torchtyping` for type-checking PyTorch tensors
See original GitHub issueHi. I was trying to use beartype
as a drop-in replacement for typeguard
with torchtyping
.
from torch import rand
from torchtyping import TensorType, patch_typeguard
from typeguard import typechecked
patch_typeguard()
@typechecked
def func(x: TensorType["batch"],
y: TensorType["batch"]) -> TensorType["batch"]:
return x + y
func(rand(3), rand(1))
This raises the expected error.
TypeError: Dimension 'batch' of inconsistent size. Got both 1 and 3.
but it doesn’t work. Should we manually write patch_beartype
like patch_typeguard
?
from torch import rand
from torchtyping import TensorType
from beartype import beartype
@beartype
def func(x: TensorType["batch"],
y: TensorType["batch"]) -> TensorType["batch"]:
return x + y
func(rand(3), rand(1))
Issue Analytics
- State:
- Created 10 months ago
- Reactions:2
- Comments:8 (3 by maintainers)
Top Results From Across the Web
patrick-kidger/torchtyping - GitHub
Type annotations and dynamic checking for a tensor's shape, dtype, names, etc. ... If you use JAX instead of PyTorch, then see jaxtyping....
Read more >[P] torchtyping -- documentation + runtime type checking of ...
I'm excited to announce torchtyping, as a way to document -- and check -- that PyTorch tensors have the correct shape (dtype, names,...
Read more >torch.Tensor — PyTorch 1.13 documentation
Torch defines 10 tensor types with CPU and GPU variants which are as follows: ... T() on tensors of dimension other than 2...
Read more >Patrick Kidger (fosstodon.org/@PatrickKidger) on Twitter: "So I ...
So I've made a library - "torchtyping" - for annotating a PyTorch Tensor's shape (dtype, names, layout, ...) And at runtime it checks...
Read more >Torchtyping: Type Annotations for A Tensor's Shape, Dtype ...
EXAMPLE from torch import rand from torchtyping import TensorType, patch_typeguard from typeguard import typechecked patch_typeguard() # use before ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Update: as a quick hack to make things easier, the latest version (0.2.9) of
jaxtyping
should now no longer have JAX as a mandatory dependency.If JAX is installed then the
jaxtyping.{Array, PyTree}
types will exist. If it isn’t, then they won’t. Either way theFloat, Int
etc. types will exist and should work with PyTorch tensors.Choice of name aside, this should mean that
jaxtyping
is now backend-independent.Yup, I’ve been thinking about how best to handle backend agnosticism. I’ve got some plans on that front, and when/if I get more time then I’d like to revisit this.