# Strategies¶

## Federated Averaging¶

class substrafl.strategies.FedAvg(algo: algorithms.algo.Algo)

Federated averaging strategy.

Federated averaging is the simplest federating strategy. A round consists in performing a predefined number of forward/backward passes on each client, aggregating updates by computing their means and distributing the consensus update to all clients. In FedAvg, strategy is performed in a centralized way, where a single server or AggregationNode communicates with a number of clients TrainDataNode and TestDataNode.

Formally, if $$w_t$$ denotes the parameters of the model at round $$t$$, a single round consists in the following steps:

$\Delta w_t^{k} = \mathcal{O}^k_t(w_t| X_t^k, y_t^k, m) \Delta w_t = \sum_{k=1}^K \frac{n_k}{n} \Delta w_t^k w_{t + 1} = w_t + \Delta w_t$

where $$\mathcal{O}^k_t$$ is the local optimizer algorithm of client $$k$$ taking as argument the averaged weights as well as the $$t$$-th batch of data for local worker $$k$$ and the number of local updates $$m$$ to perform, and where $$n_k$$ is the number of samples for worker $$k$$, $$n = \sum_{k=1}^K n_k$$ is the total number of samples.

Parameters

algo (Algo) – The algorithm your strategy will execute (i.e. train and test on all the specified nodes)

avg_shared_states(shared_states: )

Compute the weighted average of all elements returned by the train methods of the user-defined algorithm. The average is weighted by the proportion of the number of samples.

Example

shared_states = [
{"weights": [3, 3, 3], "gradient": [4, 4, 4], "n_samples": 20},
{"weights": [6, 6, 6], "gradient": [1, 1, 1], "n_samples": 40},
]
result = {"weights": [5, 5, 5], "gradient": [2, 2, 2]}

Parameters

shared_states (List[FedAvgSharedState]) – The list of the shared_state returned by the train method of the algorithm for each organization.

Raises
• EmptySharedStatesError – The train method of your algorithm must return a shared_state

• TypeError – Each shared_state must contains the key n_samples

• TypeError – Each shared_state must contains at least one element to average

• TypeError – All the elements of shared_states must be similar (same keys)

• TypeError – All elements to average must be of type np.ndarray

Returns

A dict containing the weighted average of each input parameters without the passed key “n_samples”.

Return type

FedAvgAveragedState

property name: substrafl.strategies.schemas.StrategyName

The name of the strategy

Returns

Name of the strategy

Return type

StrategyName

perform_predict(test_data_nodes: , train_data_nodes: , round_idx: int)

Perform prediction on test_data_nodes.

Parameters
• test_data_nodes (List[TestDataNode]) – test data nodes to perform the prediction from the algo on.

• train_data_nodes (List[TrainDataNode]) – train data nodes the model has been trained on.

• round_idx (int) – round index.

perform_round(*, train_data_nodes: , aggregation_node: organizations.aggregation_node.AggregationNode, round_idx: int, clean_models: bool, additional_orgs_permissions: = None)
One round of the Federated Averaging strategy consists in:
• if round_idx==0: initialize the strategy by performing a local update

(train on n mini-batches) of the models on each train data node

• aggregate the model shared_states

• set the model weights to the aggregated weights on each train data nodes

• perform a local update (train on n mini-batches) of the models on each train data nodes

Parameters
• train_data_nodes (List[TrainDataNode]) – List of the nodes on which to perform local updates.

• aggregation_node (AggregationNode) – Node without data, used to perform operations on the shared states of the models

• round_idx (int) – Round number, it starts at 0.

• clean_models (bool) – Clean the intermediary models of this round on the Substra platform. Set it to False if you want to download or re-use intermediary models. This causes the disk space to fill quickly so should be set to True unless needed.

• additional_orgs_permissions (Optional[set]) – Additional permissions to give to the model outputs after training, in order to test the model on an other organization.

## Scaffold¶

class substrafl.strategies.Scaffold(algo: algorithms.algo.Algo, aggregation_lr: float = 1)

Scaffold strategy. Paper: https://arxiv.org/pdf/1910.06378.pdf Scaffold is Federated Averaging with control variates. By adding auxiliary variables in the clients and server the authors of the related paper prove better bounds on the convergence assuming certain hypothesis, in particular with non-iid data.

A round consists in performing a predefined number of forward/backward passes on each client, aggregating updates by computing their means and distributing the consensus update to all clients. In Scaffold, strategy is performed in a centralized way, where a single server or AggregationNode communicates with a number of clients TrainDataNode and TestDataNode.

Parameters
• algo (Algo) – The algorithm your strategy will execute (i.e. train and test on all the specified nodes)

• aggregation_lr (float, Optional) – Global aggregation rate applied on the averaged weight updates (eta_g in the paper). Defaults to 1. Must be >=0.

avg_shared_states(shared_states: )

Performs the aggregation of the shared states returned by the train methods of the user-defined algorithm, according to the server operations of the Scaffold Algo.

1. Computes the weighted average of the weight updates and applies the aggregation learning rate

2. Updates the server control variate with the weighted average of the control variate updates

The average is weighted by the proportion of the number of samples.

Parameters

shared_states (List[ScaffoldSharedState]) – Shared state returned by the train method of the algorithm for each client (e.g. algorithms.pytorch.scaffold.train)

Returns

averaged weight updates and updated server control variate

Return type

ScaffoldAveragedStates

property name: substrafl.strategies.schemas.StrategyName

The name of the strategy

Returns

Name of the strategy

Return type

StrategyName

perform_predict(test_data_nodes: , train_data_nodes: , round_idx: int)

Perform prediction on test_data_nodes.

Parameters
• test_data_nodes (List[TestDataNode]) – test data nodes to perform the prediction from the algo on.

• train_data_nodes (List[TrainDataNode]) – train data nodes the model has been trained on.

• round_idx (int) – round index.

perform_round(*, train_data_nodes: , aggregation_node: organizations.aggregation_node.AggregationNode, round_idx: int, clean_models: bool, additional_orgs_permissions: = None)
One round of the Scaffold strategy consists in:
• if round_idx==0: initialize the strategy by performing a local update

(train on n mini-batches) of the models on each train data nodes

• aggregate the model shared_states

• set the model weights to the aggregated weights on each train data nodes

• perform a local update (train on n mini-batches) of the models on each train data nodes

Parameters
• train_data_nodes (List[TrainDataNode]) – List of the organizations on which to perform

• aggregation_node (organizations.aggregation_node.AggregationNode) – Node without data, used to perform operations on the shared states of the models

• round_idx (int) – Round number, it starts at 0.

• clean_models (bool) – Clean the intermediary models of this round on the Substra platform. Set it to False if you want to download or re-use intermediary models. This causes the disk space to fill quickly so should be set to True unless needed.

• additional_orgs_permissions (Optional[set]) – Additional permissions to give to the model outputs after training, in order to test the model on an other organization.

• aggregation_node

## Newton Raphson¶

class substrafl.strategies.NewtonRaphson(algo: algorithms.algo.Algo, damping_factor: float)

Newton-Raphson strategy.

Newton-Raphson strategy is based on Newton-Raphson distributed method. It leads to a faster divergence than a standard FedAvg strategy, however it can only be used on convex problems.

In a local step, the first order derivative (gradients) and the second order derivative (Hessian Matrix) of loss with respect to weights is calculated for each node.

Hessians and gradients are averaged on the aggregation node.

Updates of the weights are then calculated using the formula:

$update = -\eta * H^{-1}_\theta.\Delta_\theta$

Where $$H$$ is the Hessian of the loss with respect to $$\theta$$ and $$\Delta_\theta$$ is the gradients of the loss with respect to $$\theta$$ and $$0 < \eta <= 1$$ is the damping factor.

Parameters
• algo (Algo) – The algorithm your strategy will execute (i.e. train and test on all the specified nodes)

• damping_factor (float) – Must be between 0 and 1. Multiplicative coefficient of the parameters update. Smaller value for $$\eta$$ will increase the stability but decrease the speed of convergence of the gradient descent. Recommended value: damping_factor=0.8.

compute_averaged_states(shared_states: )

Given the gradients and the Hessian (the second order derivative of loss with respect to weights), updates of the weights are calculated using the formula:

$update = -\eta * H^{-1}_\theta.\Delta_\theta$

Where $$H$$ is the Hessian of the loss with respect to $$\theta$$ and $$\Delta_\theta$$ is the gradients of the loss with respect to $$\theta$$ and $$0 < \eta <= 1$$ is the damping factor.

The average is weighted by the number of samples.

Example

shared_states = [
{"gradients": [1, 1, 1], "hessian": [[1, 0, 0], [0, 1, 0], [0, 0, 1]], "n_samples": 2},
{"gradients": [2, 2, 2], "hessian": [[2, 0, 0], [0, 2, 0], [0, 0, 2]], "n_samples": 1}
]
damping_factor = 1

average = {"gradients": [4/3, 4/3, 4/3], "hessian": [[4/3, 0, 0],[0, 4/3, 0], [0, 0, 4/3]]}

Parameters

shared_states (List[NewtonRaphsonSharedState]) – The list of the shared_state returned by the train method of the algorithm for each node.

Raises
• EmptySharedStatesError – The train method of your algorithm must return a shared_state

• TypeError – Each shared_state must contains the key n_samples, gradients and hessian

• TypeError – Each shared_state must contains at least one element to average

• TypeError – All the elements of shared_states must be similar (same keys)

• TypeError – All elements to average must be of type np.array

Returns

A dict containing the parameters updates of each input parameters.

Return type

NewtonRaphsonAveragedStates

property name: substrafl.strategies.schemas.StrategyName

The name of the strategy

Returns

Name of the strategy

Return type

StrategyName

perform_predict(test_data_nodes: , train_data_nodes: , round_idx: int)

Perform prediction on test_data_nodes.

Parameters
• test_data_nodes (List[TestDataNode]) – test data nodes to perform the prediction from the algo on.

• train_data_nodes (List[TrainDataNode]) – train data nodes the model has been trained on.

• round_idx (int) – round index.

perform_round(*, train_data_nodes: , aggregation_node: organizations.aggregation_node.AggregationNode, round_idx: int, clean_models: bool, additional_orgs_permissions: = None)

One round of the Newton-Raphson strategy consists in:

• if round_ids==0: initialize the strategy by performing a local update of the models on each train data nodes

• aggregate the model shared_states

• set the model weights to the aggregated weights on each train data nodes

• perform a local update of the models on each train data nodes

Parameters
• train_data_nodes (List[TrainDataNode]) – List of the nodes on which to perform local updates

• aggregation_node (AggregationNode) – node without data, used to perform operations on the shared states of the models

• round_idx (int) – Round number, it starts at 0.

• clean_models (bool) – Clean the intermediary models of this round on the Substra platform. Set it to False if you want to download or re-use intermediary models. This causes the disk space to fill quickly so should be set to True unless needed.

• additional_orgs_permissions (Optional[set]) – Additional permissions to give to the model outputs after training, in order to test the model on an other organization.

## Fed PCA¶

class substrafl.strategies.FedPCA(algo: algorithms.algo.Algo)

Federated Principal Component Analysis strategy.

The goal of this strategy is to perform a principal component analysis (PCA) by computing the eigen vectors with highest eigen values of the covariance matrices regarding the provided data.

We assume we have clients indexed by $$j$$, with $$n_j$$ samples each.

We note $$N = \sum_j n_j$$ the total number of samples. We denote $$D$$ the dimension of the data, and $$K$$ the number of eigen vectors computed.

This strategy implementation is based on the federated iteration algorithm described by:

Anne Hartebrodt, Richard Röttger, Federated horizontally partitioned principal component analysis for biomedical applications, Bioinformatics Advances, Volume 2, Issue 1, 2022, vbac026, https://doi.org/10.1093/bioadv/vbac026 (algorithm 3 of the paper)

During the process, the local covariance matrices of each center are not shared. However, the column-wise mean of each dataset is shared across the centers.

The federated iteration is divided in three steps.

Step 1:
• For $$d= 1, ..., D$$, each center computes the mean of the $$d$$ component of their dataset and share it to the central aggregator. The central aggregator averages the local mean and send to all the clients the global column-wise means of data.

Step 2:
• Each center normalize their dataset by subtracting the global mean column-wise and compute the covariance matrix of their local data after mean-subtraction. We denote by $$C_j$$ the local covariance matrices.

We initialize $$eig_0$$: a matrix of size $$D \times K$$ corresponding to the $$K$$ eigen vectors we want to compute

Step 3, for a given number of rounds (rounds are labeled by $$r$$) we perform the following:
Step 3.1:
• Each center $$j$$ computes $$eig^r_j = C_j.eig^{r-1}_j$$

Step 3.2:
• The aggregator computes $$eig^r = \frac{1}{N}\sum_j n_j eig^r_j$$

Step 3:3:
• The aggregator performs a QR decomposition: $$eig^r \mapsto QR(eig^r)$$ and shares $$eig^r$$ to all the clients

$$eig^r$$ will converge to the $$K$$ eigen-vectors of the global covariance matrix with the highest eigen-values.

Parameters

algo (Algo) – The algorithm your strategy will execute (i.e. train and test on all the specified nodes)

avg_shared_states(shared_states: )

Compute the weighted average of all elements returned by the train methods of the user-defined algorithm. The average is weighted by the proportion of the number of samples.

Example

shared_states = [
{"parameters_update": [3, 6, 1], "n_samples": 20},
{"parameters_update": [6, 3, 1], "n_samples": 40},
]
result = {"parameters_update": [5, 4, 1]}

Parameters

shared_states (List[FedPCASharedState]) – The list of the shared_state returned by the train method of the algorithm for each organization.

Raises
• EmptySharedStatesError – The train method of your algorithm must return a shared_state

• TypeError – Each shared_state must contains the key n_samples

• TypeError – Each shared_state must contains at least one element to average

• TypeError – All the elements of shared_states must be similar (same keys)

• TypeError – All elements to average must be of type np.ndarray

Returns

A dict containing the weighted average of each input parameters without the passed key “n_samples”.

Return type

FedPCAAveragedState

avg_shared_states_with_qr(shared_states: )

Compute the weighted average of all elements returned by the train methods of the user-defined algorithm and factorize the obtained matrix with a QR decomposition, where Q is orthonormal and R is upper-triangular.

The returned FedPCAAveragedState the Q matrix only.

Parameters

shared_states (List[FedPCASharedState]) – The list of the shared_state returned by the train method of the algorithm for each organization.

Raises

EmptySharedStatesError – The train method of your algorithm must return a shared_state

Returns

returned the Q matrix as a FedPCAAveragedState.

Return type

FedPCAAveragedState

property name: substrafl.strategies.schemas.StrategyName

The name of the strategy

Returns

Name of the strategy

Return type

StrategyName

perform_predict(test_data_nodes: , train_data_nodes: , round_idx: int) None

Perform prediction on test_data_nodes. Perform prediction before round 3 is not take into account as all objects to compute prediction are not initialize before the second round.

Parameters
• test_data_nodes (List[TestDataNode]) – test data nodes to perform the prediction from the algo on.

• train_data_nodes (List[TrainDataNode]) – train data nodes the model has been trained on.

• round_idx (int) – round index.

Return type

None

perform_round(train_data_nodes: , aggregation_node: organizations.aggregation_node.AggregationNode, round_idx: int, clean_models: bool, additional_orgs_permissions: = None) None

The Federated Principal Component Analysis strategy uses the first two rounds as pre-processing rounds.

Three type of rounds:
• Compute the average mean on all centers at round 1.

• Compute the local covariance matrix of each center at round 2.

• Use the local covariance matrices to compute the orthogonal matrix for every next rounds.

Parameters
• train_data_nodes (List[TrainDataNode]) – List of the nodes on which to perform local updates.

• aggregation_node (AggregationNode) – Node without data, used to perform operations on the shared states of the models

• round_idx (int) – Round number, it starts at 0.

• clean_models (bool) – Clean the intermediary models of this round on the Substra platform. Set it to False if you want to download or re-use intermediary models. This causes the disk space to fill quickly so should be set to True unless needed.

• additional_orgs_permissions (Optional[set]) – Additional permissions to give to the model outputs after training, in order to test the model on an other organization.

Return type

None

## Single Organization¶

class substrafl.strategies.SingleOrganization(algo: algorithms.algo.Algo)

Single organization strategy.

Single organization is not a real federated strategy and it is rather used for testing as it is faster than other ‘real’ strategies. The training and prediction are performed on a single Node. However, the number of passes to that Node (num_rounds) is still defined to test the actual federated setting. In SingleOrganization strategy a single client TrainDataNode and TestDataNode performs all the model execution.

Parameters

algo (Algo) – The algorithm your strategy will execute (i.e. train and test on all the specified nodes)

initialization_round(*, train_data_nodes: , clean_models: bool, round_idx: = 0, additional_orgs_permissions: = None)

Call the initialize function of the algo on each train node.

Parameters
• train_data_nodes (List[TrainDataNode]) – list of the train organizations

• clean_models (bool) – Clean the intermediary models of this round on the Substra platform. Set it to False if you want to download or re-use intermediary models. This causes the disk space to fill quickly so should be set to True unless needed.

• round_idx (Optional[int]) – index of the round. Defaults to 0.

• additional_orgs_permissions (Optional[set]) – Additional permissions to give to the model outputs after training, in order to test the model on an other organization. Default to None

property name: substrafl.strategies.schemas.StrategyName

The name of the strategy

Returns

Name of the strategy

Return type

StrategyName

perform_predict(test_data_nodes: , train_data_nodes: , round_idx: int)

Perform prediction on test_data_nodes.

Parameters
• test_data_nodes (List[TestDataNode]) – test data nodes to perform the prediction from the algo on.

• train_data_nodes (List[TrainDataNode]) – train data nodes the model has been trained on.

• round_idx (int) – round index.

perform_round(*, train_data_nodes: , round_idx: int, clean_models: bool, aggregation_node: = None, additional_orgs_permissions: = None)

One round of the SingleOrganization strategy: perform a local update (train on n mini-batches) of the models on a given data node

Parameters
• train_data_nodes (List[TrainDataNode]) – List of the nodes on which to perform local updates, there should be exactly one item in the list.

• aggregation_node (AggregationNode) – Should be None otherwise it will be ignored

• round_idx (int) – Round number, it starts at 0.

• clean_models (bool) – Clean the intermediary models of this round on the Substra platform. Set it to False if you want to download or re-use intermediary models. This causes the disk space to fill quickly so should be set to True unless needed.

• additional_orgs_permissions (Optional[set]) – Additional permissions to give to the model outputs after training, in order to test the model on an other organization.

## Strategies Base Class¶

class substrafl.strategies.strategy.Strategy(algo: algorithms.algo.Algo, *args, **kwargs)

Base strategy to be inherited from SubstraFL strategies.

All child class arguments need to be passed to it through its args and kwargs in order to use them when instantiating it as a RemoteStruct in each process.

Example

class MyStrat(Strategy):
def __init__(self, algo, my_custom_arg):
super().__init__(algo=algo, my_custom_arg=my_custom_arg)

Parameters

algo (Algo) – The algorithm your strategy will execute (i.e. train and test on all the specified nodes)

Raises

exceptions.IncompatibleAlgoStrategyError – Raise an error if the strategy name is not in algo.strategies.

build_compute_plan(train_data_nodes: , aggregation_node: , evaluation_strategy: , num_rounds: int, clean_models: = True) None

Build the compute plan of the strategy. The built graph will be stored by side effect in the given train_data_nodes, aggregation_nodes and evaluation_strategy. This function create a graph be first calling the initialization_round method of the strategy at round 0, and then call the perform_round method for each new round. If the current round is part of the evaluation strategy, the perform_predict method is called to complete the graph.

Parameters
• train_data_nodes (List[TrainDataNode]) – list of the train organizations

• aggregation_node (Optional[AggregationNode]) – aggregation node, necessary for centralized strategy, unused otherwise

• evaluation_strategy (Optional[EvaluationStrategy]) – evaluation strategy to follow for testing models.

• num_rounds (int) – Number of times to repeat the compute plan sub-graph (define in perform round).

• clean_models (bool) – Clean the intermediary models on the Substra platform. Set it to False if you want to download or re-use intermediary models. This causes the disk space to fill quickly so should be set to True unless needed. Defaults to True.

Returns

None

Return type

None

initialization_round(*, train_data_nodes: , clean_models: bool, round_idx: = 0, additional_orgs_permissions: = None)

Call the initialize function of the algo on each train node.

Parameters
• train_data_nodes (List[TrainDataNode]) – list of the train organizations

• clean_models (bool) – Clean the intermediary models of this round on the Substra platform. Set it to False if you want to download or re-use intermediary models. This causes the disk space to fill quickly so should be set to True unless needed.

• round_idx (Optional[int]) – index of the round. Defaults to 0.

• additional_orgs_permissions (Optional[set]) – Additional permissions to give to the model outputs after training, in order to test the model on an other organization. Default to None

Executed at the beginning of each step of the computation graph to load on each organization the previously saved local state.

Parameters

path (pathlib.Path) – The path where the previous local state has been saved.

Returns

Return type

Any

abstract property name: substrafl.strategies.schemas.StrategyName

The name of the strategy

Returns

Name of the strategy

Return type

StrategyName

abstract perform_predict(test_data_nodes: , train_data_nodes: , round_idx: int)

Perform the prediction of the algo on each test nodes. Gets the model for a train organization and compute the prediction on the test nodes.

Parameters
• test_data_nodes (List[TestDataNode]) – list of nodes on which to evaluate

• train_data_nodes (List[TrainDataNode]) – list of nodes on which the model has been trained

• round_idx (int) – index of the round

abstract perform_round(*, train_data_nodes: , aggregation_node: , round_idx: int, clean_models: bool, additional_orgs_permissions: = None)

Perform one round of the strategy

Parameters
• train_data_nodes (List[TrainDataNode]) – list of the train organizations

• aggregation_node (Optional[AggregationNode]) – aggregation node, necessary for centralized strategy, unused otherwise

• round_idx (int) – index of the round

• clean_models (bool) – Clean the intermediary models of this round on the Substra platform. Set it to False if you want to download or re-use intermediary models. This causes the disk space to fill quickly so should be set to True unless needed.

• additional_orgs_permissions (Optional[set]) – Additional permissions to give to the model outputs after training, in order to test the model on an other organization.

save_local_state(path: pathlib.Path) None

Executed at the end of each step of the computation graph to save the local state locally on each organization.

Parameters

path (pathlib.Path) – The path where the previous local state has been saved.

Returns

None

Return type

None

## Schemas¶

Schemas used in the strategies.

class substrafl.strategies.schemas.FedAvgAveragedState(*, avg_parameters_update: )

Shared state sent by the aggregate_organization in the federated averaging strategy.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Parameters

avg_parameters_update (List[numpy.ndarray]) –

Return type

None

class substrafl.strategies.schemas.FedAvgSharedState(*, n_samples: int, parameters_update: )

Shared state returned by the train method of the algorithm for each client, received by the aggregate function in the federated averaging strategy.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Parameters
Return type

None

class substrafl.strategies.schemas.FedPCAAveragedState(*, avg_parameters_update: )

Shared state sent by the aggregate_organization in the federated PCA strategy.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Parameters

avg_parameters_update (List[numpy.ndarray]) –

Return type

None

class substrafl.strategies.schemas.FedPCASharedState(*, n_samples: int, parameters_update: )

Shared state returned by the train method of the algorithm for each client, received by the aggregate function in the federated PCA strategy.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Parameters
Return type

None

class substrafl.strategies.schemas.NewtonRaphsonAveragedStates(*, parameters_update: )

Shared state sent by the aggregate_organization in the Newton Raphson strategy.

Parameters

parameters_update (numpy.ndarray) – the new parameters_update sent to the clients

Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

class substrafl.strategies.schemas.NewtonRaphsonSharedState(*, n_samples: int, gradients: , hessian: numpy.ndarray)

Shared state returned by the train method of the algorithm for each client, received by the aggregate function in the Newton Raphson strategy.

Parameters
• n_samples (int) – number of samples of the client dataset.

• gradients (numpy.ndarray) – gradients of the model parameters $$\theta$$.

• hessian (numpy.ndarray) – second derivative of the loss function regarding the model parameters $$\theta$$.

Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

class substrafl.strategies.schemas.ScaffoldAveragedStates(*, server_control_variate: , avg_parameters_update: )

Shared state sent by the aggregate_organization (returned by the func strategies.scaffold.avg_shared_states)

Parameters
• server_control_variate (List[numpy.ndarray]) – the new server_control_variate sent to the clients

• avg_parameters_update (List[numpy.ndarray]) – the weighted average of the parameters_update from each client

Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

class substrafl.strategies.schemas.ScaffoldSharedState(*, parameters_update: , control_variate_update: , n_samples: int, server_control_variate: )

Shared state returned by the train method of the algorithm for each client (e.g. algorithms.pytorch.scaffold.train)

Parameters
• parameters_update (List[numpy.ndarray]) – the weight update of the client (delta between fine-tuned weights and previous weights)

• control_variate_update (List[numpy.ndarray]) – the control_variate update of the client

• n_samples (int) – the number of samples of the client

• server_control_variate (List[numpy.ndarray]) – the server control variate (c in the Scaffold paper’s Algo). It is sent by every client as the aggregation node doesn’t have a persistent state, and should be the same for each client as it should not be modified in the client Algo

Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

class substrafl.strategies.schemas.StrategyName(value)

An enumeration.

_generate_next_value_(start, count, last_values)

Generate the next value when not given.

name: the name of the member start: the initial start value or None count: the number of existing members last_value: the last value assigned or None

_member_type_

alias of str

class substrafl.strategies.schemas._Model

Bases: pydantic.main.BaseModel

Base model configuration

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Return type

None