Strategies¶
Federated Averaging¶
 class substrafl.strategies.FedAvg(algo: algorithms.algo.Algo)¶
Bases:
substrafl.strategies.strategy.Strategy
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 clientsTrainDataNode
andTestDataNode
.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)
Compute the weighted average of all elements returned by the train methods of the userdefined 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
 property name: substrafl.strategies.schemas.StrategyName¶
The name of the strategy
 Returns
Name of the strategy
 Return type
 perform_predict(test_data_nodes: List[substrafl.nodes.test_data_node.TestDataNode], train_data_nodes: List[substrafl.nodes.train_data_node.TrainDataNode], 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: List[substrafl.nodes.train_data_node.TrainDataNode], aggregation_node: organizations.aggregation_node.AggregationNode, round_idx: int, clean_models: bool, additional_orgs_permissions: Optional[set] = 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 minibatches) of the models on each train data node
 if
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 minibatches) 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 reuse 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)¶
Bases:
substrafl.strategies.strategy.Strategy
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 noniid 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 clientsTrainDataNode
andTestDataNode
. Parameters
Performs the aggregation of the shared states returned by the train methods of the userdefined algorithm, according to the server operations of the Scaffold Algo.
Computes the weighted average of the weight updates and applies the aggregation learning rate
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
 property name: substrafl.strategies.schemas.StrategyName¶
The name of the strategy
 Returns
Name of the strategy
 Return type
 perform_predict(test_data_nodes: List[substrafl.nodes.test_data_node.TestDataNode], train_data_nodes: List[substrafl.nodes.train_data_node.TrainDataNode], 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: List[substrafl.nodes.train_data_node.TrainDataNode], aggregation_node: organizations.aggregation_node.AggregationNode, round_idx: int, clean_models: bool, additional_orgs_permissions: Optional[set] = None)¶
 One round of the Scaffold strategy consists in:
 if
round_idx==0
: initialize the strategy by performing a local update (train on n minibatches) of the models on each train data nodes
 if
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 minibatches) 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 reuse 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)¶
Bases:
substrafl.strategies.strategy.Strategy
NewtonRaphson strategy.
NewtonRaphson strategy is based on NewtonRaphson 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: Optional[List[substrafl.strategies.schemas.NewtonRaphsonSharedState]]) substrafl.strategies.schemas.NewtonRaphsonAveragedStates ¶
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
 property name: substrafl.strategies.schemas.StrategyName¶
The name of the strategy
 Returns
Name of the strategy
 Return type
 perform_predict(test_data_nodes: List[substrafl.nodes.test_data_node.TestDataNode], train_data_nodes: List[substrafl.nodes.train_data_node.TrainDataNode], 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: List[substrafl.nodes.train_data_node.TrainDataNode], aggregation_node: organizations.aggregation_node.AggregationNode, round_idx: int, clean_models: bool, additional_orgs_permissions: Optional[set] = None)¶
One round of the NewtonRaphson strategy consists in:
if
round_ids==0
: initialize the strategy by performing a local update of the models on each train data nodesaggregate 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 reuse 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)¶
Bases:
substrafl.strategies.strategy.Strategy
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 columnwise 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 columnwise means of data.
 Step 2:
Each center normalize their dataset by subtracting the global mean columnwise and compute the covariance matrix of their local data after meansubtraction. 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^{r1}_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\) eigenvectors of the global covariance matrix with the highest eigenvalues.
 Parameters
algo (Algo) – The algorithm your strategy will execute (i.e. train and test on all the specified nodes)
Compute the weighted average of all elements returned by the train methods of the userdefined 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
Compute the weighted average of all elements returned by the train methods of the userdefined algorithm and factorize the obtained matrix with a QR decomposition, where Q is orthonormal and R is uppertriangular.
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
 property name: substrafl.strategies.schemas.StrategyName¶
The name of the strategy
 Returns
Name of the strategy
 Return type
 perform_predict(test_data_nodes: List[substrafl.nodes.test_data_node.TestDataNode], train_data_nodes: List[substrafl.nodes.train_data_node.TrainDataNode], 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: List[substrafl.nodes.train_data_node.TrainDataNode], aggregation_node: organizations.aggregation_node.AggregationNode, round_idx: int, clean_models: bool, additional_orgs_permissions: Optional[set] = None) None ¶
The Federated Principal Component Analysis strategy uses the first two rounds as preprocessing 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 reuse 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)¶
Bases:
substrafl.strategies.strategy.Strategy
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
andTestDataNode
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: List[substrafl.nodes.train_data_node.TrainDataNode], clean_models: bool, round_idx: Optional[int] = 0, additional_orgs_permissions: Optional[set] = 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 reuse 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
 perform_predict(test_data_nodes: List[substrafl.nodes.test_data_node.TestDataNode], train_data_nodes: List[substrafl.nodes.train_data_node.TrainDataNode], 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: List[substrafl.nodes.train_data_node.TrainDataNode], round_idx: int, clean_models: bool, aggregation_node: Optional[organizations.aggregation_node.AggregationNode] = None, additional_orgs_permissions: Optional[set] = None)¶
One round of the SingleOrganization strategy: perform a local update (train on n minibatches) 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 reuse 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)¶
Bases:
substrafl.compute_plan_builder.ComputePlanBuilder
Base strategy to be inherited from SubstraFL strategies.
All child class arguments need to be passed to it through its
args
andkwargs
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: List[substrafl.nodes.train_data_node.TrainDataNode], aggregation_node: Optional[List[organizations.aggregation_node.AggregationNode]], evaluation_strategy: Optional[substrafl.evaluation_strategy.EvaluationStrategy], num_rounds: int, clean_models: Optional[bool] = 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 subgraph (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 reuse 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: List[substrafl.nodes.train_data_node.TrainDataNode], clean_models: bool, round_idx: Optional[int] = 0, additional_orgs_permissions: Optional[set] = 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 reuse 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
 load_local_state(path: pathlib.Path) Any ¶
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
The loaded element.
 Return type
 abstract property name: substrafl.strategies.schemas.StrategyName¶
The name of the strategy
 Returns
Name of the strategy
 Return type
 abstract perform_predict(test_data_nodes: List[substrafl.nodes.test_data_node.TestDataNode], train_data_nodes: List[substrafl.nodes.train_data_node.TrainDataNode], 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: List[substrafl.nodes.train_data_node.TrainDataNode], aggregation_node: Optional[organizations.aggregation_node.AggregationNode], round_idx: int, clean_models: bool, additional_orgs_permissions: Optional[set] = 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 reuse 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: List[numpy.ndarray])¶
Bases:
substrafl.strategies.schemas._Model
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 if the input data cannot be parsed to form a valid model.
 Parameters
avg_parameters_update (List[numpy.ndarray]) –
 Return type
None
Bases:
substrafl.strategies.schemas._Model
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 if the input data cannot be parsed to form a valid model.
 Parameters
n_samples (int) –
parameters_update (List[numpy.ndarray]) –
 Return type
None
 class substrafl.strategies.schemas.FedPCAAveragedState(*, avg_parameters_update: List[numpy.ndarray])¶
Bases:
substrafl.strategies.schemas._Model
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 if the input data cannot be parsed to form a valid model.
 Parameters
avg_parameters_update (List[numpy.ndarray]) –
 Return type
None
Bases:
substrafl.strategies.schemas._Model
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 if the input data cannot be parsed to form a valid model.
 Parameters
n_samples (int) –
parameters_update (List[numpy.ndarray]) –
 Return type
None
 class substrafl.strategies.schemas.NewtonRaphsonAveragedStates(*, parameters_update: List[numpy.ndarray])¶
Bases:
substrafl.strategies.schemas._Model
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 if the input data cannot be parsed to form a valid model.
Bases:
substrafl.strategies.schemas._Model
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 if the input data cannot be parsed to form a valid model.
 class substrafl.strategies.schemas.ScaffoldAveragedStates(*, server_control_variate: List[numpy.ndarray], avg_parameters_update: List[numpy.ndarray])¶
Bases:
substrafl.strategies.schemas._Model
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 if the input data cannot be parsed to form a valid model.
Bases:
substrafl.strategies.schemas._Model
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 finetuned 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 if the input data cannot be parsed to form a valid model.
 class substrafl.strategies.schemas.StrategyName(value)¶

An enumeration.
 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 if the input data cannot be parsed to form a valid model.
 Return type
None