Setting local model updates (Ditto Federated learning)

David_Taylor: <p>I am currently working on implementing the Ditto personalized federated learning algorithm over human activity recognition data (HAR), however I am struggling to update local model parameters/weights. Without the personlization step in my code, local models have ~55% accuracy while after personalization accuracy seems almost random and very low ~7.</p>
<p>Local updates are computed by → v_k = v_k - lr (SGD(v_k) + interpolation(v_k - global_weights) )<br>
If interpolation is 0 → local training is just SGD</p>
<p>I’m currently stuck on line six. I want to want to select new parameter values for my local model based on SGD and the difference between global model weights and original local model weights.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/7/3/73333b14c69a83cfed30216a0ae593647098d0a3.png" data-download-href="https://discuss.pytorch.org/uploads/default/73333b14c69a83cfed30216a0ae593647098d0a3" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/7/3/73333b14c69a83cfed30216a0ae593647098d0a3.png" alt="image" data-base62-sha1="gr6FzBM6gvktsxVebOEUiqN6PzZ" width="690" height="445" data-dominant-color="2D2D26"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1208×780 54.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Currently I run one step of SGD and then slightly modify the model parameters by lr*interpolation(local_weights  - global weights). I think this might be affecting my optimizer. Is the only way to implement line six of the algorithms to create a custom optimizer?</p>

David_Taylor: <p>I also have a picture of the algorithm → <br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/7/d/7d70bd8a44e943f651ac4055aaef7177c38313e6.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/7d70bd8a44e943f651ac4055aaef7177c38313e6" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/7/d/7d70bd8a44e943f651ac4055aaef7177c38313e6_2_690x375.jpeg" alt="image" data-base62-sha1="hTHeccluNq4taXAvNyPxsiX754y" width="690" height="375" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/7/d/7d70bd8a44e943f651ac4055aaef7177c38313e6_2_690x375.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/7/d/7d70bd8a44e943f651ac4055aaef7177c38313e6_2_1035x562.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/7/d/7d70bd8a44e943f651ac4055aaef7177c38313e6.jpeg 2x" data-dominant-color="F3F1F1"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1085×590 126 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

Jiuh_star: <p>Maybe it too late but, I think you implement it in the wrong way</p>
<pre data-code-wrap="python3"><code class="lang-plaintext">_, grads, _ = c.solve_sgd(data_batch)
...

for layer in range(len(grads[1])):
    eff_grad = grads[1][layer] + self.lam * (self.local_models[idx][layer] - self.global_model[layer])
    self.local_models[idx][layer] = self.local_models[idx][layer] - self.learning_rate * eff_grad
</code></pre>
<p>check Ditto source code if you want to implement it from the ground up: <a href="https://github.com/litian96/ditto/blob/master/flearn/trainers_MTL/ditto.py" class="inline-onebox" rel="noopener nofollow ugc">ditto/ditto.py at master · litian96/ditto · GitHub</a></p>