Model inside model

Can pytorch handle models inside models? For example, let’s say we want to build a seq2seq model. Rather than creating an EncoderRNN class and DecoderRNN class then instantiating each separately inside of some training function (like in the pytorch tutorials), can we wrap them in a Seq2Seq class, which also inherits from nn.Module, instead?

From the document:
“Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes.”

1 Like