Repository: pytorch
Issue: Dispatch to Python with wrappers triggers Autograd view asserts
Labels: triaged,module: __torch_dispatch__

## 🐛 Bug

Using Dispatch to Python with a Tensor subclass that contains a Tensor triggers some autograd asserts. I triggered this error using `LoggingTensor` here: https://github.com/pytorch/pytorch/blob/394dd391dd5c30de371e77722d5d0261dd90c0b0/test/test_python_dispatch.py#L26."

In particular, calling `y = x.permute(...)` where x is a LoggingTensor triggers an assert that y.storage is not an alias of x.storage. The reason why it's not an alias is that LoggingTensor doesn't use its storage and instead uses the underlying Tensor's storage.

## To Reproduce

cd into `test`.

```py
import torch
from test_python_dispatch import LoggingTensor, capture_logs
x = LoggingTensor(torch.randn(2, 3, requires_grad=True))
with capture_logs() as logs:
    x.permute(1, 0)
```

This gives the following error:
```
RuntimeError: self__storage_saved.value().is_alias_of(result.storage())INTERNAL ASSERT FAILED at "../torch/csrc/a
utograd/generated/VariableType_0.cpp":7813, please report a bug to PyTorch.
```

This is triggering the following assert in autograd code:
```cpp
at::Tensor permute(c10::DispatchKeySet ks, const at::Tensor & self, at::IntArrayRef dims) {
  auto& self_ = unpack(self, "self", 0);
  auto _any_requires_grad = compute_requires_grad( self );
  (void)_any_requires_grad;
  std::shared_ptr<PermuteBackward> grad_fn;
  if (_any_requires_grad) {
    grad_fn = std::shared_ptr<PermuteBackward>(new PermuteBackward(), deleteNode);
    grad_fn->set_next_edges(collect_next_edges( self ));
    grad_fn->dims = dims.vec();
  }
  #ifndef NDEBUG
  c10::optional<Storage> self__storage_saved =
    self_.has_storage() ? c10::optional<Storage>(self_.storage()) : c10::nullopt;
  c10::intrusive_ptr<TensorImpl> self__impl_saved;
  if (self_.defined()) self__impl_saved = self_.getIntrusivePtr();
  #endif
  auto _tmp = ([&]() {
    at::AutoDispatchBelowAutograd guard;
    return at::redispatch::permute(ks & c10::after_autograd_keyset, self_, dims);
  })();
  auto result = std::move(_tmp);
  #ifndef NDEBUG
  if (self__storage_saved.has_value())
    // *THIS IS THE ASSERT*/
    AT_ASSERT(self__storage_saved.value().is_alias_of(self_.storage()));
  if (self__impl_saved) AT_ASSERT(self__impl_saved == self_.getIntrusivePtr());
  if (self__storage_saved.has_value())
    AT_ASSERT(self__storage_saved.value().is_alias_of(result.storage()));
  AT_ASSERT(result.use_count() <= 1, "function: permute");
  #endif
  if (grad_fn) {
      set_history(flatten_tensor_args( result ), grad_fn);
  }
  TORCH_CHECK_NOT_IMPLEMENTED(!(isFwGradDefined(self)), "Trying to use forward AD with permute that does
not support it.");
  return result;
}
```

## Expected behavior

This should not assert. Here are some potential resolutions:
- `has_storage` for a MetaTensor returns True. Maybe it should return False instead?
- Maybe LoggingTensor is implemented incorrectly, but as a user I would have no idea of how to implement it to avoid these asserts
- Somehow special-case these tensors

## Environment
 PT master.
 
 cc @ezyang @soulitzer @albanD