fix assert_allclose doesnt check shape (#47580)

Summary:
fix assert_allclose doesnt check shape

should fix https://github.com/pytorch/pytorch/issues/47449.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/47580

Reviewed By: samestep

Differential Revision: D24836399

Pulled By: walterddr

fbshipit-source-id: 943f8c83864bc01e1a782048c234e9592d2f1a25
diff --git a/torch/testing/__init__.py b/torch/testing/__init__.py
index 80120b0..c26556f 100644
--- a/torch/testing/__init__.py
+++ b/torch/testing/__init__.py
@@ -212,7 +212,8 @@
     if not isinstance(expected, torch.Tensor):
         expected = torch.tensor(expected, dtype=actual.dtype)
     if expected.shape != actual.shape:
-        expected = expected.expand_as(actual)
+        raise AssertionError("expected tensor shape {0} doesn't match with actual tensor "
+                             "shape {1}!".format(expected.shape, actual.shape))
     if rtol is None or atol is None:
         if rtol is not None or atol is not None:
             raise ValueError("rtol and atol must both be specified or both be unspecified")