Comments (4)
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.
from flower.
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), {}
from flower.
Hi @kalkite,
You're close. Now, you can also store the round_id
in the config sent. In a simple FedAvg I'd do it as following:
FedAvg(other_params,
on_fit_config_fn=lambda x: {"round_id": x})
but since you're sending already the e.g. lr
it's just one new thing to add in the function to the config.
def fit(self, parameters, config):
print(f"[Client {int(self.client_id) + 1}] fit, config: {config}")
self.set_parameters(parameters)
lr = config['learning_rate']
# LINE BELOW IS NEW
round_id = config['round_id']
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
# MODIFY THE PATH TO INCLUDE THE ROUND ID
torch.save(self.model.state_dict(), f"client_{int(self.client_id) + 1}_round_{round_id}_model.pth")
time.sleep(5)
return self.get_parameters({}), len(self.train_loader), {}
from flower.
Is this round_id
of the client taken from the server round? Something like 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 on_fit_config_fn = get_on_fit_config(cfg.config_fit)
from flower.
Related Issues (20)
- Out of Memory while learning on Cifar with 100 clients HOT 1
- macOS: pip install flwr[simulation] uninstalls flwr 1.8.0 and installs 0.16.0 HOT 6
- RayActorClientProxy.get_parameters() missing 1 required positional argument: 'group_id'
- How to let the client train using the initial model provided by the server?
- How to get consistent order of spawned clients between multiple runs with Flower's simulation?
- flutter support HOT 1
- how to show the full args in task page? HOT 1
- Perform strategy in the sampled clients and its subset at the same time
- Method Doesn't Exist HOT 3
- ConnectionError: Couldn't reach 'cifar10' on the Hub (ConnectionError)
- How can I disable federated evaluation and use only centralized evaluation? HOT 1
- Question about the type of parameter in the parameter conduction process of my model
- `num_cpus` for ray backend not respected in `run_simulation` HOT 7
- How to solve hydra. errors Error reported for OverrideParseException: LexerNoViableAltException: \ HOT 3
- Could not run FedPer Baseline HOT 8
- Possible to Dynamically Switch Federated Learning Algorithms Based on Performance? HOT 1
- Bug in server_address (flower/examples/quickstart-pytorch/)
- How about onnxruntime support?
- Can I specify the resources for each client when running simulation?
- Pytorch example simulation from Youtube not working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flower.