woodenchild95 / FL-Simulator

Pytorch implementations of some general federated optimization methods.
34 stars 5 forks source link

about FedCM #5

Closed harrylee999 closed 5 months ago

harrylee999 commented 12 months ago

hi, thanks for sharing your code. but i find your implement of FedCM is different from the FedCM paper. image and in your code is: image why you do *torch.sum(param_list delta_list)** in each local step. it seems different from FedCM paper. Are they equal? Can you explain?

i am very confused about this.

woodenchild95 commented 12 months ago

@harrylee999 Thanks for this question. FedCM uses the $\Delta$ term to correct the local gradient as: $x_{t+1} = x_t - \eta\left(\alpha g + (1-\alpha)\Delta \right)$. If you rebuild the optimizer, you can follow Adam and rebuild a new optimizer class and an optimizer.step() function. While I rebuild a new loss function. Therefore, the gradient of my loss should be $\alpha g + (1-\alpha)\Delta$. Then back to the loss, due to the gradient calculation, my loss should be $\alpha f(x) + (1-\alpha)\langle x,\Delta \rangle$. So what you ask is the inner product of the second part above.

In summary, you can rebuild a new loss as my implementation or rebuild a new optimizer as Adam. You can select what you like :) (I rebuilt the loss because in the simulator it must save the model parameters list.)