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 TensorBase.is_complex #385

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

khushi-411
Copy link

Before submitting
  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?

What does this PR do?

Fixes #339

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Sure thing!!!

@khushi-411 khushi-411 marked this pull request as ready for review May 8, 2024 22:21
@@ -617,6 +617,7 @@ def _abs_torch(x: torch.Tensor | Number):
),
),
)
elementwise_unary_ops.append(abs_opinfo)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great catch! Thank you!

@@ -1090,6 +1091,14 @@ def _abs_torch(x: torch.Tensor | Number):
)
elementwise_unary_ops.append(floor_opinfo)

is_complex_opinfo = OpInfo(
Copy link
Collaborator

Choose a reason for hiding this comment

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

is_complex is more tensor property like is_cuda, so let's put its OpInfo with the other tensor properties:

https://github.com/khushi-411/lightning-thunder/blob/05524ae8b828640587f6a67c72cd0c78671df649/thunder/tests/opinfos.py#L548

@@ -1102,6 +1102,11 @@ def ceil(a):
return clang.ceil(a)


@torchsymbol(torch.is_complex, is_method=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's not make this a symbol and let's put it next to is_cuda:

https://github.com/khushi-411/lightning-thunder/blob/05524ae8b828640587f6a67c72cd0c78671df649/thunder/torch/__init__.py#L191

But then we need to two things (I think) to make it work properly:

  • call register_method()
  • update the map _torch_to_thunder_function_map[torch.is_complex] = is_complex

Then I would expect the function and method to work as expected

Copy link
Collaborator

@tfogal tfogal May 25, 2024

Choose a reason for hiding this comment

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

Thanks for taking this on, @khushi-411! Mike had me do the same in #429, if you want more detail here.

Note that if it's both a method and a function of the module root (i.e. torch.is_complex) then AFAICT one needs to update the map for both torch.is_complex and torch.Tensor.is_complex.

Copy link
Author

Choose a reason for hiding this comment

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

Hi, @tfogal! Thanks very much for the heads-up. I'll look into the PR and keep you posted.

I'm currently travelling for a week, but I will complete this PR soon. I apologize for the delay.

@mruberry
Copy link
Collaborator

mruberry commented May 9, 2024

Hey @khushi-411! I made some comments about how to add this as a non-symbol function and method. Let's see how that works! We haven't done a lot of that before, and other operators would benefit from a pattern for it, too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement TensorBase.is_complex
5 participants