Actually it does not solve my problem. I get the error

autograd’s resize can only change the shape of a given tensor, while preserving the number of elements.

which makes sense, since my tensor collects tensors that require a gradient. Do you have any other ideas?