Implements cpu_kernel_multiple_outputs and torch.frexp#51097
Implements cpu_kernel_multiple_outputs and torch.frexp#51097RockingJavaBean wants to merge 30 commits intopytorch:masterfrom
Conversation
💊 CI failures summary and remediationsAs of commit c8198e1 (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 to the (internal) Dr. CI Users group. |
91dbe3f to
c9a493a
Compare
Codecov Report
@@ Coverage Diff @@
## master #51097 +/- ##
==========================================
+ Coverage 76.36% 77.35% +0.98%
==========================================
Files 1886 1887 +1
Lines 184699 184804 +105
==========================================
+ Hits 141048 142946 +1898
+ Misses 43651 41858 -1793 |
c9a493a to
a76fe8d
Compare
|
We should add a function that exercises this new functionality to test it, too. What about Numpy's frexp? (https://numpy.org/doc/stable/reference/generated/numpy.frexp.html). |
…kernel_mutiple_outputs
|
@mruberry Thanks for the kind suggestion, I will update this PR by adding |
…kernel_mutiple_outputs
…kernel_mutiple_outputs
…kernel_mutiple_outputs
heitorschueroff
left a comment
There was a problem hiding this comment.
Hi @RockingJavaBean , @mruberry and I took another look at your updates together. Overall, this PR is looking pretty good and close to ready. We really appreciate all the work you put into implementing frexp and also taking extra time to fix bugs in our test suite such as separating the float values.
There are still a few suggestion we have for your review:
- We think we can reuse test_reference_numerics with a tweak, and while we appreciate you demonstrating that the other test_unary_ufunc.py tests can be adapted to work with frexp(), we're a little worried that change is too big. For the final PR, we'd like to suggest skipping those tests and leaving them unmodified.
- For the test_frexp_out, add cases for incorrectly sized and noncontiguous inputs
- Add supports_tensor_out=False to the UnaryUfuncInfo and fix the test_out_arg... to correctly query for the metadata instead of skipping the test.
We look forward to your next updates!
…kernel_mutiple_outputs
123a787 to
95f662e
Compare
95f662e to
52abf28
Compare
de5c23e to
742a99f
Compare
|
I'm really grateful for the thorough review and invaluable suggestions throughout this PR. This PR has been updated with the following changes:
Please kindly take a look. @heitorschueroff @mruberry |
heitorschueroff
left a comment
There was a problem hiding this comment.
@RockingJavaBean This last version looks ready, great work! Just one last change before I land this, it looks like the PR picked up some changes from another PR which I commented on, could you confirm this and fix it please, I'll land it then.
|
@heitorschueroff I'm truly thankful for your kind review. |
You're correct. I'm landing the PR now, thank you for this great PR. |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@heitorschueroff has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
mruberry
left a comment
There was a problem hiding this comment.
Nice job, @RockingJavaBean! This is a very technically complicated PR. I appreciate your thoughtfulness on both the technical challenges and the test architecture, too.
And thanks @heitorschueroff for reviewing this!
|
It is my honor to contribute to the PyTorch project and it cannot be done without your generous help and guidance. |
…kernel_mutiple_outputs
facebook-github-bot
left a comment
There was a problem hiding this comment.
@heitorschueroff has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@heitorschueroff merged this pull request in da10ccd. |
Summary: Close pytorch#51108 Related pytorch#38349 This PR implements the `cpu_kernel_multiple_outputs` to support returning multiple values in a CPU kernel. ```c++ auto iter = at::TensorIteratorConfig() .add_output(out1) .add_output(out2) .add_input(in1) .add_input(in2) .build(); at::native::cpu_kernel_multiple_outputs(iter, [=](float a, float b) -> std::tuple<float, float> { float add = a + b; float mul = a * b; return std::tuple<float, float>(add, mul); } ); ``` The `out1` will equal to `torch.add(in1, in2)`, while the result of `out2` will be `torch.mul(in1, in2)`. It helps developers implement new torch functions that return two tensors more conveniently, such as NumPy-like functions [divmod](https://numpy.org/doc/1.18/reference/generated/numpy.divmod.html?highlight=divmod#numpy.divmod) and [frexp](https://numpy.org/doc/stable/reference/generated/numpy.frexp.html#numpy.frexp). This PR adds `torch.frexp` function to exercise the new functionality provided by `cpu_kernel_multiple_outputs`. Pull Request resolved: pytorch#51097 Reviewed By: albanD Differential Revision: D26982619 Pulled By: heitorschueroff fbshipit-source-id: cb61c7f2c79873ab72ab5a61cbdb9203531ad469
Close #51108
Related #38349
This PR implements the
cpu_kernel_multiple_outputsto support returning multiple values in a CPU kernel.The
out1will equal totorch.add(in1, in2), while the result ofout2will betorch.mul(in1, in2).It helps developers implement new torch functions that return two tensors more conveniently, such as NumPy-like functions divmod and frexp.
This PR adds
torch.frexpfunction to exercise the new functionality provided bycpu_kernel_multiple_outputs.