You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First off - I've been thinking of almost the same idea as this library for a while because I see runtime errors from tensor shape/dtype mismatches all the time, so glad that there's already something in place!
My initial approach was going to be parsing docstrings of various formats (with an existing library like docstring_parser) and performing validation on these, rather than type annotations. Is that a feature you'd consider accepting into your library? I'd be interested in writing a PR for it with some guidance
For example, I currently write Sphinx style docstrings like this
defforward(self, imgs, tokens):
"""Combine multimodal input features :param torch.FloatTensor[N, C, H, W] imgs: Batch of image pixels normalized in range of 0-1 :param torch.LongTensor[N, L] tokens: Vocabularly tokens in sequence of length ``L`` :return torch.FloatTensor[N, C] pred: Predicted probabilities for each class """
I realize the [N, C, H, W] notation is not quite as rigid as what this project proposes, and that's one reason I've been looking for a more structured approach. But regardless, I do find it nice sometimes to have this information in the docstrings instead of type annotations, particularly for functions with many parameters
The text was updated successfully, but these errors were encountered:
Hmm. Unless there's a big outcry from lots of people wanting this feature, then I'm inclined to keep things as-is just for simplicity.
However I expect it should be possible for you to piggy-back off of torchtyping and write your own library that does this. Parse the docstring, and then set __annotations__ appropriately, and then torchtyping/typeguard will take it from there. WDYT?
First off - I've been thinking of almost the same idea as this library for a while because I see runtime errors from tensor shape/dtype mismatches all the time, so glad that there's already something in place!
My initial approach was going to be parsing docstrings of various formats (with an existing library like docstring_parser) and performing validation on these, rather than type annotations. Is that a feature you'd consider accepting into your library? I'd be interested in writing a PR for it with some guidance
For example, I currently write Sphinx style docstrings like this
I realize the
[N, C, H, W]
notation is not quite as rigid as what this project proposes, and that's one reason I've been looking for a more structured approach. But regardless, I do find it nice sometimes to have this information in the docstrings instead of type annotations, particularly for functions with many parametersThe text was updated successfully, but these errors were encountered: