Update foreach APIs to use scalar lists (#51893)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/51893
Test Plan: Imported from OSS
Reviewed By: ngimel
Differential Revision: D26323606
Pulled By: izdeby
fbshipit-source-id: 53791087c924d04526fe7adb8f4ab5676d383b04