-
Notifications
You must be signed in to change notification settings - Fork 772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to Save Client Models and results After Each Round in Flower #3169
Comments
Hi, You can apply any custom logic in the e.g. fit method of the client. e.g. you can save the results and model state once you're done with fitting. |
Hi @adam-narozniak, thank you for response. I tried to save the client models, but I am only able to save the most last round of communication. Each recent fit file replaces the previous one. However, my goal is to save the client model for each round. def fit(self, parameters, config):
print(f"[Client {int(self.client_id) + 1}] fit, config: {config}")
self.set_parameters(parameters)
lr = config['learning_rate']
optimizer_conf = config['optimizer']
optimizer = getattr(optim, optimizer_conf)(self.model.parameters(), lr=lr)
epochs = config['epochs']
train_loss, train_accuracy = fed_train(model=self.model,
epochs=epochs,
optimizer=optimizer,
train_loader=self.train_loader)
print(f"Client {int(self.client_id) + 1} train_loss: {train_loss}, train_accuracy: {train_accuracy}")
# save results of each client to the Results dictionary
torch.save(self.model.state_dict(), f"client_{int(self.client_id) + 1}_model.pth")
time.sleep(5)
return self.get_parameters({}), len(self.train_loader), {} |
Hi @kalkite,
but since you're sending already the e.g.
|
Is this def get_on_fit_config(client_configs):
def fit_config_fn(server_round: int):
return {
"learning_rate": client_configs['learning_rate'],
"optimizer": client_configs['optimizer'],
"epochs": client_configs['epochs'],
"round_id": server_round
}
return fit_config_fn I keep |
Hello,
I am required to use trained models, so I need to save the client models and results after each round for applying the XAI method (SHAP). I found an example in TensorFlow. My goal is to save the state of each client's model after each round of federated learning.
Here is my client.
Saving the server model for each round.
The text was updated successfully, but these errors were encountered: