Forward() takes 2 arguments but 3 were given

username: bingqing_liu
cooked: <blockquote>
<p>class structural_attention_layer(nn.Module):<br>
def <strong>init</strong>(self):<br>
super(structural_attention_layer,self).<strong>init</strong>()</p>
<pre><code>    def forward(self,hello,world):
        return torch.randn(node_num,emb_size)
</code></pre>
</blockquote>
<blockquote>
<p>s_att=nn.Sequential()<br>
s_att.add_module(name=“structural_attention_layer”,module=structural_attention_layer())<br>
s_att(1,2)</p>
</blockquote>
<p>error occurs like the title,why?</p>

username: jeongwhanchoi
cooked: <p>You need to provide detailed information such as the stack trace when the error occurs.<br>
I think it could be the <code>TypeError</code> so that you maybe miss the positional arguments.</p>

username: ptrblck
cooked: <p><code>nn.Sequential</code> container use a single input and output tensor as the input and output activation.<br>
You could write a custom <code>nn.Module</code> for multiple inputs or check e.g. <a href="https://discuss.pytorch.org/t/how-can-i-pass-multiple-inputs-to-nn-sequential-layers/50868">this topic</a> for more information and potential workarounds.</p>

username: bingqing_liu
cooked: <p>yes,you are right.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/d/0db535f055b20ec449ded86cf6500cb8d2692eb8.png" data-download-href="https://discuss.pytorch.org/uploads/default/0db535f055b20ec449ded86cf6500cb8d2692eb8" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/d/0db535f055b20ec449ded86cf6500cb8d2692eb8_2_690x267.png" alt="image" data-base62-sha1="1XgrQU4VymSrLnDhqwVSEVlEtq8" width="690" height="267" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/d/0db535f055b20ec449ded86cf6500cb8d2692eb8_2_690x267.png, https://discuss.pytorch.org/uploads/default/original/3X/0/d/0db535f055b20ec449ded86cf6500cb8d2692eb8.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/0/d/0db535f055b20ec449ded86cf6500cb8d2692eb8.png 2x" data-dominant-color="F3F3F3"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">948×368 33.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
a single input works,so if i need to use multiple inputs,can i pack them in a list and unpack them in the next layer?</p>

username: bingqing_liu
cooked: <p>i am sorry,i don’t state my question clearly,the whole code is showed below:</p>
<pre><code class="lang-auto">import torch.nn as nn
import torch
class structural_attention_layer(nn.Module):
    def init(self):
        super(structural_attention_layer,self).init()

    def forward(self,a,b):
        return torch.randn(a,b)
    
s_att=nn.Sequential()
s_att.add_module(name="structural_attention_layer",module=structural_attention_layer())
s_att(1,2)
</code></pre>

username: ptrblck
cooked: <p>Yes, this should be possible as long as you are using your custom layers which would then unpack the input in their <code>forward</code> method. Most of the PyTorch layers defined in the <code>nn</code> namespace would fail.</p>