Do you mean to create a view?
https://pytorch.org/docs/stable/tensor_view.html
>>> a = torch.ones(2, 2, requires_grad=True)
>>> a.grad
>>> b = a[:]
>>> b._is_view()
True
>>> b._base is a
True
>>> torch.autograd.grad(b * 2 + a * 2, (a,), torch.ones(2, 2))
(tensor([[4., 4.],
        [4., 4.]]),)
>>> torch.autograd.grad(a * 2, (a,), torch.ones(2, 2))
(tensor([[2., 2.],
        [2., 2.]]),)
>>>