Extending PyTorch nn.Sequential class
I'm pretty new to OOP in Python, and rusty in general. I'd like to extend PyTorch's 'nn.Sequential' object in such a way that passing it a tuple of containing the number of node in each layer automatically generates an OrderedDict according to those nodes. For a functional example:

layers = (784, 392, 196, 98, 10)
n_layers = len(layers)
modules = OrderedDict()

# Layer definitions for inner layers:
for i in range(n_layers - 2):
    modules[f'fc{i}']   = nn.Linear(layers[i], layers[i+1])
    modules[f'relu{i}'] = nn.ReLU()

# Definition for output layer:
modules['fc_out'] = nn.Linear(layers[-2], layers[-1])
modules['smax_out'] = nn.LogSoftmax(dim=1)

# Define model and check attributes:
model = nn.Sequential(modules)


So, rather than pass the 'OrderedDict' object when initializing nn.Sequential, I want my class to take the tuple instead.

class Network(nn.Sequential):
   def__init__(self, n_nodes):
      super().__init__()

      **** INSERT LOGIC FROM LAST SNIPPET ***


So it seems like this won't work, because when my Network class calls super().__init__(), it's going to want to see the dictionary of layer activations. How might I go about writing my own network in such a way that it circumvents this problem, but still has all the functionality of PyTorche's sequential object?

I was thinking along the lines of something like:

class Network(nn.Sequential):
    def __init__(self, layers):
        super().__init__(self.init_modules(layers))


    def init_modules(self, layers):
        n_layers = len(layers)
        modules = OrderedDict()

        # Layer definitions for inner layers:
        for i in range(n_layers - 2):
            modules[f'fc{i}']   = nn.Linear(layers[i], layers[i+1])
            modules[f'relu{i}'] = nn.ReLU()

        # Definition for output layer:
        modules['fc_out'] = nn.Linear(layers[-2], layers[-1])
        modules['smax_out'] = nn.LogSoftmax(dim=1)

        return modules


I'm not sure if this sort of thing is allowed and/or good practice in Python. 

Your implementation is allowed and good.

And, you can also initilize super().__init__() vacant, then use self.add_module(key, module) in a loop to attach Linear or Relu or whatever else subsequently. In this way the function __init__ may cover the job of init_modules.
