What does happen when the parameters are sent to torch.optim.SGD() in the backward pass

I am a beginner in Pytorch. are these two codes the same? In fact, i am confused does the second code work correctly and each weight will update properly.


model = models.resnet101(pretrained=False)
opt = optim.SGD(model.parameters(), lr=lr, momentum=0.8)


model = models.resnet101(pretrained=False)

parameters = model.parameters()
weights = []
for name, param in model.named_parameters():
    if name.endswith('weight'):
weight_id = list(map(id, weight_parameters))
other_parameters = list(filter(lambda param: id(param) not in weights_id, parameters))

opt = optim.SGD([{'params' : other_parameters},
            {'params' : weights}], lr=lr, momentum=0.9)