How can I give a name to each module in ModuleList?
I have the following component in my model:

feedfnn = []
for task_name, num_class in self.tasks:
    if self.config.nonlinear_fc:
        ffnn = nn.Sequential(OrderedDict([
            ('dropout1', nn.Dropout(self.config.dropout_fc)),
            ('dense1', nn.Linear(self.config.nhid * self.num_directions * 8, self.config.fc_dim)),
            ('tanh', nn.Tanh()),
            ('dropout2', nn.Dropout(self.config.dropout_fc)),
            ('dense2', nn.Linear(self.config.fc_dim, self.config.fc_dim)),
            ('tanh', nn.Tanh()),
            ('dropout3', nn.Dropout(self.config.dropout_fc)),
            ('dense3', nn.Linear(self.config.fc_dim, num_class))
        ]))
    else:
        ffnn = nn.Sequential(OrderedDict([
            ('dropout1', nn.Dropout(self.config.dropout_fc)),
            ('dense1', nn.Linear(self.config.nhid * self.num_directions * 8, self.config.fc_dim)),
            ('dropout2', nn.Dropout(self.config.dropout_fc)),
            ('dense2', nn.Linear(self.config.fc_dim, self.config.fc_dim)),
            ('dropout3', nn.Dropout(self.config.dropout_fc)),
            ('dense3', nn.Linear(self.config.fc_dim, num_class))
        ]))
    feedfnn.append(ffnn)
self.ffnn = nn.ModuleList(feedfnn)


When I print my model, I get the description of the above component as:

(ffnn): ModuleList (
(0): Sequential (
  (dropout1): Dropout (p = 0)
  (dense1): Linear (4096 -&gt; 512)
  (dropout2): Dropout (p = 0)
  (dense2): Linear (512 -&gt; 512)
  (dropout3): Dropout (p = 0)
  (dense3): Linear (512 -&gt; 2)
)
(1): Sequential (
  (dropout1): Dropout (p = 0)
  (dense1): Linear (4096 -&gt; 512)
  (dropout2): Dropout (p = 0)
  (dense2): Linear (512 -&gt; 512)
  (dropout3): Dropout (p = 0)
  (dense3): Linear (512 -&gt; 3)
)
(2): Sequential (
  (dropout1): Dropout (p = 0)
  (dense1): Linear (4096 -&gt; 512)
  (dropout2): Dropout (p = 0)
  (dense2): Linear (512 -&gt; 512)
  (dropout3): Dropout (p = 0)
  (dense3): Linear (512 -&gt; 3)
)
)


Can I put a specific name like (task1): Sequential, (task2): Sequential instead of (0): Sequential, (1): Sequential?

That's straightforward. 

Simply start with an empty ModuleListand then use add_module for it. For example,

import torch.nn as nn
from collections import OrderedDict

final_module_list = nn.ModuleList()

a_sequential_module_with_names = nn.Sequential(OrderedDict([
        ('dropout1', nn.Dropout(0.1)),
        ('dense1', nn.Linear(10, 10)),
        ('tanh', nn.Tanh()),
        ('dropout2', nn.Dropout(0.1)),
        ('dense2', nn.Linear(10, 10)),
        ('tanh', nn.Tanh()),
        ('dropout3', nn.Dropout(0.1)),
        ('dense3', nn.Linear(10, 10))]))

final_module_list.add_module('Stage 1', a_sequential_module_with_names)
final_module_list.add_module('Stage 2', a_sequential_module_with_names)
etc.

