federated/optimization/federated.py
def iterative_process_fn(
    tff_model: tff.learning.Model,
    server_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer],
    aggregation_method: str = "fedavg",
    client_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer] = None,
    iterations: int = None,
    client_weighting: tff.learning.ClientWeighting = None,
    v: float = None,
    compression: bool = False,
    model_update_aggregation_factory: Callable[
        [], tff.aggregators.UnweightedAggregationFactory
    ] = None,
) -> tff.templates.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.\n
        server_optimizer_fn (Callable[[], tf.keras.optimizers.Optimizer]): Server optimizer function.\n
        aggregation_method (str, optional): Aggregation method. Defaults to "fedavg".\n
        client_optimizer_fn (Callable[[], tf.keras.optimizers.Optimizer], optional): Client optimizer function. Defaults to None.\n
        iterations (int, optional): [description]. Defaults to None.\n
        client_weighting (tff.learning.ClientWeighting, optional): Client weighting. Defaults to None.\n
        v (float, optional): L2 threshold. Defaults to None.\n
        compression (bool, optional): If the model should be compressed. Defaults to False.\n
        model_update_aggregation_factory (Callable[ [], tff.aggregators.UnweightedAggregationFactory ], optional): If the model should be trained with DP. Defaults to None.\n

    Returns:
        tff.templates.IterativeProcess: An Iterative Process.
    """
    if aggregation_method == "rfa":
        return create_rfa_averaging(
            tff_model,
            iterations,
            v,
            server_optimizer_fn,
            client_optimizer_fn,
            compression=compression,
        )
    if aggregation_method == "fedavg":
        if compression:
            return tff.learning.build_federated_averaging_process(
                tff_model,
                server_optimizer_fn=server_optimizer_fn,
                client_optimizer_fn=client_optimizer_fn,
                client_weighting=client_weighting,
                broadcast_process=encoded_broadcast_process(tff_model),
                model_update_aggregation_factory=model_update_aggregation_factory,
            )
        else:
            return tff.learning.build_federated_averaging_process(
                tff_model,
                server_optimizer_fn=server_optimizer_fn,
                client_optimizer_fn=client_optimizer_fn,
                client_weighting=client_weighting,
                model_update_aggregation_factory=model_update_aggregation_factory,
            )
    if aggregation_method == "fedsgd":
        if compression:
            return tff.learning.build_federated_sgd_process(
                tff_model,
                server_optimizer_fn=server_optimizer_fn,
                broadcast_process=encoded_broadcast_process(tff_model),
                model_update_aggregation_factory=model_update_aggregation_factory,
            )
        else:
            return tff.learning.build_federated_sgd_process(
                tff_model,
                server_optimizer_fn=server_optimizer_fn,
                model_update_aggregation_factory=model_update_aggregation_factory,
            )
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.\n
        server_optimizer_fn (Callable[[], tf.keras.optimizers.Optimizer]): Server optimizer function.\n
        aggregation_method (str, optional): Aggregation method. Defaults to "fedavg".\n
        client_optimizer_fn (Callable[[], tf.keras.optimizers.Optimizer], optional): Client optimizer function. Defaults to None.\n
        iterations (int, optional): [description]. Defaults to None.\n
        client_weighting (tff.learning.ClientWeighting, optional): Client weighting. Defaults to None.\n
        v (float, optional): L2 threshold. Defaults to None.\n
        compression (bool, optional): If the model should be compressed. Defaults to False.\n
        model_update_aggregation_factory (Callable[ [], tff.aggregators.UnweightedAggregationFactory ], optional): If the model should be trained with DP. Defaults to None.\n

    Returns:
        tff.templates.IterativeProcess: An Iterative Process.
    
Function builds an iterative process that performs federated aggregation. The function offers federated averaging, federated stochastic gradient descent and robust federated aggregation.
Function builds an iterative process that performs federated aggregation . The function offers federated averaging federated stochastic gradient descent and robust federated aggregation .
def iterative_process_fn(
    tff_model: tff.learning.Model,
    server_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer],
    aggregation_method: str = "fedavg",
    client_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer] = None,
    iterations: int = None,
    client_weighting: tff.learning.ClientWeighting = None,
    v: float = None,
    compression: bool = False,
    model_update_aggregation_factory: Callable[
        [], tff.aggregators.UnweightedAggregationFactory
    ] = None,
) -> tff.templates.IterativeProcess:
    if aggregation_method == "rfa":
        return create_rfa_averaging(
            tff_model,
            iterations,
            v,
            server_optimizer_fn,
            client_optimizer_fn,
            compression=compression,
        )
    if aggregation_method == "fedavg":
        if compression:
            return tff.learning.build_federated_averaging_process(
                tff_model,
                server_optimizer_fn=server_optimizer_fn,
                client_optimizer_fn=client_optimizer_fn,
                client_weighting=client_weighting,
                broadcast_process=encoded_broadcast_process(tff_model),
                model_update_aggregation_factory=model_update_aggregation_factory,
            )
        else:
            return tff.learning.build_federated_averaging_process(
                tff_model,
                server_optimizer_fn=server_optimizer_fn,
                client_optimizer_fn=client_optimizer_fn,
                client_weighting=client_weighting,
                model_update_aggregation_factory=model_update_aggregation_factory,
            )
    if aggregation_method == "fedsgd":
        if compression:
            return tff.learning.build_federated_sgd_process(
                tff_model,
                server_optimizer_fn=server_optimizer_fn,
                broadcast_process=encoded_broadcast_process(tff_model),
                model_update_aggregation_factory=model_update_aggregation_factory,
            )
        else:
            return tff.learning.build_federated_sgd_process(
                tff_model,
                server_optimizer_fn=server_optimizer_fn,
                model_update_aggregation_factory=model_update_aggregation_factory,
            )
def iterative_process_fn ( tff_model : tff . learning . Model , server_optimizer_fn : Callable [ [ ] , tf . keras . optimizers . Optimizer ] , aggregation_method : str = "fedavg" , client_optimizer_fn : Callable [ [ ] , tf . keras . optimizers . Optimizer ] = None , iterations : int = None , client_weighting : tff . learning . ClientWeighting = None , v : float = None , compression : bool = False , model_update_aggregation_factory : Callable [ [ ] , tff . aggregators . UnweightedAggregationFactory ] = None , ) -> tff . templates . IterativeProcess : if aggregation_method == "rfa" : return create_rfa_averaging ( tff_model , iterations , v , server_optimizer_fn , client_optimizer_fn , compression = compression , ) if aggregation_method == "fedavg" : if compression : return tff . learning . build_federated_averaging_process ( tff_model , server_optimizer_fn = server_optimizer_fn , client_optimizer_fn = client_optimizer_fn , client_weighting = client_weighting , broadcast_process = encoded_broadcast_process ( tff_model ) , model_update_aggregation_factory = model_update_aggregation_factory , ) else : return tff . learning . build_federated_averaging_process ( tff_model , server_optimizer_fn = server_optimizer_fn , client_optimizer_fn = client_optimizer_fn , client_weighting = client_weighting , model_update_aggregation_factory = model_update_aggregation_factory , ) if aggregation_method == "fedsgd" : if compression : return tff . learning . build_federated_sgd_process ( tff_model , server_optimizer_fn = server_optimizer_fn , broadcast_process = encoded_broadcast_process ( tff_model ) , model_update_aggregation_factory = model_update_aggregation_factory , ) else : return tff . learning . build_federated_sgd_process ( tff_model , server_optimizer_fn = server_optimizer_fn , model_update_aggregation_factory = model_update_aggregation_factory , )
Function builds an iterative process that performs federated aggregation.
Function builds an iterative process that performs federated aggregation .
"""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.\n
        server_optimizer_fn (Callable[[], tf.keras.optimizers.Optimizer]): Server optimizer function.\n
        aggregation_method (str, optional): Aggregation method. Defaults to "fedavg".\n
        client_optimizer_fn (Callable[[], tf.keras.optimizers.Optimizer], optional): Client optimizer function. Defaults to None.\n
        iterations (int, optional): [description]. Defaults to None.\n
        client_weighting (tff.learning.ClientWeighting, optional): Client weighting. Defaults to None.\n
        v (float, optional): L2 threshold. Defaults to None.\n
        compression (bool, optional): If the model should be compressed. Defaults to False.\n
        model_update_aggregation_factory (Callable[ [], tff.aggregators.UnweightedAggregationFactory ], optional): If the model should be trained with DP. Defaults to None.\n

    Returns:
        tff.templates.IterativeProcess: An Iterative Process.
    """
An Iterative Process.
An Iterative Process .
tff.templates.IterativeProcess
tff_model
tff.learning.Model
Federated model object.\n
Federated model object . \ n
server_optimizer_fn
Callable[[], tf.keras.optimizers.Optimizer]
Server optimizer function.\n
Server optimizer function . \ n
aggregation_method
str
Aggregation method. Defaults to "fedavg".\n
Aggregation method . Defaults to " fedavg " . \ n
"fedavg"
client_optimizer_fn
Callable[[], tf.keras.optimizers.Optimizer]
Client optimizer function. Defaults to None.\n
Client optimizer function . Defaults to None . \ n
None
iterations
int
[description]. Defaults to None.\n
[ description ] . Defaults to None . \ n
None
client_weighting
tff.learning.ClientWeighting
Client weighting. Defaults to None.\n
Client weighting . Defaults to None . \ n
None
v
float
L2 threshold. Defaults to None.\n
L2 threshold . Defaults to None . \ n
None
compression
bool
If the model should be compressed. Defaults to False.\n
If the model should be compressed . Defaults to False . \ n
False
model_update_aggregation_factory
Callable[
        [], tff.aggregators.UnweightedAggregationFactory
    ]
If the model should be trained with DP. Defaults to None.\n
If the model should be trained with DP . Defaults to None . \ n
None