Skip to content

Update foreach binary ops with a single scalar and list of tensors#49250

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

Update foreach binary ops with a single scalar and list of tensors#49250
izdeby wants to merge 40 commits intogh/izdeby/72/basefrom
gh/izdeby/72/head

Conversation

@izdeby
Copy link
Copy Markdown
Contributor

@izdeby izdeby commented Dec 11, 2020

Stack from ghstack:

Differential Revision: 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

@izdeby izdeby changed the title Add division logic to a slow/fast path [wip] Add division logic to a slow/fast path Dec 11, 2020
@izdeby izdeby changed the title [wip] Add division logic to a slow/fast path Update ForeachBinaryOpScalar.cu Dec 15, 2020
Iurii Zdebskyi added 2 commits December 15, 2020 15:08
@izdeby izdeby requested review from ngimel and zou3519 and removed request for ngimel December 16, 2020 16:30
Iurii Zdebskyi added 6 commits December 16, 2020 08:33
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]
@izdeby izdeby changed the title Update ForeachBinaryOpScalar.cu Update ForeachBinaryOpScalar.cu and ForeachBinaryOpList.cu Dec 21, 2020
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]
Iurii Zdebskyi added 3 commits January 29, 2021 09:28
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]
izdeby pushed a commit that referenced this pull request Feb 4, 2021
ghstack-source-id: b2ea442
Pull Request resolved: #49250
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]
@izdeby izdeby changed the title Update foreach_div and foreach_sub logic Update foreach binary ops with a single scalar and list of tensors Feb 18, 2021
Iurii Zdebskyi and others added 9 commits February 18, 2021 12:15
… 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]
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.

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:
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: 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)
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.

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.

izdeby added 3 commits March 12, 2021 10:56
… 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]
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@izdeby merged this pull request in b5cdb53.

@facebook-github-bot facebook-github-bot deleted the gh/izdeby/72/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.

3 participants