Skip to content

Update foreach binary ops with a scalar list#49249

Closed
izdeby wants to merge 40 commits intogh/izdeby/71/basefrom
gh/izdeby/71/head
Closed

Update foreach binary ops with a scalar list#49249
izdeby wants to merge 40 commits intogh/izdeby/71/basefrom
gh/izdeby/71/head

Conversation

@izdeby
Copy link
Copy Markdown
Contributor

@izdeby izdeby commented Dec 11, 2020

Stack from ghstack:

Differential Revision: D25502939


Update logic for a set of foreach APIs with a scalar list

  • Update binary ops to support boolean type
  • Update sub ops to throw an error in case of bool subtraction
  • Update division op to check for type promotion.
  • Update tests

Iurii Zdebskyi added 4 commits December 11, 2020 12:31
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests
- Update ForeachUtils.h with division check.


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests
- Update ForeachUtils.h with division check.


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests
- Update ForeachUtils.h with division check.


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests
- Update ForeachUtils.h with division check.


[ghstack-poisoned]
@izdeby izdeby changed the title Update foreach binary ops with scalar lists Update ForeachBinaryOpScalarList.cu Dec 15, 2020
Iurii Zdebskyi added 7 commits December 15, 2020 15:08
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests
- Update ForeachUtils.h with division check.


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests
- Update ForeachUtils.h with division check.


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests
- Update ForeachUtils.h with division check.


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests
- Update ForeachUtils.h with division check.


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests
- Update ForeachUtils.h with division check.


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests
- Update ForeachUtils.h with division check.


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests
- Update ForeachUtils.h with division check.


[ghstack-poisoned]
Copy link
Copy Markdown
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.

Questions about behavior

Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests
- Update ForeachUtils.h with division check.


[ghstack-poisoned]
@izdeby izdeby changed the title Update ForeachBinaryOpScalarList.cu Update ForeachBinaryOpScalarList.cu and refactor ForeachUtils.h Dec 21, 2020
@izdeby izdeby requested a review from zou3519 December 21, 2020 19:32
…ils.h"


Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests
- Update ForeachUtils.h with division check and refactored `can_use_fast_route` methods.


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests


[ghstack-poisoned]
@izdeby
Copy link
Copy Markdown
Contributor Author

izdeby commented Feb 18, 2021

I haven't read through #49250 (the next PR in this stack) but I wanted to ask first: What is the difference between #49250 and this PR? Both of the descriptions look the same:

This PR

Update binary ops to support boolean type
Update sub ops to throw an error in case of bool subtraction
Update division op to check for type promotion.
Update tests

#49250

Update foreach_sub error checking
Update division logic to check for type promotion
Updated tests

In this PR, we are updating the sub/div logic for APIs that work with scalar lists and in the next one APIs with a scalar and/or tensor list. Updating names and description for both PRs

Iurii Zdebskyi added 2 commits February 18, 2021 12:15
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
Update logic for 2 set of foreach APIs with a scalar list
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
Update logic for 2 set of foreach APIs with a scalar list
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests


[ghstack-poisoned]
@izdeby izdeby requested a review from zou3519 February 19, 2021 16:03
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
Update logic for a set of foreach APIs with a scalar list
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests


[ghstack-poisoned]
Copy link
Copy Markdown
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.

This looks pretty reasonable, it's great we are deleting all the special cases in the testing logic. I had some comments around the tests

Comment on lines +73 to +74
// In the case of division, integer inputs will result in float.
// Currently multi tensor apply can only return result of the same type as input.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It would be good to mention "This does not use FOREACH_BINARY_OP_SCALARLIST because ". It's easy to make the inference but just to clarify

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


// In the case of division, integer inputs will result in float.
// Currently multi tensor apply can only return result of the same type as input.
void foreach_tensor_div_scalarlist_kernel_cuda_(TensorList tensors, at::ArrayRef<Scalar> scalars) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also nit: is it possible to update FOREACH_BINARY_OP_SCALARLIST to take three arguments, where the last argument is div_op? Then we would be able to use FOREACH_BINARY_OP_SCALARLIST with division instead of rewriting the division logic

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return foreach_binary_op<std::divides>(tensors, scalars);
}

// In the case of subtraction, we dont allow scalar to be boolean following the torch.sub logic
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to mention "This does not use FOREACH_BINARY_OP_SCALARLIST because ". It's easy to make the inference but just to clarify that this is a special case

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

foreach_bin_op_(tensors, scalars)
with self.assertRaisesRegex(RuntimeError, "not implemented for"):
foreach_bin_op(tensors, scalars)
return
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a continue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +694 to +697
scalars = [True for _ in range(N)]
scalars[0] = 1
scalars[1] = 1.1
scalars[2] = 3 + 5j
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can be done succinctly in one line: scalars = [1, 1.1, 3 + 5j] + [True for _ in range(N - 3)]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +713 to +715
expected = [torch_bin_op(t, s) for t, s in zip(tensors, scalars)]
res = foreach_bin_op(tensors, scalars)
self.assertEqual(expected, res)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only tests correctness for the out-of-place variant, right? Should it also test correctness for the in-place variant?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Iurii Zdebskyi and others added 6 commits March 1, 2021 14:58
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
Update logic for a set of foreach APIs with a scalar list
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
Update logic for a set of foreach APIs with a scalar list
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
Update logic for a set of foreach APIs with a scalar list
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
Update logic for a set of foreach APIs with a scalar list
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
Update logic for a set of foreach APIs with a scalar list
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
Update logic for a set of foreach APIs with a scalar list
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests


[ghstack-poisoned]
@izdeby izdeby requested a review from zou3519 March 9, 2021 22:54
else:
with self.assertRaisesRegex(RuntimeError, "can't be cast to the desired output type"):
foreach_bin_op_(tensors, scalars)
continue
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the continue necessary here?

izdeby added 3 commits March 12, 2021 10:56
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
Update logic for a set of foreach APIs with a scalar list
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
Update logic for a set of foreach APIs with a scalar list
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests


[ghstack-poisoned]
Differential Revision: [D25502939](https://our.internmc.facebook.com/intern/diff/D25502939)

--------
Update logic for a set of foreach APIs with a scalar list
- Update binary ops to support boolean type
- Update sub ops to throw an error in case of bool subtraction
- Update division op to check for type promotion.
- Update tests


[ghstack-poisoned]
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@izdeby merged this pull request in 4bb34c2.

@facebook-github-bot facebook-github-bot deleted the gh/izdeby/71/head branch March 19, 2021 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants