Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TorchTyping? #71

Open
GilesStrong opened this issue Dec 3, 2021 · 0 comments
Open

Add TorchTyping? #71

GilesStrong opened this issue Dec 3, 2021 · 0 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers low priority Should be fixed eventually, but isn't urgent

Comments

@GilesStrong
Copy link
Owner

Recently I attended the PyTorch Developer event and one of the posters advertised the torchtyping package which can be used to better type-hint tensors in the code, by showing the expected dimensions with string descriptions, e.g.:

def batch_outer_product(x:   TensorType["batch", "x_channels"],
                        y:   TensorType["batch", "y_channels"]
                        ) -> TensorType["batch", "x_channels", "y_channels"]:

    return x.unsqueeze(-1) * y.unsqueeze(-2)

The dimensions of tensors can also be checked at runtime.

This is potentially useful for both developers & power-users, due to more detailed type-hinting and better diagnostics when using custom modules.

However, it is not compatible with MyPy static type-checking, meaning that TensorType must be treated as Any:

from torchtyping import TensorType  # type: ignore

Whilst not essential, replacing the Tensor type-hints in the codebase with TensorType could be useful.

@GilesStrong GilesStrong added documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers low priority Should be fixed eventually, but isn't urgent labels Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers low priority Should be fixed eventually, but isn't urgent
Projects
None yet
Development

No branches or pull requests

1 participant