Skip to content

[primTorch] Elementwise unary ops vi#79526

Closed
Aidyn-A wants to merge 17 commits intopytorch:masterfrom
Aidyn-A:Elementwise_Unary_Ops_VI
Closed

[primTorch] Elementwise unary ops vi#79526
Aidyn-A wants to merge 17 commits intopytorch:masterfrom
Aidyn-A:Elementwise_Unary_Ops_VI

Conversation

@Aidyn-A
Copy link
Copy Markdown
Collaborator

@Aidyn-A Aidyn-A commented Jun 14, 2022

This PR add primitives and references for heaviside and hypot.
Depends on #80146

@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Jun 14, 2022

🔗 Helpful links

✅ No Failures (0 Pending)

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

Expand to see more

💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

Comment thread torch/_prims/__init__.py Outdated
Comment thread torch/_prims/__init__.py
@Aidyn-A Aidyn-A changed the title Elementwise unary ops vi [primTorch] Elementwise unary ops vi Jun 14, 2022
@mruberry
Copy link
Copy Markdown
Collaborator

I don't think we need these to be prims, do we, @Aidyn-A?

@Aidyn-A
Copy link
Copy Markdown
Collaborator Author

Aidyn-A commented Jun 14, 2022

I don't think we need these to be prims, do we, @Aidyn-A?

Hi @mruberry,

I agree both of these can be refs only. I decided to make hypot as prim since it in C++ standard library, while heaviside, on the other side, does weird indexing like this:

def heaviside(a, b):
    ids = torch.eq(a, 0)
    ....
    a[ids] = b

is this a[ids] fully supported operation in refs?

@mruberry
Copy link
Copy Markdown
Collaborator

I don't think we need these to be prims, do we, @Aidyn-A?

Hi @mruberry,

I agree both of these can be refs only. I decided to make hypot as prim since it in C++ standard library

Great point -- and it's a function in CUDA, too (although only the two element version, like PyTorch has). Following our previous reasoning, seems like hypot is correctly a prim, then! My mistake on that one.

while heaviside, on the other side, does weird indexing like this:

def heaviside(a, b):
    ids = torch.eq(a, 0)
    ....
    a[ids] = b

is this a[ids] fully supported operation in refs?

No we don't have reference implementations for indexing but I think we want to use torch.where, which is supported, instead?

@Aidyn-A
Copy link
Copy Markdown
Collaborator Author

Aidyn-A commented Jun 14, 2022

No we don't have reference implementations for indexing but I think we want to use torch.where, which is supported, instead?

Right. We can use where. I will commit new changes. Thanks 👍

@Aidyn-A Aidyn-A marked this pull request as draft June 14, 2022 15:54
@Aidyn-A Aidyn-A marked this pull request as ready for review June 15, 2022 14:28
@Aidyn-A Aidyn-A requested a review from mruberry June 15, 2022 14:28
@IvanYashchuk
Copy link
Copy Markdown
Collaborator

@mruberry, heaviside is now implemented as a reference, not a prim, and all tests are passing. Could you please take another look?

Comment thread torch/_refs/__init__.py Outdated
@albanD albanD added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jun 21, 2022
@Aidyn-A Aidyn-A marked this pull request as draft June 21, 2022 19:08
@Aidyn-A Aidyn-A marked this pull request as ready for review June 21, 2022 23:01
@Aidyn-A
Copy link
Copy Markdown
Collaborator Author

Aidyn-A commented Jun 21, 2022

Hi @ngimel and @mruberry,

I fixed a tiny bug associated with where, now we can use it with two scalar arguments on the right hand side. Thanks to that I do not allocate tensors of zeros and ones in heaviside

Comment thread torch/_prims/__init__.py Outdated
@Aidyn-A Aidyn-A marked this pull request as draft June 24, 2022 17:19
@Aidyn-A Aidyn-A marked this pull request as ready for review June 30, 2022 00:07
@Aidyn-A
Copy link
Copy Markdown
Collaborator Author

Aidyn-A commented Jun 30, 2022

Now it is ready for the review.
cc @ngimel @mruberry

Copy link
Copy Markdown
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.

Awesome, nice work, @Aidyn-A!

@mruberry
Copy link
Copy Markdown
Collaborator

mruberry commented Jul 8, 2022

@pytorchbot merge

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a merge job. Check the current status here

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 8, 2022

Hey @Aidyn-A.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

facebook-github-bot pushed a commit that referenced this pull request Jul 8, 2022
Summary:
This PR add primitives and references for `heaviside` and `hypot`.
Depends on #80146

Pull Request resolved: #79526
Approved by: https://github.com/mruberry

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/04ef236c0df4e73eeb5049ed4755c65ef4b15ff5

Reviewed By: mehtanirav

Differential Revision: D37719824

Pulled By: mehtanirav

fbshipit-source-id: f5b5f7a2ce0f5141fbc1b4ef4572f96a22d323c1
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 25, 2026
This PR add primitives and references for `heaviside` and `hypot`.
Depends on pytorch#80146
Pull Request resolved: pytorch#79526
Approved by: https://github.com/mruberry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed Merged 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.

8 participants