CharlieDinh / pFedMe

Personalized Federated Learning with Moreau Envelopes (pFedMe) using Pytorch (NeurIPS 2020)
289 stars 88 forks source link

UserpFedMe class #3

Closed mehdimashayekhi closed 3 years ago

mehdimashayekhi commented 3 years ago

Hi , thanks for sharing your code. I have few questions. First is about the model update inside UserpFedMe class. Specifically I don't quite understand this part https://github.com/CharlieDinh/pFedMe/blob/96863e05e799fb6ad23248c63824b0381d2bec11/FLAlgorithms/users/userpFedMe.py#L58. What this line is doing is basically updating the personalized parameters (self.model.parameters()) to the final updated parameters of self.local_model. Can you please explain this further ? I don't know, maybe I have missed something, but the self.model.paramters() are already updated inside the inner optimization as done here https://github.com/CharlieDinh/pFedMe/blob/96863e05e799fb6ad23248c63824b0381d2bec11/FLAlgorithms/optimizers/fedoptimizer.py#L64, and I don't understand why we do need to set them back to final local weight! Second Question is I don't understand this https://github.com/CharlieDinh/pFedMe/blob/96863e05e799fb6ad23248c63824b0381d2bec11/FLAlgorithms/users/userbase.py#L39. It makes sense to update local_param but do not quite get why we need to update old_param. Please correct me if I am wrong but the only reason I can think of is because we are evaluating on the final aggregated model. Third question is here https://github.com/CharlieDinh/pFedMe/blob/96863e05e799fb6ad23248c63824b0381d2bec11/FLAlgorithms/servers/serverpFedMe.py#L54 where we train on all users not selected users. Why is that ? thanks much

CharlieDinh commented 3 years ago

Hi Mehdimashayekhi,

Thanks for your questions.

  1. For the first question: we have both personalized model (\theta) and local model (w_i), so actually in the optimizer, we only update the personalized model, not the local model, after we got the personalized model => we update the local model in lines 53 and 54. So actually self.update_parameters(self.local_model) is to update the parameter of the model at local device => then we use this for aggregation part, if I don't update it, the server will aggregate the personalized model, not local model.
CharlieDinh commented 3 years ago
  1. For the second question: As I used self.model.parameters() and self.local_model as 2 variables, at initial after receiving the global model from the server, they should have similar values. self.model.parameters() will be changed when I update at the optimizer. At this time self.model.parameters() is a personalized model. so and also it is the reason why I update self.update_parameters(self.local_model) to make self.model.parameters() and self.local_model are similar.
CharlieDinh commented 3 years ago
  1. For pFedMe, it is allowed all devices to self-training. it means that even the devices are not selected for aggregation, but I can do self-training. For the evaluation, we need to evaluate the personalized model of all devices, if a device is not selected and is not trained, so we don't have the personalized model of its device for evaluation.
mehdimashayekhi commented 3 years ago

Hi Mehdimashayekhi,

Thanks for your questions.

  1. For the first question: we have both personalized model (\theta) and local model (w_i), so actually in the optimizer, we only update the personalized model, not the local model, after we got the personalized model => we update the local model in lines 53 and 54. So actually self.update_parameters(self.local_model) is to update the parameter of the model at local device => then we use this for aggregation part, if I don't update it, the �server will aggregate the personalized model, not local model.

Thanks for your response. I totally agree with whatever you said, including the server aggregation. In the current implementation what you are saying is right which is " if I don't update it, the �server will aggregate the personalized model, not local model.", but this is based on the current implementation we have. My question is why the personalized model should be updated to the local model ? In other words if we change the code to use final local model for aggregation, do we still need to update the personalized model to local model ? Okay I see you answered this in my second question, which you said after each round of aggregation, self.model.parameters() and self.local_model they should have similar values, which makes sense.