-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[jit] Implements divmod function #20979
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
ddb87ca to
603a834
Compare
603a834 to
7cab633
Compare
d63408f to
8bd2d01
Compare
wanchaol
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.
Also, please add overloads for floating point numbers, this is now only working for integers which is not complete, consider using the micros (like DEFINE_BINARY_OP, etc) instead of adding it explicitly.
torch/csrc/jit/register_prim_ops.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.
please put this into aten namespace, everything that has schema should go to aten instead of prim, prim is reserved for unschematized operator, other ops like abs did it wrong and we will fix it in the future.
|
Hi @wanchaol the implementation of |
wanchaol
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.
looks good on the implementation, you don't need to add the micro for it considering that it is a rare use case that returns two results, making them separately sounds fine. it would be good if you can add mixed operand type overloads as well :)
torch/csrc/jit/register_prim_ops.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.
what about mixed operand types? like (int, float) and (float, int)? Can you also add these two? we should apply binary arithmetic operators rules for those use cases according to the python documentation
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.
Apply binary arithmetic operators rules would it mean calculating quotient first using / and then calculating mod using it?
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.
@pandeykartikey Yep that's correct. In general results returned here should match python divmod results in all combinations of operand types. Given there will be similar combo of them, it's the best to be generated (similar to aten::log) instead of writing each Operator separately with similar implementation.
test/test_jit.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.
Can you also check with some negative inputs? Python and C++ differ in their mod with negative numbers, we want to make sure it matches the Python behavior
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.
Also need to error check for 0 input
3c622c1 to
4a7d8d5
Compare
|
@pandeykartikey would you mind resolving the comments & conflicts? |
bf71afb to
8c37b6d
Compare
|
@wanchaol could you please follow up on this PR? |
wanchaol
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.
Thanks for adding the mix operand type overloads! The PR looks good to me, but it needs to rebase with the master since there're some file conflicts recently. Also have some small nits.
test/test_jit.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.
can't you just use self.checkScript(func_int, (1024, 0)) here and other exception cases?
torch/csrc/jit/register_prim_ops.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.
\ in this macro are not aligned, can you indent and align them?
4bf1870 to
35ef1c9
Compare
|
@wanchaol I have rebased the branch on master and made the other fixes. |
35ef1c9 to
b4d7f87
Compare
|
@pandeykartikey do you mind fix the clang-tidy linting issue? Maybe worth setting it up locally if you wish, see contributing doc |
|
@wanchaol Fixed the linting issue. |
zou3519
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.
Some of the tests are failing (click one of the red 'X's). We should fix those before landing.
Jun 07 13:09:48 ======================================================================
Jun 07 13:09:48 ERROR: test_divmod (__main__.TestScript)
Jun 07 13:09:48 ----------------------------------------------------------------------
Jun 07 13:09:48 Traceback (most recent call last):
Jun 07 13:09:48 File "test_jit.py", line 5666, in test_divmod
Jun 07 13:09:48 self.checkScriptRaisesRegex(func_int, (1024, 0), RuntimeError, "division by 0")
Jun 07 13:09:48 File "test_jit.py", line 2898, in checkScriptRaisesRegex
Jun 07 13:09:48 script(*inputs)
Jun 07 13:09:48 File "test_jit.py", line 5638, in func_int
Jun 07 13:09:48 return divmod(a, b)
Jun 07 13:09:48 ZeroDivisionError: integer division or modulo by zero
Jun 07 13:09:48
Jun 07 13:09:48 ----------------------------------------------------------------------
Jun 07 13:09:48 Ran 1934 tests in 585.133s
Jun 07 13:09:48
Jun 07 13:09:48 FAILED (errors=1, skipped=45, expected failures=1)
Jun 07 13:09:49 Traceback (most recent call last):
Jun 07 13:09:49 File "test/run_test.py", line 449, in <module>
Jun 07 13:09:49 main()
Jun 07 13:09:49 File "test/run_test.py", line 441, in main
Jun 07 13:09:49 raise RuntimeError(message)
Jun 07 13:09:49 RuntimeError: test_jit failed!
Jun 07 13:09:49 + cleanup
Jun 07 13:09:49 + retcode=1
Jun 07 13:09:49 + set +x
b26566b to
913e552
Compare
|
Hi @wanchaol I switched back to my previous implementation of zero division error because the |
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.
@wanchaol has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: This PR refer to issue #18627 Pull Request resolved: pytorch/pytorch#20979 Differential Revision: D15743929 Pulled By: wanchaol fbshipit-source-id: 967fc3fd519501e427176e10b112c8be1390540b
This PR refer to issue #18627