Differences between writing models with nn.sequential() VS creating a Class?

You can use whatever fits your use case.
While some people like to use the nn.Sequential approach a lot, I usually just use it for small sub-modules and like to define my model in a functional way, i.e. derive from nn.Module and write the forward method myself.

This approach gives you more flexibility in my opinion, since you are able to easily create skip connections etc.
On the other hand if you just want to stack layers together, nn.Sequential is totally fine.

18 Likes