A more elegant way of creating the nets in pytorch?

Thank you, it does reduce the number of lines of code needed to write a class with a sequential processing. However, it does not eliminate the decoupling of the declaration of the network in the “init” call from its invocation in the “forward” call with a potential for a mismatch and code management issues in case of larger and more complex networks with structure that may depend on data samples. For example, if the “layer1” was a more complex non-sequential network with a graph structure that is produced by a non-trivial python function, its output size would be harder to guess/hardcode for the layer2 without actually invoking layer1 on the data first, so the “layer2” can not be declared with a static input size of 200, because you don’t know it before actually running the layer1.

Also, debugging of this code would be harder because you would not be able to examine the intermediate results of a forward call that invokes the whole stack of submodules. Ideally I want to be able to declare the whole network in the forward call without having to write a bunch of if statements and be able to examine all of the intermediate results line by line in the forward.