Skip to content

Conversation

@Justin-Huber
Copy link
Contributor

#38349

@mruberry
Not entirely sure if all the changes are necessary in how functions are added to Pytorch.

Should it throw an error when called with a non-complex tensor? Numpy allows non-complex arrays in its imag() function which is used in its isreal() function but Pytorch's imag() throws an error for non-complex arrays.

Where does assertONNX() get its expected output to compare to?

@Justin-Huber Justin-Huber marked this pull request as draft July 11, 2020 02:21
@dr-ci
Copy link

dr-ci bot commented Jul 11, 2020

💊 CI failures summary and remediations

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


None of the CI failures appear to be your fault 💚



❄️ 1 failure tentatively classified as flaky

but reruns have not yet been triggered to confirm:

See CircleCI build pytorch_linux_xenial_cuda10_2_cudnn7_py3_gcc7_test (1/1)

Step: "Download Docker image" (full log | diagnosis details | 🔁 rerun) ❄️

9VDo2n92R6UHZ5iqk9Wijq6QqwZ6vxJZZxNAR6QcR8am8RNqxOYjGmt4ZTx9t1P4n4AueNO4Gbl67a3UVVA9baalepMQdsiEJ2xGbXES4%2BlSM%2FKt8odC3JXR6uky4MtTDUpyfd5gEFqbjcItblHQzFcchLBrOXJars0MMprQPeAbspPjAV7ZlHARBtx4EQ%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20200717T234123Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Credential=ASIAYTIFIPBEANZ7EANH%2F20200717%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=dd144fad668c078bc7a087416b119b840236a149d9f72dfb17fc6f55719ba999: net/http: TLS handshake timeout
DOCKER_IMAGE: 308535385114.dkr.ecr.us-east-1.amazonaws.com/pytorch/pytorch-linux-xenial-cuda10.2-cudnn7-py3-gcc7:ab1632df-fa59-40e6-8c23-98e004f61148-ebe1aa73751a73b302cd1fd86e0ba006696b2d4e 
Parallel backend flags:  
VDo2n92R6UHZ5iqk9Wijq6QqwZ6vxJZZxNAR6QcR8am8RNqxOYjGmt4ZTx9t1P4n4AueNO4Gbl67a3UVVA9baalepMQdsiEJ2xGbXES4%2BlSM%2FKt8odC3JXR6uky4MtTDUpyfd5gEFqbjcItblHQzFcchLBrOXJars0MMprQPeAbspPjAV7ZlHARBtx4EQ%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20200717T234123Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Credential=ASIAYTIFIPBEANZ7EANH%2F20200717%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=dd144fad668c078bc7a087416b119b840236a149d9f72dfb17fc6f55719ba999: net/http: TLS handshake timeout 

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 16 times.

@kshitij12345
Copy link
Collaborator

@Justin-Huber
Great work!

The relevant tests should be added in test_torch.py under the TestTorchDevice class, testing with all dtypes available.

To compare it against numpy you can search for the usage of self.compare_with_numpy in test_torch.py

You can use self.assertRaises to verify the expected error is raised where the dtype is not supported.

@mruberry mruberry self-requested a review July 12, 2020 07:17
@mruberry
Copy link
Collaborator

Be sure to take this out of draft and ping me when it's ready for review again.

Should it throw an error when called with a non-complex tensor? Numpy allows non-complex arrays in its imag() function which is used in its isreal() function but Pytorch's imag() throws an error for non-complex arrays.

It's OK to throw an error for now but I would add a note explaining why the error is thrown and ensure that we test the error happens. That way if someone fixes imag() they'll know to update the test.

Where does assertONNX() get its expected output to compare to?

I'm not totally sure what assertONNX does but I think it just verifies that the module can be translated to ONNX. If it compares output it probably compares the PyTorch output with the ONNX output.


@unittest.skipIf(not TEST_NUMPY, 'NumPy not found')
@dtypes(torch.float32)
def test_isreal_nan(self, device, dtype):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can remove this test and add float('nan') to the previous test if it stops comparing with NumPy.

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 separated this to declutter the noncomplex test, since we'd have to separate int from floats using NaN there.

@Justin-Huber Justin-Huber marked this pull request as ready for review July 14, 2020 17:53
@Justin-Huber
Copy link
Contributor Author

@mruberry It's ready to go. I changed the nan test case a bit to include nan and inf checks on the imaginary part of complex nums

@mruberry mruberry changed the title [WIP] Preliminary isreal() impl #38349 torch.isreal Jul 16, 2020
- func: isreal(Tensor self) -> Tensor
use_c10_dispatcher: full
variants: function, method
device_guard: False
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why set the device guard to false? Do the at::ones_like and at::imag calls set the device guard?

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 was just a copy-paste. I just checked and at::ones_like doesn't set device_guard and at::imag sets device_guard to False. What determines setting it to False?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not totally sure. In some special cases it may be OK, but I would just remove the "device_guard" line for safety.

@mruberry
Copy link
Collaborator

Hey @Justin-Huber, this looks great! Just have one question and one cleanup suggestion.

@smessmer smessmer added module: operators triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module module: complex Related to complex number support in PyTorch labels Jul 16, 2020
@Justin-Huber
Copy link
Contributor Author

Justin-Huber commented Jul 17, 2020

Not sure why the one build is failing @mruberry

@mruberry
Copy link
Collaborator

Not sure why the one build is failing @mruberry

Don't worry about it; it's a hardware failure unrelated to your PR.

@mruberry
Copy link
Collaborator

Not sure why the one build is failing @mruberry

Is this ready for another review, @Justin-Huber?

@Justin-Huber
Copy link
Contributor Author

Justin-Huber commented Jul 17, 2020

Yep! @mruberry

r"""
isreal(input) -> Tensor
Returns a new tensor with boolean elements representing if each element is real-valued or not.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"if each element of :attr:input is ..."

All real-valued types are considered real. Complex values are considered real when their imaginary part is 0.
Arguments:
input (Tensor): A tensor to check
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can just use "{input}" here and a suitable string will be autogenerated

input (Tensor): A tensor to check
Returns:
Tensor: A boolean tensor containing a True at each location of real elements.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"a boolean tensor with True where :attr:input is real-valued and False elsewhere"

Copy link
Collaborator

@mruberry mruberry left a comment

Choose a reason for hiding this comment

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

Cool! Nice work, @Justin-Huber. Just a few doc fixes which should be very easy to make and we'll get this in. Just ping me when the strings are updated.

r"""
isreal(input) -> Tensor
Returns a new tensor with boolean elements representing if each element of :attr:input is real-valued or not.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is good but you need the backticks around "input" for this (and the reference below) to format properly:

:attr:`input`

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.

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

@Justin-Huber
Copy link
Contributor Author

@mruberry Everything good to go?

@mruberry
Copy link
Collaborator

@mruberry Everything good to go?

Yep. Just has to go through the internal landing process.

@mruberry
Copy link
Collaborator

It's landed! Congrats, @Justin-Huber! Let me know if you're interested in another project.

@facebook-github-bot
Copy link
Contributor

@mruberry merged this pull request in c6d0fdd.

@Justin-Huber
Copy link
Contributor Author

Awesome! And yeah definitely, is there anything meatier?

@mruberry
Copy link
Collaborator

Awesome! And yeah definitely, is there anything meatier?

A great next step would be a function like nextafter, which likely requires writing a TensorIterator kernel. Does that sound interesting?

@Justin-Huber
Copy link
Contributor Author

Yeah definitely, could you point me to some resources on pytorch kernel's?

@mruberry
Copy link
Collaborator

Yeah definitely, could you point me to some resources on pytorch kernel's?

You can check out our wiki and this article by QuanSight for more on TensorIterator. The best place to look is probably at what a recent PR changed, though. Take a look at this recent PR implementing lcm and gcd: https://github.com/pytorch/pytorch/pull/40651/files, and let me know if you have additional questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: complex Related to complex number support in PyTorch open source triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants