[jit][script] Handling for py2/py3 division differences#11016
[jit][script] Handling for py2/py3 division differences#11016zou3519 wants to merge 6 commits intopytorch:masterfrom
Conversation
torch/csrc/jit/register_prim_ops.cpp
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
I think the fix should be:
|
fb3a86e to
12091d4
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
This should be good for another review. I'm a little concerned about ONNX export though (I'm not sure if I should be) because of the following:
@jamesr66a should I be concerned? |
facebook-github-bot
left a comment
There was a problem hiding this comment.
zou3519 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
Had offline chat with @apaszke, I am going to fix the ONNX export |
zdevito
left a comment
There was a problem hiding this comment.
This looks good -- I have some minor comments.
torch/csrc/jit/register_prim_ops.cpp
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/jit/frontend.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
test/test_jit.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
facebook-github-bot
left a comment
There was a problem hiding this comment.
zou3519 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
| // - aten::div(int, int) -> float is the python truediv operator. This doesn't | ||
| // exist in ONNX so we express it in terms of ONNX ops. | ||
| // | ||
| TORCH_API void PrepareDivisionForONNX(const std::shared_ptr<Graph>& graph); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
facebook-github-bot
left a comment
There was a problem hiding this comment.
zou3519 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
| torch._C._jit_pass_lint(graph) | ||
|
|
||
| # onnx only supports tensors, but 1 / 2 = 0.5 and tensor(1) / tensor(2) = 0 | ||
| torch._C._jit_pass_prepare_division_for_onnx(graph) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
jamesr66a
left a comment
There was a problem hiding this comment.
Fixup the ONNX pass and add TORCH_API to Node::matches (to make windows CI pass) then this should be good to go
| Value* longtensor = subgraph->insertNode(subgraph->createNumToTensor(input))->output(); | ||
| // FLOAT = 1 | ||
| // https://github.com/onnx/onnx/blob/6bedd27b0307c9295039bd847895a27275160a98/onnx/onnx.in.proto#L282 | ||
| Node* cast = subgraph->create(onnx::Cast, {longtensor})->i_(attr::to, 1); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
95a42f2 to
943f4e7
Compare
|
@pytorchbot retest this please |
2 similar comments
|
@pytorchbot retest this please |
|
@pytorchbot retest this please |
|
This still looks good. There are some expect file issues. |
- In Python 2, use of `/` (regardless of int/float/Tensor) causes a compiler error if `from __future__ import division` is not imported in the file. - The / operator is universally set to do "true" division for integers - Added a `prim::FloorDiv` operator because it is used in loop unrolling. The error if users use '/' in python 2 without importing from __future__ occurs when building the JIT AST.
- s/prim::FloorDiv/aten::floordiv - Fix onnx export for true division on integers
facebook-github-bot
left a comment
There was a problem hiding this comment.
zou3519 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: - In Python 2, use of `/` (regardless of int/float/Tensor) causes a compiler error if `from __future__ import division` is not imported in the file. - The / operator is universally set to do "true" division for integers - Added a `prim::FloorDiv` operator because it is used in loop unrolling. The error if users use '/' in python 2 without importing from __future__ occurs when building the JIT AST. cc apaszke zdevito Pull Request resolved: pytorch#11016 Differential Revision: D9613527 Pulled By: zou3519 fbshipit-source-id: 0cebf44d5b8c92e203167733692ad33c4ec9dac6
/(regardless of int/float/Tensor) causes a compiler error iffrom __future__ import divisionis not imported in the file.prim::FloorDivoperator because it is used in loop unrolling.The error if users use '/' in python 2 without importing from future
occurs when building the JIT AST.
cc @apaszke @zdevito