# How to create MLP model with arbitrary number of hidden layers

**URL:** <https://discuss.pytorch.org/t/how-to-create-mlp-model-with-arbitrary-number-of-hidden-layers/13124>\
**Category:** Uncategorized\
**Created:** [February 1, 2018, 2:15am UTC](https://discuss.pytorch.org/t/how-to-create-mlp-model-with-arbitrary-number-of-hidden-layers/13124 "2018-02-01T02:15:04Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![dpernes](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/dpernes/32/16250_2.png) [@dpernes](https://discuss.pytorch.org/u/dpernes)\
**Post date:** [February 1, 2018, 1:31pm UTC](https://discuss.pytorch.org/t/how-to-create-mlp-model-with-arbitrary-number-of-hidden-layers/13124/2 "2018-02-01T13:31:00Z")

</div>

You should use a nn.ModuleList instead of a python list. Looking at this topic might be useful: [When should I use nn.ModuleList and when should I use nn.Sequential?](https://discuss.pytorch.org/t/when-should-i-use-nn-modulelist-and-when-should-i-use-nn-sequential/5463/4)

---

_[View the full topic](https://discuss.pytorch.org/t/how-to-create-mlp-model-with-arbitrary-number-of-hidden-layers/13124)._
