Repository: pytorch
Issue: test_python_dispatch fails on DEBUG=1
Labels: triaged,module: dispatch

### 🐛 Describe the bug

`python test/test_python_dispatch.py`
```
 ERROR: test_produce_real_type (__main__.TestPythonDispatch)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test/test_python_dispatch.py", line 371, in test_produce_real_type
    x[:, 1].contiguous(memory_format=torch.contiguous_format)  # optional memory format
RuntimeError: self__storage_saved.value().is_alias_of(result.storage()) INTERNAL ASSERT FAILED at "../torch/csrc/autograd/generated/VariableType_4.cpp":9776, please report a bug to PyTorch. 

======================================================================
ERROR: test_extend_library_with_dispatch_key_arg (__main__.TestPythonRegistration)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test/test_python_dispatch.py", line 219, in test_extend_library_with_dispatch_key_arg
    self.assertEqual(torch.sum(x), x)
RuntimeError: result.storage().use_count() == 1 INTERNAL ASSERT FAILED at "../torch/csrc/autograd/generated/VariableType_2.cpp":13157, please report a bug to PyTorch. function: sum

======================================================================
ERROR: test_override_cpu_sum (__main__.TestPythonRegistration)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test/test_python_dispatch.py", line 79, in test_override_cpu_sum
    self.assertEqual(torch.sum(x), x)
RuntimeError: result.storage().use_count() == 1 INTERNAL ASSERT FAILED at "../torch/csrc/autograd/generated/VariableType_2.cpp":13157, please report a bug to PyTorch. function: sum

======================================================================
FAIL: test_none_wrapping (__main__.TestPythonDispatch)
----------------------------------------------------------------------
RuntimeError: self__storage_saved.value().is_alias_of(result.storage()) INTERNAL ASSERT FAILED at "../torch/csrc/autograd/generated/VariableType_3.cpp":5047, please report a bug to PyTorch. 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test/test_python_dispatch.py", line 1072, in test_none_wrapping
    out.backward()
AssertionError: "but got None" does not match "self__storage_saved.value().is_alias_of(result.storage()) INTERNAL ASSERT FAILED at "../torch/csrc/autograd/generated/VariableType_3.cpp":5047, please report a bug to PyTorch. "

======================================================================
FAIL: test_subclass_creation (__main__.TestPythonDispatch)
----------------------------------------------------------------------
RuntimeError: self__storage_saved.value().is_alias_of(result.storage()) INTERNAL ASSERT FAILED at "../torch/csrc/autograd/generated/VariableType_1.cpp":2542, please report a bug to PyTorch. 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test/test_python_dispatch.py", line 563, in test_subclass_creation
    b = LoggingTensor(torch.rand(2)).as_subclass(Foo)
AssertionError: "subclass Foo but.*already associated to a python object of type LoggingTensor" does not match "self__storage_saved.value().is_alias_of(result.storage()) INTERNAL ASSERT FAILED at "../torch/csrc/autograd/generated/VariableType_1.cpp":2542, please report a bug to PyTorch. "
```

### Versions

master