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

**URL:** <https://discuss.pytorch.org/t/differences-between-writing-models-with-nn-sequential-vs-creating-a-class/17470>\
**Category:** Uncategorized\
**Created:** [May 3, 2018, 11:13pm UTC](https://discuss.pytorch.org/t/differences-between-writing-models-with-nn-sequential-vs-creating-a-class/17470 "2018-05-03T23:13:02Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [May 4, 2018, 12:25am UTC](https://discuss.pytorch.org/t/differences-between-writing-models-with-nn-sequential-vs-creating-a-class/17470/2 "2018-05-04T00:25:59Z")

</div>

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.

---

_[View the full topic](https://discuss.pytorch.org/t/differences-between-writing-models-with-nn-sequential-vs-creating-a-class/17470)._
