Skip to content

Commit 25b0104

Browse files
EthanHughEthan Hugh
and
Ethan Hugh
authored
FedProx Update Branch (#175)
Co-authored-by: Ethan Hugh <ethanhugh@Ethans-MacBook-Air.local>
1 parent 76fae91 commit 25b0104

File tree

2 files changed

+2
-24
lines changed

2 files changed

+2
-24
lines changed

docs/Examples.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ The git repository includes a number of examples that showcased how third-party
1616
|[FedAtt](https://arxiv.org/abs/1812.07108) | An implementation of the FedAtt algorithm — Ji et al., "[Learning Private Neural Language Modeling with Attentive Aggregation](https://arxiv.org/abs/1812.07108)," in the Proceedings of the 2019 International Joint Conference on Neural Networks (IJCNN 2019). To run this example, change directory to `examples/fedatt`, and run `python fedatt.py -c <configuration file>`. | Yes |
1717
|[FedNova](https://proceedings.neurips.cc/paper/2020/hash/564127c03caab942e503ee6f810f54fd-Abstract.html) | Change directory to `examples/fednova` and run `python fednova.py -c <configuration file>`. | Yes |
1818
|[FedSarah](https://arxiv.org/pdf/1703.00102.pdf) | Change directory to `examples/fedsarah` and run `python fedsarah.py -c <configuration file>`. | Yes |
19-
|[FedProx](https://arxiv.org/pdf/1812.06127.pdf) | Set `optimizer` of `trainer` to `FedProx` in your configuration file. | Yes |
19+
|[FedProx](https://arxiv.org/pdf/1812.06127.pdf) | Change directory to `examples/fedprox` and run `python fedprox.py -c <configuration file>`. | Yes |
2020
|[SCAFFOLD](https://arxiv.org/pdf/1910.06378.pdf) | Change directory to `examples/scaffold` and run `python scaffold.py -c <configuration file>`. | Not yet |

examples/fedprox/fedprox_trainer.py

+1-23
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def flatten_weights_from_model(model):
2525

2626
class FedProxLocalObjective:
2727
""" Representing the local objective of FedProx clients. """
28+
2829
def __init__(self, model):
2930
self.model = model
3031
self.init_global_weights = flatten_weights_from_model(model)
@@ -44,29 +45,6 @@ def compute_objective(self, outputs, labels):
4445

4546
class Trainer(basic.Trainer):
4647
""" The federated learning trainer for the FedProx client. """
47-
def train_process(self, config, trainset, sampler, cut_layer=None):
48-
"""The main training loop in FedProx framework. """
49-
50-
# For FedProx, the server will accept partial solutions from straggling clients
51-
# after waiting them for a certain amount of time. To re-create this scenario in
52-
# an experiment, a proportion of the selected clients will train for a smaller
53-
# number of epochs to simulate the stragglers that return with partial solutions,
54-
# as mentioned in Section 5.2
55-
if hasattr(Config().clients, 'straggler_simulation') and Config(
56-
).clients.straggler_simulation:
57-
np.random.seed(self.client_id)
58-
# Determine whether this selected client is a straggler
59-
strag_prop = Config().clients.straggler_percentage / 100
60-
is_straggler = np.random.choice([True, False],
61-
p=[strag_prop, 1 - strag_prop])
62-
if is_straggler:
63-
# Choose the epoch uniformly as mentioned in Section 5.2 of the paper
64-
global_epochs = Config().trainer.epochs
65-
config['epochs'] = np.random.choice(np.arange(
66-
1, global_epochs))
67-
68-
super(Trainer, self).train_process(config, trainset, sampler,
69-
cut_layer)
7048

7149
def loss_criterion(self, model):
7250
""" Return the loss criterion for FedProx clients. """

0 commit comments

Comments
 (0)