Add some forward AD formulas (#69384)

Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/69384

Test Plan: Imported from OSS

Reviewed By: albanD

Differential Revision: D33020602

Pulled By: soulitzer

fbshipit-source-id: a92dd243f2b5b21fe277b0bb17bcd61dfe5a0d67
This commit is contained in:
soulitzer
2021-12-12 00:07:50 -08:00
committed by Facebook GitHub Bot
parent baf92f9d5a
commit 0dcbd73eee
3 changed files with 78 additions and 6 deletions

View File

@ -516,6 +516,9 @@ class TestViewOps(TestCase):
g_expected = torch.stack([gi if j == i else torch.zeros_like(gi)
for j in range(3)], dim=0)
self.assertEqual(g, g_expected)
# Check with gradcheck
stacked = torch.randn(3, 10, 10, dtype=torch.double, requires_grad=True)
gradcheck(lambda x: x.unbind(), (stacked,), check_forward_ad=True)
def test_expand_view(self, device) -> None:
t = torch.ones((5, 1), device=device)