Skip to content
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

Refactor/SK-1144 | Simplify on_train and on_validate #731

Merged
merged 7 commits into from
Oct 30, 2024

Conversation

benjaminastrand
Copy link
Contributor

Key changes

  • Moved boiler plate code from client to ClientAPI to make it simpler for the user to implement an on_train/on_validate function
  • Updated client_v2 accordingly
  • These changes eliminate the client's (client_v2 or exemple in README) need to import fedn protos

grpc_handler.py

  • Removed unnecessary params from send_model_update()

client_api.py

  • Replaced _subscribers with train_callback and validate_callback
    • train_callback needs to take in_model as parameter and return out_model and metadata dict
    • validate_callback needs to take in_model as parameter and return metrics dict
  • _task_stream_callback now invokes update_local_model or validate_global_model depending on task request type
    • update_local_model and validate_global_model contain boiler plate code that was previously inside the on_train and on_validate callbacks (getting/sending model from/to combiner, generating uuid, assembling metadata, sending model update/validation)
    • This replaces the functions train and validate
  • run method creates a child thread for heart beats and listens to task stream in main thread

client_v2.py

  • Adjusted training and validation functions for the updated client_api.py

README.rst

  • Updated example client that makes use of the new API

Copy link
Contributor

@niklastheman niklastheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good improvements overall, nice work! I have some input (nothing major), check out the comments!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could include a callback function for training in this README example. It doesn't need to do anything more than return the input model. The end goal is to make users understand how they can develop clients that help with their use case.

receiver_name=receiver_name,
receiver_role=receiver_role,
receiver_name=request.sender.name,
receiver_role=request.sender.role,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about these changes... Don't know if a TaskRequest as input is the way to go. It creates a dependency that did not exist previously... If you think it's cleaner, keep it.

@benjaminastrand benjaminastrand merged commit f3ec362 into feature/SK-1102 Oct 30, 2024
16 checks passed
@benjaminastrand benjaminastrand deleted the refactor/SK-1144 branch October 30, 2024 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants