Hi
I have a federated learning scenario in which i want to send my cloud model parameters to different clients. i tried different ways. i did it with

model_dict[name_of_models[i]].conv1.weight.data = main_model.conv1.weight.detach().clone())

and it was working but as i saw here its better to not use .data in my code.
so i change it to

model_dict[name_of_models[i]].conv1.weight = nn.Parameters(model.conv1.weight.detach().clone())

but when i do this my clients model stop updating. i think that’s because i changed the parameters i referenced in their optimizer.
now i’m doing it with

with torch.no_grad():
for i in range(number_of_clients):
state_dict = model_dict[name_of_models[i]].state_dict()
        state_dict['conv1.weight'] = main_model.conv1.weight.detach().clone()
        state_dict['conv2.weight'] = main_model.conv2.weight.detach().clone()
        
        state_dict['conv1.bias'] = main_model.conv1.bias.detach().clone()
        state_dict['conv2.bias'] = main_model.conv2.bias.detach().clone()
        
        state_dict['fc1.weight'] = main_model.fc1.weight.detach().clone()
        state_dict['fc2.weight'] = main_model.fc2.weight.detach().clone()
        state_dict['fc3.weight'] = main_model.fc3.weight.detach().clone()
    
        state_dict['fc1.bias'] = main_model.fc1.bias.detach().clone()
        state_dict['fc2.bias'] = main_model.fc2.bias.detach().clone()
        state_dict['fc3.bias'] = main_model.fc3.bias.detach().clone()
        
        model_dict[name_of_models[i]] = model_dict[name_of_models[i]].load_state_dict(state_dict)


but when i do this i get the error ‘_IncompatibleKeys’ object has no attribute ‘train’ while training my model.
i will appreciate if anyone give me an advice on how to do this properly.
thanks