nvflare.app_common.response_processors.global_weights_initializer module

class GlobalWeightsInitializer(weights_prop_name: str = 'global_model', weight_method: str = 'first', client_name: str | None = None)[source]

Bases: ResponseProcessor

Set global model weights based on specified weight setting method.

  • weights_prop_name – name of the prop to be set into fl_ctx for the determined global weights

  • weight_method – the method to select final weights: one of “first”, “client”

  • client_name – the name of the client to be used as the weight provider

If weight_method is “first”, then use the weights reported from the first client; If weight_method is “client”, then only use the weights reported from the specified client.

create_task_data(task_name: str, fl_ctx: FLContext) Shareable[source]

Create the data for the task to be sent to clients to collect their weights

  • task_name – name of the task

  • fl_ctx – the FL context

Returns: task data

final_process(fl_ctx: FLContext) bool[source]

Perform the final check on all the received weights from the clients.


fl_ctx – FLContext


boolean indicating whether the final response processing is successful. If not successful, the control flow will exit.

process_client_response(client: Client, task_name: str, response: Shareable, fl_ctx: FLContext) bool[source]

Process the weights submitted by a client.

  • client – the client that submitted the response

  • task_name – name of the task

  • response – submitted data from the client

  • fl_ctx – FLContext


boolean to indicate if the client data is acceptable. If not acceptable, the control flow will exit.

class WeightMethod[source]

Bases: object

CLIENT = 'client'
FIRST = 'first'