Skip to content

Conversation

@cpuhrsch
Copy link
Contributor

@cpuhrsch cpuhrsch commented Oct 31, 2022

Support passing value scalars as a flat 1D Tensor.

Currently we can only pass either an individual scalar or a ScalarList.

@pytorch-bot pytorch-bot bot added the release notes: foreach_frontend release notes category label Oct 31, 2022
@pytorch-bot
Copy link

pytorch-bot bot commented Oct 31, 2022

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/88157

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit 1fedef8:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@cpuhrsch cpuhrsch changed the title Add _foreach_addcdiv.Tensor Add _foreach_addcdiv(_).Tensor Nov 1, 2022
@cpuhrsch cpuhrsch requested a review from ngimel November 1, 2022 02:17
@cpuhrsch cpuhrsch marked this pull request as ready for review November 1, 2022 02:17
for scalar in Scalars:
self._test_pointwise_op(device, dtype, op, N, True, disable_fastpath, values=scalar)
for _, scalarlist in getScalarLists(N):
self._test_pointwise_op(device, dtype, op, N, True, disable_fastpath, values=torch.tensor(scalar))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should you also test the case where torch.tensor(scalar, device=device) ?
Same for all the updates below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we'll need to add more "assertRegexFail" type tests

CUDA: foreach_tensor_addcdiv_scalarlist_cuda_
autogen: _foreach_addcdiv.ScalarList_out

- func: _foreach_addcdiv_.Tensor(Tensor(a!)[] self, Tensor[] tensor1, Tensor[] tensor2, Tensor scalars) -> ()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Curious why this is not Tensor[] scalars? That sounds more consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because those are more difficult to convert to scalars efficiently.

Copy link
Collaborator

Choose a reason for hiding this comment

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

At least, #88173 will pass Tensor[] to this according to the temporary code in there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well it can convert the step sizes to a torch.Tensor before calling into foreach

Copy link
Collaborator

Choose a reason for hiding this comment

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

Doing a .cat() before every call sounds like a big overhead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's for 1-element tensors on cpu only, should be fast.

@cpuhrsch cpuhrsch changed the title Add _foreach_addcdiv(_).Tensor Add _foreach_addc(div/mul)(_).Tensor Nov 1, 2022
@cpuhrsch cpuhrsch requested a review from albanD November 1, 2022 20:34
@cpuhrsch
Copy link
Contributor Author

cpuhrsch commented Nov 2, 2022

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 2, 2022
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Copy link
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

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

Sounds good!

kulinseth pushed a commit to kulinseth/pytorch that referenced this pull request Nov 5, 2022
Support passing value scalars as a flat 1D Tensor.

Currently we can only pass either an individual scalar or a ScalarList.
Pull Request resolved: pytorch#88157
Approved by: https://github.com/ngimel, https://github.com/albanD
kulinseth pushed a commit to kulinseth/pytorch that referenced this pull request Dec 10, 2022
Support passing value scalars as a flat 1D Tensor.

Currently we can only pass either an individual scalar or a ScalarList.
Pull Request resolved: pytorch#88157
Approved by: https://github.com/ngimel, https://github.com/albanD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: foreach_frontend release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants