I am trying to implement a Strategy utilizing Clustered Federated Lerning based on the paper Efficient Distribution Similarity Identification in Clustered Federated Learning via Principal Angles Between Client Data Subspaces. I figured out to send the principal components for the clustering within the fit method in the client:
def fit(self, parameters, config: dict[str, bool | bytes | float | int | str]):
# TODO: FOR PACFL, calculate here the svd and other things within the first epoch and then do normal training, this is part of client fit method
lr = config['lr']
momentum = config['momentum']
epochs = config['local_epochs']
current_server_round = config['current_server_round']
print(current_server_round)
if current_server_round == 1:
data_by_label = gather_data_by_label(self.trainloader)
svd_results = compute_svd_for_each_label_top_k(data_by_label, 3)
res = np.hstack(svd_results)
return self.get_parameters({}), len(self.trainloader), {"svd": json.dumps(res.tolist())}
else:
optim = torch.optim.SGD(self.model.parameters(), lr=lr, momentum=momentum)
train(self.model,self.trainloader,optimizer=optim,epochs=epochs, device=self.device)
return self.get_parameters({}), len(self.trainloader), {}
Now for the server strategy: In the aggregate_fit the clustering was also implemented with the same intention of only doing it if server_round is equal to 1 and save the clusters to the Strategy Object. Here is where my problem starts, i do not really figure out how to pass/send the individual model parameters per cluster to the clients belonging to a specific cluster. I assume the clusterwise aggregation would happen within the aggregate_fit based on the clients ids matched with the ids in the saved clusters. But how do i send the individual model parameters to the clients belonging to a cluster?
Greetings