I am designing a neural network that has a sequential module that is composed of a variable number of linear layers depending on the initial size of the feature space. The problem is that on the first module that I append to my sequential module, the code stops executing and my runtime is crashed. Here is my code:
self.sequential = nn.Sequential()
input_dim = feature_size
output_dim = int(feature_size // scaling_factor)
while (output_dim > 1000):
print("%s_%s" % (input_dim, output_dim))
# Hangs on next line
self.sequential.add_module("%s_%s" % (input_dim, output_dim), nn.Linear(input_dim, output_dim))
input_dim = output_dim
output_dim = int(input_dim // get_scaling_factor(input_dim))
What is the appropriate way to create a sequential module with a variable number of layers?
EDIT:
Turns out the code above is OK. The reason for which I was getting the hanging was that I was attempting to create a layer with way too many inputs and outputs for the interpreter to handle. (Both input_dim and output_dim were on the order of 100,000s).