Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use nn.ModuleList and when should I use nn.Sequential?

Tags:

pytorch

I am new to Pytorch and one thing that I don't quite understand is the usage of nn.ModuleList and nn.Sequential. Can I know when I should use one over the other? Thanks.

like image 608
Samrat Hasan Avatar asked Nov 29 '17 02:11

Samrat Hasan


1 Answers

nn.ModuleList does not have a forward method, but nn.Sequential does have one. So you can wrap several modules in nn.Sequential and run it on the input.

nn.ModuleList is just a Python list (though it's useful since the parameters can be discovered and trained via an optimizer). While nn.Sequential is a module that sequentially runs the component on the input.

like image 180
Egor Lakomkin Avatar answered Oct 09 '22 22:10

Egor Lakomkin