Sequential vs. custom extending nn.Module

what is the difference in defining the net by plugging in a number of nn.layers in the Sequential container and inheriting from nn.Module with appropriate layer members and expliticit definition of the forward pass?

Are the situations in which it is advised to use one over the other?

thanks in advance

1 Like

Hi,

Both are the same. It the custom module is the most general way to do it. The Sequential has been added to be able to avoid having to reimplement it every time for networks that are sequential (and a bit for historical reasons).
You can use either of them, note that the custom forward will give you more freedom to do whatever you want :slight_smile:

2 Likes

thank you! I see that clearer now =)