Nn.modulelist not implemented error

Hi, I am trying to create several encoder blocks by using nn.ModuleList and I get NotImplementedError.

class Transformer(nn.Module):
    def __init__(self,embed_size,num_heads,N,in_channels,batch_size,num_encoders,num_class):
        self.num_heads = num_heads
        self.embed_size = embed_size
        self.N = N
        self.in_channels = in_channels
        self.batch_size = batch_size
        self.num_encoders = num_encoders
        self.num_class = num_class
        self.proj = Project(self.N,self.in_channels,self.embed_size,self.batch_size)
        self.block = nn.ModuleList([nn.ModuleList([nn.LayerNorm(self.embed_size),EncoderBlock(self.embed_size,self.num_heads,self.N,self.in_channels,self.batch_size)]) for i in range(num_encoders)])
        self.encoders = EncoderBlock(self.embed_size,self.num_heads,self.N,self.in_channels,self.batch_size)##nn.ModuleList( EncoderBlock(self.embed_size,self.num_heads,self.N,self.in_channels,self.batch_size) for i in range(num_encoders))
        self.Linear = nn.Linear(self.embed_size,self.num_class)
        self.layernorm = nn.LayerNorm(num_class)

        indices = [i for i in range(self.num_class)]
        self.indices = torch.tensor(indices)

    def forward(self,img):
        out = self.proj(img)
        out = self.block(out) ## I got error here
        out = self.Linear(torch.squeeze(torch.index_select(out,1,torch.tensor(self.N**2))))
        out = self.layernorm(out)
        return out

What is the problem or are the problems?

You cannot execute the nn.ModuleList directly but would need to iterate it (as you would do with a plain Python list).
If you want to execute the internal layers sequentially you could use nn.Sequential instead.

My bad, thanks a lot.