[te] Don't fuse integer fmod or remainder#48700
[te] Don't fuse integer fmod or remainder#48700bertmaher wants to merge 7 commits intogh/bertmaher/36/basefrom
Conversation
fmod and remainder on int tensors will raise ZeroDivisionError if their divisors are 0. I don't think we should try to generate code that raises exceptions. If at some point we really wanted to fuse these, I might lean towards calling a C++ helper function from the generated code. Differential Revision: [D25265792](https://our.internmc.facebook.com/intern/diff/D25265792/) [ghstack-poisoned]
fmod and remainder on int tensors will raise ZeroDivisionError if their divisors are 0. I don't think we should try to generate code that raises exceptions. If at some point we really wanted to fuse these, I might lean towards calling a C++ helper function from the generated code. Differential Revision: [D25265792](https://our.internmc.facebook.com/intern/diff/D25265792/) ghstack-source-id: 117634182 Pull Request resolved: #48700
ZolotukhinM
left a comment
There was a problem hiding this comment.
Overall looks good, but I wonder if division by 0 was the only issue. There is another test called test_binary_div_ops that doesn't try to divide by 0 but still fails with int8. Only fusing floats would solve that too, but I'm curious what was the problem there - we might have some other bug.
| if (!st || !isFloatingType(*st)) { | ||
| return false; | ||
| } | ||
| } else if (!v->type()->cast<FloatType>()) { |
There was a problem hiding this comment.
This doesn't include Half and Double, does it?
There was a problem hiding this comment.
It might. We don't seem to differentiate statically halfs, doubles and single-points, @eellison ?
There was a problem hiding this comment.
this check is on a non-Tensor type (Scalar value), so Half/Double doesn't apply here
| return lambda x, y: fn(x, y) | ||
|
|
||
| dtypes = [ | ||
| # FIXME: Fails in IR Eval: torch.int8 and_ cpu |
There was a problem hiding this comment.
This FIXME is for a different issue.
There was a problem hiding this comment.
What's the issue? It looked like a vestigial FIXME.
There was a problem hiding this comment.
The issue is that the combination op=and, dtype=int8, device=cpu fails on IR eval :) I added it in one of the recent commits
There was a problem hiding this comment.
Ohhh, so what threw me off was this being in the block of dtypes. I read it as saying the combination of int8 and cpu fails :-p. Anyways I'll put it back
Actually there are at least two other issues which end up being side-stepped by this PR. I should probably fix them too, really, although they become more annoying to test if ints are banned in fusion (which I still think is the right call for the ZeroDivisionError reason).
|
💊 CI failures summary and remediationsAs of commit 2d267c9 (more details on the Dr. CI page):
Extra GitHub checks: 1 failed
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 33 times. |
| if (!st || !isFloatingType(*st)) { | ||
| return false; | ||
| } | ||
| } else if (!v->type()->cast<FloatType>()) { |
There was a problem hiding this comment.
this check is on a non-Tensor type (Scalar value), so Half/Double doesn't apply here
| if (!st || !isFloatingType(*st)) { | ||
| return false; | ||
| } | ||
| } else if (!v->type()->cast<FloatType>()) { |
There was a problem hiding this comment.
You could also allow constant non-zero ints:
(v->type()->cast<IntType>() && constant_as<int>(v).value_or(0) != 0)
| } | ||
| } | ||
|
|
||
| // Value is only supported if operands are floats. |
There was a problem hiding this comment.
Do we need to exclude non-floating point tensors if they are the first input ?
There was a problem hiding this comment.
That's a good point, this could be relaxed.
fmod and remainder on int tensors will raise ZeroDivisionError if their divisors are 0. I don't think we should try to generate code that raises exceptions. If at some point we really wanted to fuse these, I might lean towards calling a C++ helper function from the generated code. Differential Revision: [D25265792](https://our.internmc.facebook.com/intern/diff/D25265792/) [ghstack-poisoned]
fmod and remainder on int tensors will raise ZeroDivisionError if their divisors are 0. I don't think we should try to generate code that raises exceptions. If at some point we really wanted to fuse these, I might lean towards calling a C++ helper function from the generated code. Differential Revision: [D25265792](https://our.internmc.facebook.com/intern/diff/D25265792/) [ghstack-poisoned]
fmod and remainder on int tensors will raise ZeroDivisionError if their divisors are 0. I don't think we should try to generate code that raises exceptions. If at some point we really wanted to fuse these, I might lean towards calling a C++ helper function from the generated code. Differential Revision: [D25265792](https://our.internmc.facebook.com/intern/diff/D25265792/) [ghstack-poisoned]
Pull Request resolved: #48700 fmod and remainder on int tensors will raise ZeroDivisionError if their divisors are 0. I don't think we should try to generate code that raises exceptions. If at some point we really wanted to fuse these, I might lean towards calling a C++ helper function from the generated code. ghstack-source-id: 117741914 Differential Revision: [D25265792](https://our.internmc.facebook.com/intern/diff/D25265792/)
…der" fmod and remainder on int tensors will raise ZeroDivisionError if their divisors are 0. I don't think we should try to generate code that raises exceptions. If at some point we really wanted to fuse these, I might lean towards calling a C++ helper function from the generated code. Differential Revision: [D25265792](https://our.internmc.facebook.com/intern/diff/D25265792/) [ghstack-poisoned]
fmod and remainder on int tensors will raise ZeroDivisionError if their divisors are 0. I don't think we should try to generate code that raises exceptions. If at some point we really wanted to fuse these, I might lean towards calling a C++ helper function from the generated code. Differential Revision: [D25265792](https://our.internmc.facebook.com/intern/diff/D25265792/) [ghstack-poisoned]
Pull Request resolved: #48700 fmod and remainder on int tensors will raise ZeroDivisionError if their divisors are 0. I don't think we should try to generate code that raises exceptions. If at some point we really wanted to fuse these, I might lean towards calling a C++ helper function from the generated code. ghstack-source-id: 117821429 Differential Revision: [D25265792](https://our.internmc.facebook.com/intern/diff/D25265792/)
…mod or remainder" fmod and remainder on int tensors will raise ZeroDivisionError if their divisors are 0. I don't think we should try to generate code that raises exceptions. If at some point we really wanted to fuse these, I might lean towards calling a C++ helper function from the generated code. Differential Revision: [D25265792](https://our.internmc.facebook.com/intern/diff/D25265792/) [ghstack-poisoned]
Pull Request resolved: #48700 fmod and remainder on int tensors will raise ZeroDivisionError if their divisors are 0. I don't think we should try to generate code that raises exceptions. If at some point we really wanted to fuse these, I might lean towards calling a C++ helper function from the generated code. ghstack-source-id: 117845642 Differential Revision: [D25265792](https://our.internmc.facebook.com/intern/diff/D25265792/)
Codecov Report
@@ Coverage Diff @@
## gh/bertmaher/36/base #48700 +/- ##
=====================================================
Coverage 80.83% 80.83%
=====================================================
Files 1860 1860
Lines 200742 200751 +9
=====================================================
+ Hits 162274 162285 +11
+ Misses 38468 38466 -2 |
| return true; | ||
| } | ||
|
|
||
| bool typesAreSupported(const Node* node) { |
There was a problem hiding this comment.
While you’re at it, could you move the cuda_only fuse set ?
|
This pull request has been merged in 2d07d5b. |
Summary: Pull Request resolved: pytorch#48700 fmod and remainder on int tensors will raise ZeroDivisionError if their divisors are 0. I don't think we should try to generate code that raises exceptions. If at some point we really wanted to fuse these, I might lean towards calling a C++ helper function from the generated code. ghstack-source-id: 117845642 Test Plan: `buck test //caffe2/test:jit -- test_binary_ops` Reviewed By: eellison Differential Revision: D25265792 fbshipit-source-id: 0be56ba3feafa1dbf3c37f6bb8c1550cb6891e6d
Stack from ghstack:
fmod and remainder on int tensors will raise ZeroDivisionError if their divisors are 0. I don't think we should try to generate code that raises exceptions. If at some point we really wanted to fuse these, I might lean towards calling a C++ helper function from the generated code.
Differential Revision: D25265792