alibaba / FederatedScope

An easy-to-use federated learning platform
https://www.federatedscope.io
Apache License 2.0
1.26k stars 206 forks source link

save client's model #746

Closed junzlovegood closed 7 months ago

junzlovegood commented 8 months ago

hi, how do I save the model generated by the client in the Personalized Federated Learning Settings? Thanks.

rayrayraykk commented 7 months ago

You'll need to update your configuration settings. Please set cfg.federate.save_client_model to True. Additionally, you must specify a valid file path for the cfg.federate.save_to where the client model should be saved.

If you have any further questions or encounter any issues, feel free to reach out.

junzlovegood commented 7 months ago

I update the configuration settings in the yarm file as follow:

federate:
  mode: standalone
  save_client_model: True

but it raise an error:

 raise KeyError("Non-existent config key: {}".format(full_key))
KeyError: 'Non-existent config key: federate.save_client_model'

It doesn't work for me.

rayrayraykk commented 7 months ago

My bad for this feature only exists in the llm branch. Could you switch to llm branch to use this feature?

In federatedscope/core/workers/client.py:

            if update_best_this_round and self._cfg.federate.save_client_model:
                path = add_prefix_to_path(f'client_{self.ID}_',
                                          self._cfg.federate.save_to)
                self.trainer.save_model(path, self.state)

in federatedscope/core/configs/cfg_fl_setting.py

    cfg.federate.save_client_model = False