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

Feature/SK-1102 | Simplify ClientAPI and add support for inference #726

Merged
merged 20 commits into from
Nov 11, 2024

Conversation

niklastheman
Copy link
Contributor

@niklastheman niklastheman commented Oct 11, 2024

Added a readme file to the client directory. This is an attempt to make users see how easy they can create their own clients.

Benjamin:
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
  • Added support for predict in ClientAPI and GrpcHandler
  • Added functions in GrpcHandler to create gRPC messages for model update, validation and prediction

grpc_handler.py

  • Added function create_update_message, create_validation_message and create_prediction_message which populate and return a gRPC message of the relevant type
  • Function send_model_update() now takes a ModelUpdate message as input directly and only handles logic for sending the message to the server

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
  • gRPC messages for update, validation and predict are created in update_local_model, validate_global_model and predict_global_model respectively and are sent in status and to GrpcHandler

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

@github-actions github-actions bot added feature New feature or request minor labels Oct 11, 2024
Copy link
Member

@ahellander ahellander left a comment

Choose a reason for hiding this comment

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

Nice, I think it will be helpful to have something like this.

However I think we can make it even neater, I have some ideas, let's talk about it.

@niklastheman
Copy link
Contributor Author

Nice, I think it will be helpful to have something like this.

However I think we can make it even neater, I have some ideas, let's talk about it.

Yes, let's!

@benjaminastrand benjaminastrand marked this pull request as draft October 30, 2024 07:56
}

# Do your training here, out_model is your result...
out_model = in_model
Copy link
Member

Choose a reason for hiding this comment

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

I think it is better to give a minimal, but working example. This could be confusing.

"lr": 1,
}

config = {
Copy link
Member

Choose a reason for hiding this comment

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

Don't understand this. How can the client set the round_id?

return metrics

def main(api_url: str, api_port: int, token: str = None):
print(f"API URL: {api_url}")
Copy link
Member

Choose a reason for hiding this comment

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

Remove printouts?

@benjaminastrand benjaminastrand changed the title Feature/SK-1102 | Add example README to client directory Feature/SK-1102 | Simplify ClientAPI and add support for inference Nov 4, 2024
@benjaminastrand
Copy link
Contributor

benjaminastrand commented Nov 5, 2024

  • Added predict to GrpcHandler and ClientAPI
  • Added functions to create gRPC messages for update, validation and prediction
    • ClientAPI sends request + model data to GrpcHandler and receives gRPC message back
    • gRPC message is sent to combiner and in status
  • Updated README (minimal example of ML training will be added in a new issue)

@Wrede Wrede changed the title Feature/SK-1102 | Simplify ClientAPI and add support for inference Feature/SK-1102 | Simplify ClientAPI and add support for inference Nov 5, 2024
@benjaminastrand benjaminastrand marked this pull request as ready for review November 5, 2024 14:04
@Wrede Wrede changed the title Feature/SK-1102 | Simplify ClientAPI and add support for inference Feature/SK-1102 | Simplify ClientAPI and add support for inference Nov 5, 2024
Copy link
Member

@Wrede Wrede left a comment

Choose a reason for hiding this comment

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

Imo I think you should change the Name of ClientAPI to maybe Project, ProjectManager, Context, ContextManager and import it into the root init so that you can:
from fedn import Context

@benjaminastrand
Copy link
Contributor

Changed name of client api

  • ClientAPI -> FednClient
  • client_api.py -> fedn_client.py

@Wrede Wrede merged commit 20034b2 into master Nov 11, 2024
19 checks passed
@Wrede Wrede deleted the feature/SK-1102 branch November 11, 2024 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants