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

[Opinfo] Better ErrorMsg for test_out with wrong shape #56023

Open
ejguan opened this issue Apr 14, 2021 · 1 comment
Open

[Opinfo] Better ErrorMsg for test_out with wrong shape #56023

ejguan opened this issue Apr 14, 2021 · 1 comment
Labels
module: tests Issues related to tests (not the torch.testing module) triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@ejguan
Copy link
Contributor

ejguan commented Apr 14, 2021

While I implement Opinfo for inner #55536, the SkipInfo is added due to AssertionError: UserWarning not triggered : Resized a non-empty tensor but did not warn about it.

We assume the output tensor with wrong shape will be resized into expected shape

pytorch/test/test_ops.py

Lines 614 to 627 in b1d17bc

def _case_two_transform(t):
wrong_shape = list(t.shape)
if len(wrong_shape) == 0:
# Handles scalar tensor case (empty list)
wrong_shape = [2]
else:
wrong_shape[-1] = wrong_shape[-1] + 1
return make_tensor(wrong_shape, dtype=t.dtype, device=t.device)
out = _apply_out_transform(_case_two_transform, expected)
msg_fail = "Resized a non-empty tensor but did not warn about it."
with self.assertWarnsRegex(UserWarning, "An output with one or more elements", msg=msg_fail):
op_out(out=out)

But torch.inner doesn't resize the output tensor as we expected, even if it's a bug (reported #56022).

>>> a = torch.randn(5)
>>> b = torch.randn(5)
>>> torch.inner(a, b)
tensor(-4.2595)
>>> c = torch.randn(2)
>>> torch.inner(a, b, out=c)
tensor([-4.2595, -4.2595])

We should have a better error message in this case like raising an error of Output tensor is not resized as expect rather than assertion for resizing.

cc @mruberry @VitalyFedyunin @walterddr

@ejguan ejguan added the module: tests Issues related to tests (not the torch.testing module) label Apr 14, 2021
@mruberry
Copy link
Collaborator

mruberry commented Apr 14, 2021

Thank you for filing this issue, @ejguan. So torch.inner() broadcasts to out=!? This is a great bug. And thank you for filing an issue for the test and the operation.

@mruberry mruberry added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: tests Issues related to tests (not the torch.testing module) triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

2 participants