optimization¶
optimization.centralized module¶
- federated.optimization.centralized.centralized_pipeline(name: str, output: str, epochs: int, batch_size: int, optimizer: str, model: str, learning_rate: float) → float¶
Function runs centralized training pipeline.
- Args:
name (str): Name of the experiment.
output (str): Where to save config files. Defaults to history.
epochs (int): Number of epochs. Defaults to 15.
batch_size (int): Batch size. Defaults to 32.
optimizer (str): Which optimizer to use. Defaults to sgd.
model (str): Which model to use.
learning_rate (float): Learning rate to be used. Defaults to 1.0.
- Returns:
float: Training time after centralized learning.
optimization.federated module¶
- federated.optimization.federated.federated_pipeline(name: str, aggregation_method: str, client_weighting: str, keras_model_fn: str, server_optimizer_fn: str, server_optimizer_lr: float, client_optimizer_fn: str, client_optimizer_lr: float, data_selector: str, output: str, client_epochs: int, batch_size: int, number_of_clients: int, number_of_clients_per_round: int, number_of_rounds: int, iterations: int, v: float, compression: bool, dp: bool, noise_multiplier: float, clipping_value: float, seed: Optional[int] = None) → float¶
Function runs federated training pipeline on the dataset.
- Args:
name (str): Experiment name.
aggregation_method (str): Aggregation method. Defaults to “fedavg”.
client_weighting (str): Client weighting. Either Uniform or Data dependent. Defaults to NUM_EXAMPLES.
keras_model_fn (str): Keras Model.
server_optimizer_fn (str): Server Optimizer. Defaults to sgd.
server_optimizer_lr (float): Learning rate for server optimizer. Defaults to 1.0.
client_optimizer_fn (str): Client optimizer. Defaults to sgd.
client_optimizer_lr (float): Learning rate for client optimizer. Defaults to 0.02.
data_selector (str): Data distribution. Defaults to non-iid.
output (str): Where to log files. Defaults to history.
client_epochs (int): Number of client epochs. Defaults to 10.
batch_size (int): Batch size. Defaults to 32.
number_of_clients (int): Number of clients. Defaults to 10.
number_of_clients_per_round (int): Number of clients per round. Defaults to 5.
number_of_rounds (int): Number of global rounds. Defaults to 15.
iterations (int): Number of RFA iterations. Defaults to 3.
v (float): L2 threshold. Defaults to 1e-6.
compression (bool): If the data should be compressed. Defaults to False.
dp (bool): If the differential privacy should be applied. Defaults to False.
noise_multiplier (float): The noise multipler that shoud be used with DP.
clipping_norm (float): The clipping norm used with DP.
seed (int, optional): Random seed. Defaults to None.
- Returns:
float: Returns training time after federated learning.
- federated.optimization.federated.get_optimizer(optimizer: str, learning_rate: float) → Callable[], tensorflow.python.keras.optimizer_v2.optimizer_v2.OptimizerV2]¶
Function for getting correct optimizer.
- Args:
optimizer (str): Optimizer to be used.
learning_rate (float): Learning rate.
- Returns:
Callable[[], tf.keras.optimizers.Optimizer]: Returns function for optimizer.
- federated.optimization.federated.iterative_process_fn(tff_model: tensorflow_federated.python.learning.model.Model, server_optimizer_fn: Callable[], tensorflow.python.keras.optimizer_v2.optimizer_v2.OptimizerV2], aggregation_method: str = 'fedavg', client_optimizer_fn: Optional[Callable[], tensorflow.python.keras.optimizer_v2.optimizer_v2.OptimizerV2]] = None, iterations: Optional[int] = None, client_weighting: Optional[tensorflow_federated.python.learning.federated_averaging.ClientWeighting] = None, v: Optional[float] = None, compression: bool = False, model_update_aggregation_factory: Optional[Callable[], tensorflow_federated.python.aggregators.factory.UnweightedAggregationFactory]] = None) → tensorflow_federated.python.core.templates.iterative_process.IterativeProcess¶
Function builds an iterative process that performs federated aggregation. The function offers federated averaging, federated stochastic gradient descent and robust federated aggregation.
- Args:
tff_model (tff.learning.Model): Federated model object.
server_optimizer_fn (Callable[[], tf.keras.optimizers.Optimizer]): Server optimizer function.
aggregation_method (str, optional): Aggregation method. Defaults to “fedavg”.
client_optimizer_fn (Callable[[], tf.keras.optimizers.Optimizer], optional): Client optimizer function. Defaults to None.
iterations (int, optional): [description]. Defaults to None.
client_weighting (tff.learning.ClientWeighting, optional): Client weighting. Defaults to None.
v (float, optional): L2 threshold. Defaults to None.
compression (bool, optional): If the model should be compressed. Defaults to False.
model_update_aggregation_factory (Callable[ [], tff.aggregators.UnweightedAggregationFactory ], optional): If the model should be trained with DP. Defaults to None.
- Returns:
tff.templates.IterativeProcess: An Iterative Process.