federated/utils/rfa.py
def create_rfa_averaging(
    create_model: Callable[[], tff.learning.Model],
    iterations: int,
    v: float,
    server_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer],
    client_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer],
    compression: bool = False,
) -> tff.templates.IterativeProcess:
    """Function for setting up Robust Federated Aggregation.

    Args:
        create_model (Callable[[], tff.learning.Model]): Function for creating a model.\n
        iterations (int): Calls to Secure Average Oracle.\n
        v (float): L2 Threshold.\n
        server_optimizer_fn (Callable[[], tf.keras.optimizers.Optimizer]): Server Optimizer Function.\n
        client_optimizer_fn (Callable[[], tf.keras.optimizers.Optimizer]): Client Optimizer Function.\n
        compression (bool, optional): Whether the model should be compressed. Defaults to False.\n

    Returns:
        tff.templates.IterativeProcess: Returns an Iterative Process with the RFA Averaging scheme
    """
    with tf.Graph().as_default():
        model = tff.framework.type_from_tensors(create_model().weights.trainable)
    robust_measured_process = create_robust_measured_process(
        model, iterations, v, compression=compression
    )

    if compression:
        return tff.learning.build_federated_averaging_process(
            create_model,
            server_optimizer_fn=server_optimizer_fn,
            client_optimizer_fn=client_optimizer_fn,
            aggregation_process=robust_measured_process,
            broadcast_process=encoded_broadcast_process(create_model),
        )

    else:
        return tff.learning.build_federated_averaging_process(
            create_model,
            server_optimizer_fn=server_optimizer_fn,
            client_optimizer_fn=client_optimizer_fn,
            aggregation_process=robust_measured_process,
        )
Function for setting up Robust Federated Aggregation.

    Args:
        create_model (Callable[[], tff.learning.Model]): Function for creating a model.\n
        iterations (int): Calls to Secure Average Oracle.\n
        v (float): L2 Threshold.\n
        server_optimizer_fn (Callable[[], tf.keras.optimizers.Optimizer]): Server Optimizer Function.\n
        client_optimizer_fn (Callable[[], tf.keras.optimizers.Optimizer]): Client Optimizer Function.\n
        compression (bool, optional): Whether the model should be compressed. Defaults to False.\n

    Returns:
        tff.templates.IterativeProcess: Returns an Iterative Process with the RFA Averaging scheme
    
Function for setting up Robust Federated Aggregation.
Function for setting up Robust Federated Aggregation .
def create_rfa_averaging(
    create_model: Callable[[], tff.learning.Model],
    iterations: int,
    v: float,
    server_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer],
    client_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer],
    compression: bool = False,
) -> tff.templates.IterativeProcess:
    with tf.Graph().as_default():
        model = tff.framework.type_from_tensors(create_model().weights.trainable)
    robust_measured_process = create_robust_measured_process(
        model, iterations, v, compression=compression
    )
    if compression:
        return tff.learning.build_federated_averaging_process(
            create_model,
            server_optimizer_fn=server_optimizer_fn,
            client_optimizer_fn=client_optimizer_fn,
            aggregation_process=robust_measured_process,
            broadcast_process=encoded_broadcast_process(create_model),
        )
    else:
        return tff.learning.build_federated_averaging_process(
            create_model,
            server_optimizer_fn=server_optimizer_fn,
            client_optimizer_fn=client_optimizer_fn,
            aggregation_process=robust_measured_process,
        )
def create_rfa_averaging ( create_model : Callable [ [ ] , tff . learning . Model ] , iterations : int , v : float , server_optimizer_fn : Callable [ [ ] , tf . keras . optimizers . Optimizer ] , client_optimizer_fn : Callable [ [ ] , tf . keras . optimizers . Optimizer ] , compression : bool = False , ) -> tff . templates . IterativeProcess : with tf . Graph ( ) . as_default ( ) : model = tff . framework . type_from_tensors ( create_model ( ) . weights . trainable ) robust_measured_process = create_robust_measured_process ( model , iterations , v , compression = compression ) if compression : return tff . learning . build_federated_averaging_process ( create_model , server_optimizer_fn = server_optimizer_fn , client_optimizer_fn = client_optimizer_fn , aggregation_process = robust_measured_process , broadcast_process = encoded_broadcast_process ( create_model ) , ) else : return tff . learning . build_federated_averaging_process ( create_model , server_optimizer_fn = server_optimizer_fn , client_optimizer_fn = client_optimizer_fn , aggregation_process = robust_measured_process , )
Function for setting up Robust Federated Aggregation.
Function for setting up Robust Federated Aggregation .
"""Function for setting up Robust Federated Aggregation.

    Args:
        create_model (Callable[[], tff.learning.Model]): Function for creating a model.\n
        iterations (int): Calls to Secure Average Oracle.\n
        v (float): L2 Threshold.\n
        server_optimizer_fn (Callable[[], tf.keras.optimizers.Optimizer]): Server Optimizer Function.\n
        client_optimizer_fn (Callable[[], tf.keras.optimizers.Optimizer]): Client Optimizer Function.\n
        compression (bool, optional): Whether the model should be compressed. Defaults to False.\n

    Returns:
        tff.templates.IterativeProcess: Returns an Iterative Process with the RFA Averaging scheme
    """
Returns an Iterative Process with the RFA Averaging scheme
Returns an Iterative Process with the RFA Averaging scheme
tff.templates.IterativeProcess
create_model
Callable[[], tff.learning.Model]
Function for creating a model.\n
Function for creating a model . \ n
iterations
int
Calls to Secure Average Oracle.\n
Calls to Secure Average Oracle . \ n
v
float
None
server_optimizer_fn
Callable[[], tf.keras.optimizers.Optimizer]
Server Optimizer Function.\n
Server Optimizer Function . \ n
client_optimizer_fn
Callable[[], tf.keras.optimizers.Optimizer]
Client Optimizer Function.\n
Client Optimizer Function . \ n
compression
bool
Whether the model should be compressed. Defaults to False.\n
Whether the model should be compressed . Defaults to False . \ n
False