Context#

class pfl.context.LocalResultMetaData(num_steps)#

Data that is typically returned by a model’s local optimization procedure, e.g. PyTorchModel.do_multiple_epochs_of. Can have useful information needed by the algorithm.

Parameters:

num_steps (int) – The number of local steps taken during the local optimization procedure.

class pfl.context.UserContext(num_datapoints, seed, user_id=None, metrics=<factory>)#

Provides read-only information about the user. This is exposed to postprocessors’ local statistics postprocessing procedure in simulation, see postprocess_one_user.

Parameters:
  • num_datapoints (int) – The number of datapoints of the user.

  • seed (Optional[int]) – A seed to use for any stochastic postprocessing operations.

  • user_id (Optional[str]) – ID of user. Can be None if user didn’t specify any user IDs, which is fine if there are no algorithms in use that require user IDs.

  • metrics (Metrics) – The metrics collected in the current central iteration for the user this context belongs to.

class pfl.context.CentralContext(current_central_iteration, do_evaluation, cohort_size, population, algorithm_params, model_train_params, model_eval_params=None, seed=None)#

Provides read-only information about server-side parameters. This is exposed to:

Parameters:
  • current_central_iteration (int) – The current central iteration number, starting at 0.

  • do_evaluation (bool) – Whether the local evaluations need to be done or not. This can speed up the simulation considerably if the multiple local evaluations are expensive compared to the local training and the adopters need the metrics only sporadically (typically, every nth round).

  • cohort_size (int) – The requested cohort size.

  • population (Population) – The population to target with this context.

  • algorithm_params (TypeVar(AlgorithmHyperParamsType, bound= AlgorithmHyperParams)) – The algorithm context for this central iteration.

  • model_train_params (TypeVar(ModelHyperParamsType, bound= ModelHyperParams)) – Hyper-parameter configuration for local training of model.

  • model_eval_params (Optional[TypeVar(ModelHyperParamsType, bound= ModelHyperParams)]) – Hyper-parameter configuration for evaluation of model.

  • seed (Optional[int]) – A seed to use for any stochastic postprocessing operations.

property state_description#

Description of current state of training.