florist.api.routes.server.training module

FastAPI routes for training.

client_training_listener(job, client_info, database)[source]

Listen to the Redis’ channel that reports updates on the training process of a FL client.

Keeps consuming updates to the channel until it finds shutdown in the client metrics.

Parameters:
  • job (Job) – (Job) The job that has this client’s metrics.

  • client_info (ClientInfo) – (ClientInfo) The ClientInfo with the client_uuid to listen to.

  • database (Database[Dict[str, Any]]) – (pymongo.database.Database) An instance of the database to save the information into the Job. MUST BE A SYNCHRONOUS DATABASE since this function cannot be marked as async because of limitations with FastAPI’s BackgroundTasks.

Return type:

None

server_training_listener(job, database)[source]

Listen to the Redis’ channel that reports updates on the training process of a FL server.

Keeps consuming updates to the channel until it finds fit_end in the server metrics, then closes the job with FINISHED_SUCCESSFULLY and saves both the clients and server’s metrics to the job in the database.

Parameters:
  • job (Job) – (Job) The job with the server_uuid to listen to.

  • database (Database[Dict[str, Any]]) – (pymongo.database.Database) An instance of the database to save the information into the Job. MUST BE A SYNCHRONOUS DATABASE since this function cannot be marked as async because of limitations with FastAPI’s BackgroundTasks.

Return type:

None

async start(job_id, request, background_tasks)[source]

Start FL training for a job id by starting a FL server and its clients.

Parameters:
  • job_id (str) – (str) The id of the Job record in the DB which contains the information necessary to start training.

  • request (Request) – (fastapi.Request) the FastAPI request object.

  • background_tasks (BackgroundTasks) – (BackgroundTasks) A BackgroundTasks instance to launch the training listener, which will update the progress of the training job.

Return type:

JSONResponse

Returns:

(JSONResponse) If successful, returns 200 with a JSON containing the UUID for the server and the clients in the format below. The UUIDs can be used to pull metrics from Redis.

{

“server_uuid”: <client uuid>, “client_uuids”: [<client_uuid_1>, <client_uuid_2>, …, <client_uuid_n>],

}

If not successful, returns the appropriate error code with a JSON with the format below:

{“error”: <error message>}