-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Port isposinf & isneginf kernel to structured kernels
#60633
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
Conversation
💊 CI failures summary and remediationsAs of commit a5cd52d (more details on the Dr. CI page and at hud.pytorch.org/pr/60633): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 Preview docs built from this PR 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 to the (internal) Dr. CI Users group. |
isposinf & isneginf kernel to structured kernels.isposinf & isneginf kernel to structured kernels.
4625aed to
2ce2c61
Compare
3b0b1b2 to
f9fc14b
Compare
Codecov Report
@@ Coverage Diff @@
## master #60633 +/- ##
==========================================
+ Coverage 76.12% 76.21% +0.08%
==========================================
Files 2062 2062
Lines 205577 205579 +2
==========================================
+ Hits 156501 156681 +180
+ Misses 49076 48898 -178 |
82d6ceb to
ad37106
Compare
isposinf & isneginf kernel to structured kernels.isposinf & isneginf kernel to structured kernels
ad37106 to
ebd6d39
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried inheriting from TensorIteratorBase? You can do that with structured_inherits: TensorIteratorBase.
It looks like right now, you don't use TensorIteratorBase at all in the meta functions of isneginf and isposinf. Two reasons that would be useful are:
- We want to make sure that the meta function does all of the type promotion / broadcasting / handles other meta-like edge cases. If you use TensorIterator in the actual impl() function but not the meta() function, there's a risk of forgetting to do some checking in the meta function that's normally handled by TensorIterator.
- (More long-term) We eventually want to make all TensorIterator ops structured and use
TensorIteratorBaseeverywhere, instead ofTensorIterator.
Let me know if you run into issues with that - we've had some instances of it being hard to directly use TensorIteratorBase, mostly because TensorIterator doesn't let you modify the output tensor before calling into it. I think you'll have to use .declare_static_dtype_and_device(kBool, self.device()) in the config to force TensorIterator to treat the output tensor as a bool.
cc @ysiraichi in case you uncovered any other issues - I think you started looking into porting a few binary comparison ops.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bdhirsh it seems like the intention here was to avoid constructing the TensorIterator entirely in the case that we short circuit to fill_.
But I do agree that TI is better, because as currently written the meta function is wrong, as it doesn't preserve layout.
|
@bdhirsh I'm going to let you shepherd this one |
59c4342 to
5499816
Compare
aten/src/ATen/TensorIterator.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One point need to discuss is that, after considering similar operators (like torch.signbit) that require boolean casting output, I wrote unary_boolean_op for code reuse. I am not sure if that is appropriate or should I build TI directly in meta function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, one reason not to is that it looks like not all "unary boolean" ops follow this same set of config.
E.g. looking at the logical_not kernel - it's pretty similar, in that torch.logical_not(a) will return a boolean tensor, but it looks like it doesn't enforce that the out= tensor has to have boolean dtype. So you can't unconditionally use .declare_static_dtype_and_device(at::kBool, a.device()) - you only want to do it when the output is currently not defined (in the functional version of the op).
If you leave this as a TensorIterator API, can you change the name (maybe unary_force_boolean_op?), and leave a comment mentioning that this API should only be used when the output tensor must have boolean type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds very reasonable, thanks for such detailed explanation! Let me change the name and leave a comment to describe that.
5499816 to
a5cd52d
Compare
|
@bdhirsh has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Porting
torch.isposinf&torch.isneginfto structured kernelRelated #55070