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 xlogy and xlog1py references #77712

Closed
wants to merge 33 commits into from

Conversation

rdspring1
Copy link
Contributor

@rdspring1 rdspring1 commented May 18, 2022

  • Add reference implementations for xlogy and xlog1py
  • Replace _wrap_scalar helper function with scalar_tensor prim

cc @ezyang @mruberry @ngimel @lezcano @fdrocha

 * Add reference implementations for [bitwise_not, i0, i1, zeta, xlogy, xlog1py]
 * Add prim operations for [i0, i1, zeta]
@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented May 18, 2022

🔗 Helpful links

✅ No Failures (0 Pending)

As of commit 786fa83 (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.

@rdspring1 rdspring1 changed the title Add Special Ops 1 references [WIP] Add Special Ops 1 references May 18, 2022
torch/_prims/__init__.py Outdated Show resolved Hide resolved
torch/_prims/__init__.py Outdated Show resolved Hide resolved
torch/_prims/__init__.py Outdated Show resolved Hide resolved
torch/_prims/__init__.py Outdated Show resolved Hide resolved
torch/_prims/__init__.py Outdated Show resolved Hide resolved
torch/_prims/__init__.py Outdated Show resolved Hide resolved
torch/_prims/__init__.py Outdated Show resolved Hide resolved
torch/_refs/__init__.py Outdated Show resolved Hide resolved
torch/_refs/__init__.py Outdated Show resolved Hide resolved
torch/_refs/__init__.py Outdated Show resolved Hide resolved
torch/_refs/__init__.py Outdated Show resolved Hide resolved
torch/_refs/__init__.py Outdated Show resolved Hide resolved
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.

This looks great, @rdspring1! It shows a solid understanding of the system, fixes several issues, and adds the needed prims, references, and OpInfos. I made a few inline comments for your review, most of them are very minor

Don't hesitate to reach out on Slack if you have any questions!

@rdspring1
Copy link
Contributor Author

@mruberry I updated the logic handling scalar values, but still needed to make them into scalar_tensors for ops like eq and log.

torch/_prims/__init__.py Outdated Show resolved Hide resolved
type_promotion_kind=ELEMENTWISE_TYPE_PROMOTION_KIND.INT_TO_FLOAT,
)
def xlogy(a: Union[TensorLikeType, NumberType], b: Union[TensorLikeType, NumberType]):
assert isinstance(a, TensorLike) or isinstance(b, TensorLike)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change these asserts to be checks and add a comment for why the scalar_tensor construction is needed

b = scalar_tensor(b, dtype=a.dtype, device=a.device)
elif isinstance(b, TensorLike) and isinstance(a, Number):
a = scalar_tensor(a, dtype=b.dtype, device=b.device)
assert isinstance(a, TensorLike)
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 these asserts can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lint complains without the asserts.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's OK then to add a comment explaining the asserts are to satisfy the linter, or to disable the linter's checks on the line that's complaining (with a note about why the check is disabled)

)
def xlogy(a: Union[TensorLikeType, NumberType], b: Union[TensorLikeType, NumberType]):
assert isinstance(a, TensorLike) or isinstance(b, TensorLike)
if isinstance(a, TensorLike) and isinstance(b, Number):
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 an awkward construction because it constructs the scalar_tensor in the datatype of the tensor, but it's OK to do so because the type promotion decorator has already converted the tensor to the appropriate dtype

Copy link
Collaborator

Choose a reason for hiding this comment

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

These conditions can be simplified since one of a and b is a tensorlike object per the above check:

a = torch.scalar_tensor(a, b.dtype, b.device) if isinstance(a, Number) else a
b = torch.scalar_tensor(b, a.dtype, a.device) if isinstance(a, Number) else b

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mypy also complained about this change, since the other argument is Union[TensorLikeType, NumberType]

Copy link
Collaborator

Choose a reason for hiding this comment

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

Darn. I really don't like mypy

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.

Looks good overall but see a couple cleanup notes!

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 18, 2022
@rdspring1
Copy link
Contributor Author

@pytorchbot merge -g

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks on your PR pass since you used the green (-g) flag (ETA: 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 3 additional jobs have failed, first few of them are: trunk ,trunk / macos-12-py3-arm64-mps / Run MPS tests ,trunk / linux-focal-rocm5.2-py3.7 / test (default, 1, 2, linux.rocm.gpu)

Details for Dev Infra team Raised by workflow job

@rdspring1
Copy link
Contributor Author

@pytorchbot rebase -s

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 19, 2022

You don't have permissions to rebase this PR, only people with write permissions may rebase PRs.

@rdspring1
Copy link
Contributor Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@github-actions
Copy link

Hey @rdspring1.
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.

sgrigory pushed a commit to sgrigory/pytorch that referenced this pull request Oct 28, 2022
 * Add reference implementations for `xlogy` and `xlog1py`
 * Replace `_wrap_scalar` helper function with `scalar_tensor` prim
Pull Request resolved: pytorch#77712
Approved by: https://github.com/mruberry
kulinseth pushed a commit to kulinseth/pytorch that referenced this pull request Nov 5, 2022
 * Add reference implementations for `xlogy` and `xlog1py`
 * Replace `_wrap_scalar` helper function with `scalar_tensor` prim
Pull Request resolved: pytorch#77712
Approved by: https://github.com/mruberry
kulinseth pushed a commit to kulinseth/pytorch that referenced this pull request Dec 10, 2022
 * Add reference implementations for `xlogy` and `xlog1py`
 * Replace `_wrap_scalar` helper function with `scalar_tensor` prim
Pull Request resolved: pytorch#77712
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
ciflow/trunk Trigger trunk jobs on your pull request cla signed Merged module: primTorch 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.

None yet

8 participants