Small Godot project: mat2 must be a matrix

Caferino: <p>Short video of the problem: <a href="https://drive.google.com/file/d/1iU9JqBU-yuC7uhPQ_CNELNPw-GjlDDPe/view?usp=sharing" class="inline-onebox" rel="noopener nofollow ugc">Godot RL Agents.m4v - Google Drive</a></p>
<p>Hello, I am a newcomer who just started using PyTorch and Godot RL Agents yesterday for the first time following the steps of this 10-min tutorial (<a href="https://youtu.be/f8arMv_rtUU?si=sqsQw0FW2nJAmXkd&amp;t=355" rel="noopener nofollow ugc">https://youtu.be/f8arMv_rtUU?si=sqsQw0FW2nJAmXkd&amp;t=355</a>), but I am stuck at minute 5:55, when executing the training; it only works for like 5 seconds, then it crashes and closes itself, leaving these errors in the log:</p>
<blockquote>
<p>(rl) caferino@caferino:~/Documents/Python Envs$ python3 stable_baselines3_example.py<br>
No game binary has been provided, please press PLAY in the Godot editor<br>
waiting for remote GODOT connection on port 11008<br>
connection established<br>
action space {‘move’: {‘size’: 2, ‘action_type’: ‘continuous’}}<br>
observation space {‘obs’: {‘size’: [0], ‘space’: ‘box’}}<br>
Using cuda device<br>
/home/caferino/Documents/Python Envs/rl/lib/python3.10/site-packages/torch/nn/init.py:412: UserWarning: Initializing zero-element tensors is a no-op<br>
warnings.warn(“Initializing zero-element tensors is a no-op”)<br>
Logging to logs/sb3/experiment_13<br>
/home/caferino/Documents/Python Envs/rl/lib/python3.10/site-packages/torch/nn/modules/linear.py:114: UserWarning: An output with one or more elements was resized since it had shape [1, 64], which does not match the required output shape [64]. 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:28.)<br>
return F.linear(input, self.weight, self.bias)<br>
| time/              |    |<br>
|    fps             | 6  |<br>
|    iterations      | 1  |<br>
|    time_elapsed    | 5  |<br>
|    total_timesteps | 32 |<br>
/home/caferino/Documents/Python Envs/rl/lib/python3.10/site-packages/torch/nn/modules/linear.py:114: UserWarning: An output with one or more elements was resized since it had shape [32, 64], which does not match the required output shape [64]. 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:28.)<br>
return F.linear(input, self.weight, self.bias)<br>
/home/caferino/Documents/Python Envs/rl/lib/python3.10/site-packages/stable_baselines3/ppo/ppo.py:248: UserWarning: Using a target size (torch.Size([1])) that is different to the input size (torch.Size([32])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.<br>
value_loss = F.mse_loss(rollout_data.returns, values_pred)<br>
Traceback (most recent call last):<br>
File “/home/caferino/Documents/Python Envs/stable_baselines3_example.py”, line 215, in <br>
model.learn(**learn_arguments)<br>
File “/home/caferino/Documents/Python Envs/rl/lib/python3.10/site-packages/stable_baselines3/ppo/ppo.py”, line 315, in learn<br>
return super().learn(<br>
File “/home/caferino/Documents/Python Envs/rl/lib/python3.10/site-packages/stable_baselines3/common/on_policy_algorithm.py”, line 299, in learn<br>
self.train()<br>
File “/home/caferino/Documents/Python Envs/rl/lib/python3.10/site-packages/stable_baselines3/ppo/ppo.py”, line 279, in train<br>
loss.backward()<br>
File “/home/caferino/Documents/Python Envs/rl/lib/python3.10/site-packages/torch/_tensor.py”, line 492, in backward<br>
torch.autograd.backward(<br>
File “/home/caferino/Documents/Python Envs/rl/lib/python3.10/site-packages/torch/autograd/<strong>init</strong>.py”, line 251, in backward<br>
Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass<br>
RuntimeError: mat2 must be a matrix<br>
exit was not clean, using atexit to close env<br>
close message sent</p>
</blockquote>
<p>I am still not experienced with the tools, but I have been troubleshooting numerous things: Resize.cpp doesn’t show up anywhere, only Resize.h; trying to find where to change mm to matmul; using batch_size = 64 instead of 32 in ppo.py to avoid a “mini-batch” problem I had too; trying to find where to use t.resize_(0) although I read .view or .reshape is more recommended to use; been in the documentation learning new concepts about the software, but still no luck anything regarding modifying Tensors or mat2 properly…</p>
<p>I don’t know what I am doing yet tbh, but I want to learn, I followed the tutorial as is as an introduction (I did notice tho, at minute 1:28, the file being used, “stable_baselines3_example.py” has 75 LoC less than the current version (updated recently 4 days ago), so maybe I need to configure something not shown in the video, or my laptop is simply a mess, it has given me a lot of problems before for having dualboot or something sketchy in my files…, but I will keep searching for the solution and share it if I find it.</p>
<p>My laptop neofetch:<br>
caferino@caferino<br>
OS: Pop!_OS 22.04 LTS x86_64<br>
Host: HP ENVY m7 Notebook<br>
Kernel: 6.6.10-76060610-generic<br>
Uptime: 1 day, 20 hours, 54 minutes<br>
Packages: 3698 (dpkg), 44 (flatpak)<br>
Shell: bash 5.1.16<br>
Resolution: 1280x720, 1920x1080<br>
DE: GNOME 42.5<br>
WM: Mutter<br>
WM Theme: Pop<br>
Theme: Pop-dark [GTK2/3]<br>
Icons: Pop [GTK2/3]<br>
Terminal: tilix<br>
CPU: Intel i7-7500U (4) @ 3.00GHz<br>
GPU: Intel HD Graphics 620<br>
GPU: NVIDIA GeForce 940MX<br>
Memory: 6999MiB / 15880MiB</p>

taaha_saleem_bajwa: <p>Having the same problem. Did you find a solution?</p>

AlphaBetaGamma96: <aside class="quote no-group" data-username="Caferino" data-post="1" data-topic="196170">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/caferino/48/67280_2.png" class="avatar"> Caferino:</div>
<blockquote>
<p>File “/home/caferino/Documents/Python Envs/stable_baselines3_example.py”, line 215, in</p>
</blockquote>
</aside>
<p>Hi <a class="mention" href="/u/caferino">@Caferino</a>,</p>
<p>Can you share the file above? You probably have a Tensor with incorrect dimensions.</p>