RuntimeError: size mismatch, m1: [471 x 1024], m2: [471 x 1024] at /opt/conda/conda-bld/pytorch_1579040055865/work/aten/src/THC/generic/THCTensorMathBlas.cu:290

Ranga_Muvavarirwa: <p>Am extending a <a href="https://github.com/muvavarirwa/chessy" rel="nofollow noopener">personal/hobby project</a> – to support MADDPG. Full disclosure – not the most elegant code here…</p>
<p>Getting size mismatch error – though dimensions should work as they are identical per error.</p>
<p><strong>Model</strong> is defined under <strong>model.py</strong>. Also summarized here:</p>
<p>CriticNetwork(<br>
(fc1): Linear(in_features=471, out_features=1024, bias=True)<br>
(fc2): Linear(in_features=1024, out_features=10240, bias=True)<br>
(fc3): Linear(in_features=10240, out_features=1024, bias=True)<br>
(fc4): Linear(in_features=1024, out_features=1, bias=True)<br>
)<br>
ActorNetwork(<br>
(fc1): Linear(in_features=384, out_features=1024, bias=True)<br>
(fc2): Linear(in_features=1024, out_features=10240, bias=True)<br>
(fc3): Linear(in_features=10240, out_features=1024, bias=True)<br>
(fc4): Linear(in_features=1024, out_features=87, bias=True)<br>
)</p>
<p>Whereas the ARGS are defined in <strong>args.py</strong></p>
<h1>===========================================================================</h1>
<p>select a game: [‘chessy’ or ‘checkers’]: chessy<br>
select number of teams:  [0, 1 or 2] 2<br>
Choose a name for this team [e.g. ‘blue_team’ or ‘green_team’]: Agent<br>
Choose a color for team_2 [e.g. ‘blue’: green<br>
Please enter team’s skill_level [1 = Novice, 10 = expert]: 10<br>
Please enter team’s strategy [0 = ‘cooperative’, 1 = ‘competitive’]: 1<br>
Choose a name for this team [e.g. ‘blue_team’ or ‘green_team’]: Environment<br>
Choose a color for team_2 [e.g. ‘blue’: red<br>
Please enter team’s skill_level [1 = Novice, 10 = expert]: 1<br>
Please enter team’s strategy [0 = ‘cooperative’, 1 = ‘competitive’]: 1<br>
How many trials would you like to run? [1 - 1,000,000] 10000<br>
Do you want to see the board positions in realtime? [ ‘Yes’ or ‘No’ ]no<br>
==============================RUN_TRIALS==================================</p>
<p>/home/ubuntu/chessy/model.py:46: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.<br>
return F.softmax(self.fc4(x))</p>
<hr>
<p>RuntimeError                              Traceback (most recent call last)<br>
 in <br>
7     global HISTORY_FILE<br>
8     user_input = userInput()<br>
----&gt; 9     run_trials(user_input)<br>
10<br>
11 <span class="hashtag">#main</span>()</p>
<p> in run_trials(user_input)<br>
29         env = Game(user_input.game, args, 8, sides, user_input.display_board_positions)<br>
30<br>
—&gt; 31         run_trial(user_input,env, mCritic)<br>
32<br>
33         cycle += 1</p>
<p> in run_trial(user_input, env, mCritic)<br>
26         next_state         = np.array(list(map(int, env.state))).astype(np.float32)<br>
27<br>
—&gt; 28         agent_p0.step(state, action, int(reward), next_state, done, mCritic)<br>
29<br>
30         time_step += 1</p>
<p>~/chessy/agent.py in step(self, state, action, reward, next_state, done, mCritic)<br>
59         if len(self.memory) &gt; self.args[‘BATCH_SIZE’]:<br>
60             experiences = self.memory.sample()<br>
—&gt; 61             self.train(experiences, mCritic)<br>
62<br>
63</p>
<p>~/chessy/agent.py in train(self, experiences, mCritic)<br>
99             # Get predicted next-state actions and Q values from target models<br>
100             actions_next   = self.actor_target(next_states)<br>
–&gt; 101             Q_targets_next = mCritic.target(next_states, actions_next)<br>
102<br>
103             # Compute Q targets for current states (y_i)</p>
<p>~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in <strong>call</strong>(self, *input, **kwargs)<br>
530             result = self._slow_forward(*input, **kwargs)<br>
531         else:<br>
–&gt; 532             result = self.forward(*input, **kwargs)<br>
533         for hook in self._forward_hooks.values():<br>
534             hook_result = hook(self, input, result)</p>
<p>~/chessy/model.py in forward(self, state, action)<br>
70         state  = torch.transpose(state, 0,1)<br>
71         action = torch.transpose(action,0,1)<br>
—&gt; 72         x = F.relu(self.fc1(torch.cat((state, action))))<br>
73         x = F.relu(self.fc2(x))<br>
74         x = F.relu(self.fc3(x))</p>
<p>~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in <strong>call</strong>(self, *input, **kwargs)<br>
530             result = self._slow_forward(*input, **kwargs)<br>
531         else:<br>
–&gt; 532             result = self.forward(*input, **kwargs)<br>
533         for hook in self._forward_hooks.values():<br>
534             hook_result = hook(self, input, result)</p>
<p>~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/linear.py in forward(self, input)<br>
85<br>
86     def forward(self, input):<br>
—&gt; 87         return F.linear(input, self.weight, self.bias)<br>
88<br>
89     def extra_repr(self):</p>
<p>~/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py in linear(input, weight, bias)<br>
1368     if input.dim() == 2 and bias is not None:<br>
1369         # fused op is marginally faster<br>
-&gt; 1370         ret = torch.addmm(bias, input, weight.t())<br>
1371     else:<br>
1372         <span class="hashtag">#print</span>(“INPUT:\n{}\n”.format(input))</p>
<p>RuntimeError: size mismatch, m1: [471 x 1024], m2: [471 x 1024] at /opt/conda/conda-bld/pytorch_1579040055865/work/aten/src/THC/generic/THCTensorMathBlas.cu:290</p>
<p>action = “2,2,-1”</p>
<p>action.split(",")</p>
<p>x = torch.Tensor(np.random.choice((0,1),87)).to(device)</p>
<p>x.shape</p>
<p>y = torch.Tenso</p>

ptrblck: <p>Could you check the shape of <code>torch.cat((state, action))</code> and make sure it has the desired shape of <code>[batch_size, 471]</code>?</p>
<p>PS: you can post code snippets by wrapping them into three backticks ```, which makes debugging easier. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>

Ranga_Muvavarirwa: <p>Thanks <a class="mention" href="/u/ptrblck">@ptrblck</a><br>
Turned out that I was improperly transposing tensor. Issue resolved in checked-in code on github.</p>
<p>Thanks!</p>