I am new to PyTorch. As part of my project, I have some code where I construct an OrderedDict incrementally at runtime depending on the layers that are needed as part of the model. Now the way this code is structured is as ,
growingordereddict = {}
for layers in total_layer_list:
 # depending on the layer create the corresponding nn module and add to ordered dictionary.
 # In Pytorch you need to know the number of in_channels for a module with parameters such as 
#Conv and Dense. In order to obtain the number of in channels, the hack I use is to within the loop,
#construct a temp model with the orderedDict present so far and find the output size. This output 
#size will be the input channel to the next layer

# for example,
# tempmodel = nn.Sequential(growingordereddict)
 # out = tempmodel(torch.randn(1,3,5,5)) #model takes fixed size input
 # size = out.size()

#Use this size when constructing the next nn module as in_channels

After this loop is done, the final OrderedDict will have all the layers.
At the end outside the loop I do this,
torch.manual_seed(1)
model = nn.Sequential(growingorderedict)

However, I notice that on running each time, the initial weights are different. They don’t seem to have a fixed value corresponding to seed 1. Why is my code getting different initial weights for the layer each run, though I use a fixed seed of 1?
I noticed that if I have a sample code with the OrderedDict predefined and manual seed 1, the weights are the same each run. But in the case above where I have a for loop in which I instantiate a model many times to get the output size to construct the next layer, the manual seed set outside the loop to instantiate the final model does not seem to fix the model weights? What is the connection and why is this happening?