title: PyTorch - TypeError: forward() takes 1 positional argument but 2 were given
body: <p>I do not understand where this error comes from, the number of arguments to the model seems correct, below is my model:</p>
  <pre class="lang-py prettyprint-override"><code>class MancalaModel(nn.Module):
  
      def __init__(self, n_inputs=16, n_outputs=16):
          super().__init__()
  
          n_neurons = 256
  
          def create_block(n_in, n_out):
              block = nn.ModuleList()
              block.append(nn.Linear(n_in, n_out))
              block.append(nn.ReLU())
              return block
  
          self.blocks = nn.ModuleList()
          self.blocks.append(create_block(n_inputs, n_neurons))
          for _ in range(6):
              self.blocks.append(create_block(n_neurons, n_neurons))
  
          self.actor_block = nn.ModuleList()
          self.critic_block = nn.ModuleList()
          for _ in range(2):
              self.actor_block.append(create_block(n_neurons, n_neurons))
              self.critic_block.append(create_block(n_neurons, n_neurons))
  
          self.actor_block.append(create_block(n_neurons, n_outputs))
          self.critic_block.append(create_block(n_neurons, 1))
  
          self.apply(init_weights)
  
      def forward(self, x):
          x = self.blocks(x)
          actor = F.softmax(self.actor_block(x))
          critics = self.critic_block(x)
          return actor, critics
  </code></pre>
  <p>Then I create an instance and make a forward pass with random number</p>
  <pre class="lang-py prettyprint-override"><code>model = MancalaModel()
  x = model(torch.rand(1, 16))
  </code></pre>
  <p>Then I got the TypeError saying the number of arguments is not correct:</p>
  <pre><code>      2 model = MancalaModel()
  ----&gt; 3 x = model(torch.rand(1, 16))
        4 # summary(model, (16,), device='cpu')
        5 
  
  d:\environments\python\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
      725             result = self._slow_forward(*input, **kwargs)
      726         else:
  --&gt; 727             result = self.forward(*input, **kwargs)
      728         for hook in itertools.chain(
      729                 _global_forward_hooks.values(),
  
  D:\UOM\Year3\AI &amp; Games\KalahPlayer\agents\model_agent.py in forward(self, x)
       54 
       55     def forward(self, x):
  ---&gt; 56         x = self.blocks(x)
       57         actor = F.softmax(self.actor_block(x))
       58         critics = self.critic_block(x)
  
  d:\environments\python\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
      725             result = self._slow_forward(*input, **kwargs)
      726         else:
  --&gt; 727             result = self.forward(*input, **kwargs)
      728         for hook in itertools.chain(
      729                 _global_forward_hooks.values(),
  
  TypeError: forward() takes 1 positional argument but 2 were given
  </code></pre>
  <p>Any help is appreciated, thanks!</p>