Skip to content

Commit bac07c7

Browse files
JauntboxSvetlana Karslioglu
and
Svetlana Karslioglu
authored
Fix matmul resizing UserWarning (#1932)
The tensor tutorial has a section illustrating standard matrix multiplication vs. element-wise multiplication. In the standard matrix multiplication part, the output array is created with size [5, 4], while the output size will be [5, 5]. This raises a UserWarning: `UserWarning: An output with one or more elements was resized since it had shape [5, 4], which does not match the required output shape [5, 5].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).` Fix is to replace the `rand_like` argument with a tensor of the proper size, like `y1`. Co-authored-by: Svetlana Karslioglu <svekars@fb.com>
1 parent 599234a commit bac07c7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Diff for: beginner_source/basics/tensorqs_tutorial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
y1 = tensor @ tensor.T
146146
y2 = tensor.matmul(tensor.T)
147147

148-
y3 = torch.rand_like(tensor)
148+
y3 = torch.rand_like(y1)
149149
torch.matmul(tensor, tensor.T, out=y3)
150150

151151

0 commit comments

Comments
 (0)