and replace them directly in each iteration, which could (and in your case will) reuse the data_ptr.
If you print item.data_ptr() of x and y or item before the contiguous() call you would see that they are different.
Thanks! It seems hard to find a real ‘inplace’ function to make ‘x, y’ contiguous. Now I use the outputs to overlap inputs, which behaves like ‘inplace’:
ret = 
for item in args:
device = 'cuda:0'
x = torch.rand([2, 3, 4], device=device).transpose(0, 2)
y = torch.zeros_like(x)
x, y = set_contiguous(x, y)