Fix sum_to behavior with zero dimensions (#15796)
Summary:
Fixes #15223.
This fixes an autograd bug where backprop either fails or produces
gradients of incorrect sizes when tensors with zero-sized dimensions are
involved.
Previously, we were reducing along dimensions that had size greater than 1
when summing to a size in autograd. This is incorrect because we should also reduce
along dimensions with size 0 to produce a tensor of size 1 in that
dimension that then gets viewed to the correct shape.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15796
Differential Revision: D13593199
Pulled By: zou3519
fbshipit-source-id: 2e2acac34943a9b7fabadc10c9efd4f66db298fd