I have a model called CombinedModel() which itself consists of 3 smaller blocks (named submodel1, submodel2, submodel3).
I created multiple instances of this CombinedModel() as so:
model1 = CombinedModel()
model2 = CombinedModel()
model3 = CombinedModel()




When checking the layer weights individually by calling them as model1.submodel1.layer[0].weight I observed that the weights in all three model instances are the same. Is this purely due to having a similar random initialization with the same random seed?


I proceeded to train only the first model model1:


def train_model(model,optimizer):

## Loop over epochs
    model.train()
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()

# Call instances of model and optimizer
model1 = CombinedModel()
optimizer = torch.optim.Adam(model1.parameters())

# Run function
train_model(model1,optimizer)


After doing so I checked the layer weights of all 3 models and found that the weights were again the same. How does training model1 independently affect the other weights as well?
model1.submodule1.layer[0].weight
model2.submodule1.layer[0].weight
model3.submodule1.layer[0].weight

The above three are all the same, despite model2 and model3 not being trained.
Even when I create a new model instance (model4 = CombinedModel()) after finishing model1 training, model4 also has the same weights as the other 3 models.
Why is it that each instance has the same weights? And how can I avoid this weight dependency among instances?