Update foreach binary ops with a single scalar and list of tensors#49250
Update foreach binary ops with a single scalar and list of tensors#49250izdeby wants to merge 40 commits intogh/izdeby/72/basefrom
Conversation
[ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- - Update ForeachBinaryOpScalar.cu to throw better errors in case of sub - Update division logic to check for type promotion [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- - Update ForeachBinaryOpScalar.cu to throw better errors in case of sub - Update division logic to check for type promotion [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- - Update ForeachBinaryOpScalar.cu to throw better errors in case of sub - Update division logic to check for type promotion [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- - Update ForeachBinaryOpScalar.cu to throw better errors in case of sub - Update division logic to check for type promotion [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- - Update ForeachBinaryOpScalar.cu to throw better errors in case of sub - Update division logic to check for type promotion [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- - Update ForeachBinaryOpScalar.cu to throw better errors in case of sub - Update division logic to check for type promotion [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- - Update ForeachBinaryOpScalar.cu to throw better errors in case of sub - Update division logic to check for type promotion [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
… tensors" Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- Update logic for 2 set of foreach APIs: 1) Binary ops with a scalar 2) Binary ops with a list of tensors - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
… tensors" Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- Update logic for 2 set of foreach APIs: 1) Binary ops with a scalar 2) Binary ops with a list of tensors - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
… tensors" Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- Update logic for 2 sets of the foreach APIs: 1) Binary ops with a scalar 2) Binary ops with a list of tensors - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
… tensors" Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- Update logic for 2 sets of the foreach APIs: 1) Binary ops with a scalar 2) Binary ops with a list of tensors - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
… tensors" Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- Update logic for 2 sets of the foreach APIs: 1) Binary ops with a scalar 2) Binary ops with a list of tensors - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
… tensors" Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- Update logic for 2 sets of the foreach APIs: 1) Binary ops with a scalar 2) Binary ops with a list of tensors - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
… tensors" Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- Update logic for 2 sets of the foreach APIs: 1) Binary ops with a scalar 2) Binary ops with a list of tensors - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
… tensors" Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- Update logic for 2 sets of the foreach APIs: 1) Binary ops with a scalar 2) Binary ops with a list of tensors - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
… tensors" Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- Update logic for 2 sets of the foreach APIs: 1) Binary ops with a scalar 2) Binary ops with a list of tensors - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
zou3519
left a comment
There was a problem hiding this comment.
Had some minor comments. Splitting up the PRs really helped, this was easy to review
| res = foreach_bin_op(tensors, scalar) | ||
|
|
||
| if dtype == torch.bool: | ||
| if foreach_bin_op == torch._foreach_sub: |
There was a problem hiding this comment.
nit: this test is called test_int_scalar. That's not very descriptive, it looks like what is being tested here is binary ops where the second argument is an int. Maybe something like test_tensorlist_scalar_op?
| self.assertEqual(res, expected) | ||
|
|
||
| # In case of In-place op, we can't change the dtype | ||
| foreach_bin_op_(tensors, scalar) |
There was a problem hiding this comment.
NB: this modifies the input "tensors" in-place, which means that the values are different the next iteration of the outer for-loop. But that seems to be okay. Usually to avoid mutating we would clone the input before performing the in-place operation.
No action item required here. It may possibly be nicer if we cloned tensors before calling the in-place op but that's subjective. I also see this pattern in the other test that is being modified in this PR.
… tensors" Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- Update logic for 2 sets of the foreach APIs: 1) Binary ops with a scalar 2) Binary ops with a list of tensors - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
… tensors" Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- Update logic for 2 sets of the foreach APIs: 1) Binary ops with a scalar 2) Binary ops with a list of tensors - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
… tensors" Differential Revision: [D25502938](https://our.internmc.facebook.com/intern/diff/D25502938) ---- Update logic for 2 sets of the foreach APIs: 1) Binary ops with a scalar 2) Binary ops with a list of tensors - Update foreach_sub error checking - Update division logic to check for type promotion - Updated tests [ghstack-poisoned]
Stack from ghstack:
Differential Revision: D25502938
Update logic for 2 sets of the foreach APIs: