Skip to content

Conversation

walterddr
Copy link
Contributor

@walterddr walterddr commented Sep 21, 2020

this fixes #42983.

@dr-ci
Copy link

dr-ci bot commented Sep 21, 2020

💊 CI failures summary and remediations

As of commit c78539d (more details on the Dr. CI page):


  • 2/2 failures possibly* introduced in this PR
    • 2/2 non-CircleCI failure(s)

Extra GitHub checks: 1 failed


codecov.io: 1 failed


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 33 times.

@walterddr walterddr force-pushed the gh/walterddr/type_check_testing_internal_3 branch 2 times, most recently from e6fae89 to c23ca86 Compare September 22, 2020 04:37
@walterddr walterddr changed the title initial commit for type checking on tensor.py Enable torch.tensor typechecks Sep 22, 2020
@walterddr walterddr force-pushed the gh/walterddr/type_check_testing_internal_3 branch from c23ca86 to f4e8106 Compare September 22, 2020 15:26
several ignores are put in due to limitation on mypy
@walterddr walterddr force-pushed the gh/walterddr/type_check_testing_internal_3 branch from f4e8106 to 8c82951 Compare September 22, 2020 16:01
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@walterddr has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@codecov
Copy link

codecov bot commented Sep 22, 2020

Codecov Report

Merging #45077 into master will decrease coverage by 0.00%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #45077      +/-   ##
==========================================
- Coverage   67.83%   67.83%   -0.01%     
==========================================
  Files         384      384              
  Lines       50050    50060      +10     
==========================================
+ Hits        33953    33958       +5     
- Misses      16097    16102       +5     
Impacted Files Coverage Δ
torch/types.py 77.41% <60.00%> (-9.54%) ⬇️
torch/tensor.py 88.72% <71.42%> (+0.04%) ⬆️
torch/testing/_internal/expecttest.py 77.55% <0.00%> (-1.03%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4a0aa69...c78539d. Read the comment docs.

@walterddr walterddr marked this pull request as ready for review September 22, 2020 20:50
@walterddr walterddr requested review from malfet and ezyang September 22, 2020 20:50
@@ -536,6 +531,7 @@ def gen_pyi(declarations_path, out):
'def __init__(self, other: Tensor) -> None: ...',
'def __init__(self, size: {}, *, {}) -> None: ...'.format(type_to_python('IntArrayRef'), DEVICE_PARAM),
],
'as_subclass': ["def as_subclass(self, cls) -> Tensor: ..."],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have a more accurate type here but I won't block this PR on it.

@@ -576,6 +573,10 @@ def gen_pyi(declarations_path, out):
],
'item': ["def item(self) -> Number: ..."],
'copy_': ["def copy_(self, src: Tensor, non_blocking: _bool=False) -> Tensor: ..."],
'set_': ['def set_(self, storage: Storage, offset: _int, size: Size, stride: Tuple[_int]) -> Tensor: ...',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean Tuple[_int, ...] here; otherwise it's a single element tuple

@@ -576,6 +573,10 @@ def gen_pyi(declarations_path, out):
],
'item': ["def item(self) -> Number: ..."],
'copy_': ["def copy_(self, src: Tensor, non_blocking: _bool=False) -> Tensor: ..."],
'set_': ['def set_(self, storage: Storage, offset: _int, size: Size, stride: Tuple[_int]) -> Tensor: ...',
'def set_(self, storage: Storage) -> Tensor: ...'],
'split': ['def split(self, split_size: _int, dim: _int=0) -> Union[Tuple[Tensor, ...], List[Tensor]]: ...',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't want to specify what the return type is, just say Sequence[Tensor]. But I think we guarantee that we return a list here.

'set_': ['def set_(self, storage: Storage, offset: _int, size: Size, stride: Tuple[_int]) -> Tensor: ...',
'def set_(self, storage: Storage) -> Tensor: ...'],
'split': ['def split(self, split_size: _int, dim: _int=0) -> Union[Tuple[Tensor, ...], List[Tensor]]: ...',
'def split(self, split_size: Tuple[_int], dim: _int=0) -> Union[Tuple[Tensor, ...], List[Tensor]]: ...'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here

@ezyang
Copy link
Contributor

ezyang commented Sep 23, 2020

Some minor errors but it LGTM. There's also some small extra trailing whitespace. Thanks for doing this!

Copy link
Contributor Author

@walterddr walterddr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the review @ezyang. I will clean them up asap

@@ -528,7 +534,7 @@ def __format__(self, format_spec):
return self.item().__format__(format_spec)
return object.__format__(self, format_spec)

def __ipow__(self, other):
def __ipow__(self, other): # type: ignore[misc]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably the only issue I dont know what's the right way to fix:

apparently __ipow__ is not defined in the generated _C/__init__.pyi and in previous line __pow__ = _C._TensorBase.pow instead of _C._TensorBase.__pow__ (which is defined BTW). it got me a bit confused.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, reading the code here, it sounds like we don't implement __ipow__ (that's why we raise NotImplemented here). So it isn't unexpected that it's not defined in _C. What's the problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops. forgot to mention the problem - mypy expects identical signature between __pow__ and __ipow__ since a **= b is equivalent to a = a ** b. Yes I think we are expected to not implemented this function so I will just leave it as ignore for now.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@walterddr has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

torch/tensor.py Outdated
@@ -154,7 +160,7 @@ def __setstate__(self, state):
raise RuntimeError('__setstate__ can be only called on leaf Tensors')
if len(state) == 4:
# legacy serialization of Tensor
self.set_(*state)
self.set_(*state)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: try to avoid unnecessary trailing space

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can configure your editor to tell you about this. On vim I use set listchars=tab:>-,trail:·

@@ -576,6 +573,10 @@ def gen_pyi(declarations_path, out):
],
'item': ["def item(self) -> Number: ..."],
'copy_': ["def copy_(self, src: Tensor, non_blocking: _bool=False) -> Tensor: ..."],
'set_': ['def set_(self, storage: Storage, offset: _int, size: Size, stride: Tuple[_int, ...]) -> Tensor: ...',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this again, I don't think Tuple is the right type here, because I'm pretty sure we accept lists too here. I think using the _size type for size and stride will be more correct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_size is defined in torch.types

...

def _new_shared(self, int) -> 'Storage':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you deleting _new_shared() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was reordering them based on alphabetical order :-)

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@walterddr has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@walterddr merged this pull request in bea7901.

@facebook-github-bot facebook-github-bot deleted the gh/walterddr/type_check_testing_internal_3 branch January 27, 2021 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable torch.tensor typechecks during CI
5 participants