fed_learn.handlers package

class Handler

Bases: object

This class defines the abstract behavior required of a Handler.

A handler is an object that listens to certain AutoML workflow events and takes actions on such events.

after_aggregation(ctx: fed_learn.model_meta.FLContext)

FL server finish the aggregation process of the round.

Parameters

ctx – the job context

before_aggregation(ctx: fed_learn.model_meta.FLContext)

FL server starts the aggregation process of the round.

Parameters

ctx – the job context

client_quit(ctx: fed_learn.model_meta.FLContext)

FL client has quit. :param ctx: the main context

client_register(ctx: fed_learn.model_meta.FLContext)

A new FL client has registered. :param ctx: the main context

end_round(ctx: fed_learn.model_meta.FLContext)

FL round of process has ended. :param ctx: the main context

handle_event(event: str, ctx: fed_learn.model_meta.FLContext)

The default event handler that calls a predefined method for each event type.

Parameters
  • event – event to be handled

  • ctx – context for cross-component data sharing

receive_contribution(ctx: fed_learn.model_meta.FLContext)

FL server receive a contribution from one client.

Parameters

ctx – the job context

receive_model(ctx: fed_learn.model_meta.FLContext)

FL client receives current model from server.

Parameters

ctx – the job context

receive_validation_models(ctx: fed_learn.model_meta.FLContext)

FL client receives models from server for validation.

Parameters

ctx – the job context

rollback(ctx: fed_learn.model_meta.FLContext)

Rollback any changes made to FL Context by the handler.

Parameters

ctx (FLContext) – Job context

send_best_model(ctx: fed_learn.model_meta.FLContext)

FL client sends best model to server.

Parameters

ctx – the job context

send_global_model(ctx: fed_learn.model_meta.FLContext)

FL server send the global model to a client. :param ctx: the main context

send_validation_results(ctx: fed_learn.model_meta.FLContext)

FL client sends validation results to server.

Parameters

ctx – the job context

shutdown(ctx: fed_learn.model_meta.FLContext)

The handler is being shutdown. Use this method to clean up the handler.

NOTE: this method is called in the reverse order of handler chain. If your handler depends on other handlers, your handler will be shutdown before the handlers you depend on.

Parameters

ctx

startup(ctx: fed_learn.model_meta.FLContext)

The handler is being started up. Use this method to initialize the handler based on info in the context.

NOTE: this method is called in the order of handler chain. If your handler depends on some info provided by previous handlers, you can get such info from the ctx.

Parameters

ctx – main context

fire_event(event: str, handlers: list, ctx: fed_learn.model_meta.FLContext)

Fires the specified event and invokes the list of handlers.

Parameters
  • event – the event to be fired

  • handlers – handlers to be invoked

  • ctx – context for cross-component data sharing

class ModelSelectionHandler(weigh_by_local_iter=False, validation_metric_name='initial_validation_metric', aggregation_weights={'1': 1.0, '2': 1.0})

Bases: fed_learn.handlers.handler.Handler

Parameters
  • weigh_by_local_iter – default False

  • validation_metric_name – meta data name used for model selection

before_aggregation(fl_ctx)

FL server starts the aggregation process of the round.

Parameters

ctx – the job context

rollback(fl_ctx)

Rollback is called if exception occurs in handler.

startup(fl_ctx)

The handler is being started up. Use this method to initialize the handler based on info in the context.

NOTE: this method is called in the order of handler chain. If your handler depends on some info provided by previous handlers, you can get such info from the ctx.

Parameters

ctx – main context

class ServerValidationHandler(evaluator: fed_learn.components.model_evaluator.ModelEvaluator, num_rounds_per_valid: int)

Bases: fed_learn.handlers.handler.Handler

Parameters
  • evaluator – A model evaluator.

  • num_rounds_per_valid – number of rounds per validation.

after_aggregation(fl_ctx)

FL server finish the aggregation process of the round.

Parameters

ctx – the job context

rollback(fl_ctx)

Rollback any changes made to FL Context by the handler.

Parameters

ctx (FLContext) – Job context

startup(fl_ctx)

The handler is being started up. Use this method to initialize the handler based on info in the context.

NOTE: this method is called in the order of handler chain. If your handler depends on some info provided by previous handlers, you can get such info from the ctx.

Parameters

ctx – main context

© Copyright 2020, NVIDIA. Last updated on Feb 2, 2023.