-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
23 lines (20 loc) · 815 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import flwr as fl
import sys
import numpy as np
class SaveModelStrategy(fl.server.strategy.FedAvg):
def aggregate_fit(self,rnd,results,failures):
aggregated_weights = super().aggregate_fit(rnd, results, failures)
if aggregated_weights is not None:
# Save aggregated_weights
print(f"Saving round {rnd} aggregated_weights...")
np.savez(f"round-{rnd}-weights.npz", *aggregated_weights)
return aggregated_weights
# Create strategy and run server
strategy = SaveModelStrategy()
# Start Flower server for three rounds of federated learning with 1Gb of data
fl.server.start_server(
server_address = 'localhost:'+str(sys.argv[1]) ,
config={"num_rounds": 3} ,
grpc_max_message_length = 1024*1024*1024,
strategy = strategy
)