-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Implement hypot #42291
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
Implement hypot #42291
Conversation
💊 CI failures summary and remediationsAs of commit ab5c398 (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 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. This comment has been revised 46 times. |
b9eabb1 to
be19bda
Compare
|
@mruberry PTAL. Not sure why that single build is failing. Also, I have a few questions:
Mainly asking these to try to be consistent. Thanks! |
|
It looks like the build failed with an infrastructure error. Sorry about that. It doesn't indicate anything is wrong with this PR.
We're not very stringent about what is/isn't a method, and it's OK to not implement a method variant of hypot. The README suggests it's "core" operations which are also methods and that functions which are "too complicated" aren't.
Adding vectorized CPU support is great and of interest when an operation is part of a performance bottleneck, but not required for the first version of an op (unless it's perf critical).
That is an excellent question! I think we prefer using the _mm256 where available. |
mruberry
left a comment
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.
This is a very well written and mostly complete PR, thank you for submitting it, @muthuArivoli!
I suggested a few small corrections and updates.
d594fd4 to
0db398a
Compare
|
@mruberry PTAL, I made all the requested changes |
test/test_torch.py
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.
better add a test for bfloat16 on CPU:
@dtypesIfCPU(torch.bfloat16, torch.float32, torch.float64)
@dtypes(torch.float32, torch.float64)
...
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.
Awesome! Nice work @muthuArivoli. Please add the requested bfloat16 test variant on CPU and then I'll merge this.
Update: you'll also have to merge with master to rebase past the issue causing several builds to fail. Sorry about that.
4a0bad6 to
59e2041
Compare
|
@mruberry, I added bfloat16 to the tests, but since bfloat16 does not seem to be supported for numpy arrays, I tested against the equivalent formula just for bfloat16. Is that okay, or should I create a different test with hardcoded values just for bfloat16? |
facebook-github-bot
left a comment
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.
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Sounds good. Another option is to compare against fp32 in NumPy. I'll run this PR through our internal tests now. Let me know if you're interested in implementing another NumPy function. |
|
This is failing on some internal mobile builds: @dreiss Do you know how we handle mobile issues like this? |
|
I realized that I didn't add hypot to If not, should I just remove the Vec256 support, and leave that for a later PR? |
I'm not sure, unfortunately. This is also happening on nextafter, strangely. I'm going to try to follow-up with the mobile team tomorrow but versions of these PRs without the vectorized code paths would be the fastest way to get them in. We can follow-up with the vectorized code paths after the mobile issues are resolved. |
|
Big thank you to @dreiss who took the time to discuss the Android build issues with me offline. @dreiss suggests trying two things. First, implement hypot (and nextafter) in c10/util/math_compat.h: pytorch/c10/util/math_compat.h Line 47 in c660d2a
Second, add a simple vectorized implementation on Neon that just loops over its inputs and calls std::hypot (std::nextafter). I realize I suggested removing the vectorized Neon you wrote previously since it wasn't required for server builds, so my mistake there. @dreiss suggested looking at the implementations of pow and atan2 in that file as a guide, if needed. The c10/util/match_compat.h implementations for hypot (and nextafter) don't have to work, just like the nexttoward implementation. Does that make sense? If that doesn't fix the issue then I'll follow-up with @dreiss and the mobile team again and see if we can help out instead of requesting all these changes from you, @muthuArivoli. We appreciate your patience and diligence dealing with these issues. |
|
@mruberry I added the vectorized implementation back to Neon, and I added the function to the math_compat header. Currently, I'm just throwing an error, but hopefully someone will eventually be able to implement and test that. If this works, I'll go ahead and do the same on the nextafter PR. Also, seems like the linting error is from someone else's work. |
c10/util/math_compat.h
Outdated
| } | ||
|
|
||
| // TODO: this function needs to be implemented and tested. Currently just throw an error. | ||
| inline float hypot(float x, long double y) { |
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.
hypot's signature is (float, float) and (double, double)
facebook-github-bot
left a comment
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.
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
I'll run the update through the Android builds now. |
|
Android build is fixed. OSS PR build failures look like a failure in the base, not a problem with this revision. Starting the land process now. |
|
Looks like a conflict slipped in. Would you please rebase (and fix the nit, I guess, since the PR must be rebased anyway). |
|
Just fixed the merge conflict and fixed the method signature |
facebook-github-bot
left a comment
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.
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Related to #38349
Closes #22764