Verbose Warning with torch.matrix_exp

On torch 1.12.1+cu113 have a tensor T with T.shape = torch.Size([64, 512, 512]) on a cuda device. When I call torch.matrix_exp(T) I get the following warning:

<string>:1: UserWarning: An output with one or more elements was resized since it had shape [45, 512, 512], 
which does not match the required output shape [1, 45, 512, 512]. This behavior is deprecated, 
and in a future PyTorch release outputs will not be resized unless they have zero elements. 
You can explicitly reuse an out tensor t by resizing it, inplace, to zero elements with 
t.resize_(0). (Triggered internally at  ../aten/src/ATen/native/Resize.cpp:17.)

Note that I cannot reproduce it with this simple case:

T = torch.randn(64, 512, 512, device="cuda:0")
print(T.shape)
print(torch.matrix_exp(T).shape)

I believe this has to do with how matrix_exp handles different order approximations (hence the arbitrary 45 shape in the warning message). Any advice on how to fix this? Or at least suppress this warning message (it is coming multiple times an iteration for me).

1 Like