Skip to content

Conversation

@pandeykartikey
Copy link
Contributor

@pandeykartikey pandeykartikey commented May 27, 2019

This PR refer to issue #18627

@pytorchbot pytorchbot added the oncall: jit Add this issue/PR to JIT oncall triage queue label May 27, 2019
@pytorchbot pytorchbot added the module: internals Related to internal abstractions in c10 and ATen label May 27, 2019
@pandeykartikey pandeykartikey marked this pull request as ready for review May 27, 2019 06:48
Copy link
Collaborator

@wanchaol wanchaol left a 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.

Copy link
Collaborator

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.

@pandeykartikey
Copy link
Contributor Author

Hi @wanchaol the implementation of floating point and integer variation of divmod are very different. So, I have added it explicitly.
There was also no micro which handles two outputs. Shall I add one micro for that too?

Copy link
Collaborator

@wanchaol wanchaol 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 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 :)

Copy link
Collaborator

@wanchaol wanchaol May 28, 2019

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

Copy link
Contributor Author

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?

Copy link
Contributor

@ailzhang ailzhang Jun 5, 2019

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
Copy link
Contributor

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

Copy link
Contributor

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

@pandeykartikey pandeykartikey force-pushed the jit-divmod branch 2 times, most recently from 3c622c1 to 4a7d8d5 Compare May 29, 2019 12:22
@ailzhang
Copy link
Contributor

ailzhang commented Jun 5, 2019

@pandeykartikey would you mind resolving the comments & conflicts?

@pandeykartikey
Copy link
Contributor Author

@ailzhang I was waiting for a reply by @wanchaol on a doubt about binary arithmetic on mixed operands. All the others comments have been resolved in the previous commit.

@pandeykartikey pandeykartikey force-pushed the jit-divmod branch 3 times, most recently from bf71afb to 8c37b6d Compare June 6, 2019 16:37
@ezyang
Copy link
Contributor

ezyang commented Jun 6, 2019

@wanchaol could you please follow up on this PR?

@ezyang ezyang added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jun 6, 2019
@ezyang ezyang dismissed wanchaol’s stale review June 6, 2019 18:53

needs response

@pandeykartikey
Copy link
Contributor Author

@ailzhang @wanchaol @driazati This PR seems complete from my side would you mind taking a look.

Copy link
Collaborator

@wanchaol wanchaol left a 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
Copy link
Collaborator

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?

Copy link
Collaborator

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?

@pandeykartikey pandeykartikey force-pushed the jit-divmod branch 2 times, most recently from 4bf1870 to 35ef1c9 Compare June 7, 2019 06:55
@pandeykartikey
Copy link
Contributor Author

@wanchaol I have rebased the branch on master and made the other fixes.

@wanchaol
Copy link
Collaborator

wanchaol commented Jun 7, 2019

@pandeykartikey do you mind fix the clang-tidy linting issue?

Traceback (most recent call last):
  File "tools/clang_tidy.py", line 295, in <module>
    main()
  File "tools/clang_tidy.py", line 291, in main
    print(run_clang_tidy(options, line_filters, files))
  File "tools/clang_tidy.py", line 189, in run_clang_tidy
    raise RuntimeError(message.format(output))
RuntimeError: Found clang-diagnostic-errors in clang-tidy output: /home/travis/build/pytorch/pytorch/torch/csrc/jit/register_prim_ops.cpp:2407:9: error: expected ')' [clang-diagnostic-error]
        "aten::divmod(int x, int y) -> (int, int)",
        ^
/home/travis/build/pytorch/pytorch/torch/csrc/jit/register_prim_ops.cpp:2406:13: note: to match this '('
    Operator(
            ^
/home/travis/build/pytorch/pytorch/torch/csrc/jit/register_prim_ops.cpp:2407:9: error: expected unqualified-id [clang-diagnostic-error]
        "aten::divmod(int x, int y) -> (int, int)",
        ^
/home/travis/build/pytorch/pytorch/torch/csrc/jit/register_prim_ops.cpp:2472:13: error: use of undeclared identifier 'simpleClassTypeArg' [clang-diagnostic-error]
           !simpleClassTypeArg(schema_args[0], class_type) ||
            ^
/home/travis/build/pytorch/pytorch/torch/csrc/jit/register_prim_ops.cpp:2473:13: error: use of undeclared identifier 'simpleClassTypeArg' [clang-diagnostic-error]
           !simpleClassTypeArg(schema_args[1], class_type) ||

Maybe worth setting it up locally if you wish, see contributing doc

@pandeykartikey
Copy link
Contributor Author

@wanchaol Fixed the linting issue.

zou3519
zou3519 previously requested changes Jun 7, 2019
Copy link
Contributor

@zou3519 zou3519 left a 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

@pytorchbot pytorchbot added module: nccl Problems related to nccl support module: onnx Related to torch.onnx module: third_party labels Jun 8, 2019
@pandeykartikey pandeykartikey force-pushed the jit-divmod branch 5 times, most recently from b26566b to 913e552 Compare June 8, 2019 15:33
@pandeykartikey
Copy link
Contributor Author

Hi @wanchaol I switched back to my previous implementation of zero division error because the checkScriptWithRegex was not catching the error in the case of division by zero it was just throwing it and hence the previous tests didn't pass.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

@zou3519 zou3519 dismissed their stale review June 10, 2019 20:05

stale

zdevito pushed a commit to zdevito/ATen that referenced this pull request Jun 10, 2019
Summary:
This PR refer to issue #18627
Pull Request resolved: pytorch/pytorch#20979

Differential Revision: D15743929

Pulled By: wanchaol

fbshipit-source-id: 967fc3fd519501e427176e10b112c8be1390540b
@facebook-github-bot
Copy link
Contributor

@wanchaol merged this pull request in 2378c12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: internals Related to internal abstractions in c10 and ATen module: nccl Problems related to nccl support module: onnx Related to torch.onnx module: third_party oncall: jit Add this issue/PR to JIT oncall triage queue 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.

10 participants