I am having the same issue with a different architecture.  Specifically, I am trying to build a stacked LSTM, where each layer may have a different number of units.  It would be very convenient to pass a list of layer sizes as an argument and have the same function build the network as appropriate.  Every attempt has failed:


The most obvious way is to build lists of ‘torch.nn.LSTM’ and hidden layers, and manage them directly.  This fails, I think, because they are “hidden” in a list, even though defined in the init routine.


Similarly, but for completeness, building a dict of layers with integer keys failed, for what I believe is the same reason.


A rather horrible attempt to use ‘vars(self)’ to force-construct meaningful variable names failed in a more complicated way, and honestly, it’s a terrible idea anyway.


What is the accepted way to do what I’m trying to do, without re-implementing the whole LSTM architecture myself?  Is there a way to force the registration of the LSTM objects with the parameters list?