diff --git a/doc/source/_static/custom.css b/doc/source/_static/custom.css index b77704f497c..907f81a1e2a 100644 --- a/doc/source/_static/custom.css +++ b/doc/source/_static/custom.css @@ -1,5 +1,7 @@ -@import url(https://fonts.googleapis.com/css?family=Inter:400,600); - html, body{ - font-family: Inter,BlinkMacSystemFont,-apple-system,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,Helvetica,Arial,sans-serif; + font-family: Montserrat,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji; +} + +.mermaid { + background: #f8f8f8 } diff --git a/doc/source/_templates/base.html b/doc/source/_templates/base.html index 220397880c7..d32313db754 100644 --- a/doc/source/_templates/base.html +++ b/doc/source/_templates/base.html @@ -85,6 +85,8 @@ {%- block scripts -%} {# Custom JS #} + + {%- block regular_scripts -%} {% for path in script_files -%} {{ js_tag(path) }} diff --git a/doc/source/conf.py b/doc/source/conf.py index 354e25548cc..ffd358da48f 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -24,7 +24,7 @@ # Fixing path issue for autodoc -sys.path.insert(0, os.path.abspath('../../src/py')) +sys.path.insert(0, os.path.abspath("../../src/py")) # -- Project information ----------------------------------------------------- @@ -135,3 +135,11 @@ """ nbsphinx_prolog = _open_in_colab_button nbsphinx_epilog = _open_in_colab_button + +# -- Options for sphinxcontrib-mermaid ------------------------------------- +# Don't load it automatically through the extension as we are loading it through the +# theme (see base.html) as the inclusion of require.js by the extension `nbsphinx` +# breaks the way mermaid is loaded. The solution is to load mermaid before the +# require.js script added by `nbsphinx`. We can only enforce this in the theme +# itself. +mermaid_version = "" diff --git a/doc/source/contributor-setup.rst b/doc/source/contributor-setup.rst index 5c1f7ac84a8..034ca184fcc 100644 --- a/doc/source/contributor-setup.rst +++ b/doc/source/contributor-setup.rst @@ -32,7 +32,7 @@ Install a ``flwr`` pre-release from PyPI: - ``pip install -U --pre flwr`` (without extras) - ``pip install -U --pre flwr[simulation]`` (with extras) -Python packages can be installed from git repositories. Use the following command to install the latest version of Flower directly from GitHub:: +Python packages can be installed from git repositories. Use one of the following commands to install the Flower directly from GitHub. Install ``flwr`` from the default GitHub branch (``main``): diff --git a/doc/source/secagg.rst b/doc/source/secagg.rst index cf857413e53..cc24c5a0fc4 100644 --- a/doc/source/secagg.rst +++ b/doc/source/secagg.rst @@ -66,94 +66,95 @@ In this implementation, each client will be assigned with a unique index (int) f The Flower server will execute and process received results in the following order: .. mermaid:: - sequenceDiagram - participant S as Flower Server - participant P as SecAgg+ Protocol - participant C1 as Flower Client - participant C2 as Flower Client - participant C3 as Flower Client - - S->>P: generate_graph - activate P - P-->>S: client_graph - deactivate P - - Note left of P: Stage 0:
Setup Config - rect rgb(249, 219, 130) - S->>P: setup_config
clients, config_dict - activate P - P->>C1: SetupConfigIns - deactivate P - P->>C2: - P->>C3: - C1->>P: SetupConfigRes (empty) - C2->>P: - C3->>P: - activate P - P-->>S: None - deactivate P - end - - Note left of P: Stage 1:
Ask Keys - rect rgb(249, 219, 130) - S->>P: ask_keys
clients - activate P - P->>C1: AskKeysIns (empty) - deactivate P - P->>C2: - P->>C3: - C1->>P: AskKeysRes - C2->>P: - C3->>P: - activate P - P-->>S: public keys - deactivate P - end - - Note left of P: Stage 2:
Share Keys - rect rgb(249, 219, 130) - S->>P: share_keys
clients, public_keys_dict,
client_graph - activate P - P->>C1: ShareKeysIns - deactivate P - P->>C2: - P->>C3: - C1->>P: ShareKeysRes - C2->>P: - C3->>P: - activate P - P-->>S: encryted key shares - deactivate P - end - - Note left of P: Stage 3:
Ask Vectors - rect rgb(249, 219, 130) - S->>P: ask_vectors
clients,
forward_packet_list_dict - activate P - P->>C1: AskVectorsIns - deactivate P - P->>C2: - P->>C3: - C1->>P: AskVectorsRes - C2->>P: - activate P - P-->>S: masked vectors - deactivate P - end - - Note left of P: Stage 4:
Unmask Vectors - rect rgb(249, 219, 130) - S->>P: unmask_vectors
clients, dropped_clients,
client_graph - activate P - P->>C1: UnmaskVectorsIns - deactivate P - P->>C2: - C1->>P: UnmaskVectorsRes - C2->>P: - activate P - P-->>S: key shares - deactivate P - end + + sequenceDiagram + participant S as Flower Server + participant P as SecAgg+ Protocol + participant C1 as Flower Client + participant C2 as Flower Client + participant C3 as Flower Client + + S->>P: generate_graph + activate P + P-->>S: client_graph + deactivate P + + Note left of P: Stage 0:
Setup Config + rect rgb(249, 219, 130) + S->>P: setup_config
clients, config_dict + activate P + P->>C1: SetupConfigIns + deactivate P + P->>C2: + P->>C3: + C1->>P: SetupConfigRes (empty) + C2->>P: + C3->>P: + activate P + P-->>S: None + deactivate P + end + + Note left of P: Stage 1:
Ask Keys + rect rgb(249, 219, 130) + S->>P: ask_keys
clients + activate P + P->>C1: AskKeysIns (empty) + deactivate P + P->>C2: + P->>C3: + C1->>P: AskKeysRes + C2->>P: + C3->>P: + activate P + P-->>S: public keys + deactivate P + end + + Note left of P: Stage 2:
Share Keys + rect rgb(249, 219, 130) + S->>P: share_keys
clients, public_keys_dict,
client_graph + activate P + P->>C1: ShareKeysIns + deactivate P + P->>C2: + P->>C3: + C1->>P: ShareKeysRes + C2->>P: + C3->>P: + activate P + P-->>S: encryted key shares + deactivate P + end + + Note left of P: Stage 3:
Ask Vectors + rect rgb(249, 219, 130) + S->>P: ask_vectors
clients,
forward_packet_list_dict + activate P + P->>C1: AskVectorsIns + deactivate P + P->>C2: + P->>C3: + C1->>P: AskVectorsRes + C2->>P: + activate P + P-->>S: masked vectors + deactivate P + end + + Note left of P: Stage 4:
Unmask Vectors + rect rgb(249, 219, 130) + S->>P: unmask_vectors
clients, dropped_clients,
client_graph + activate P + P->>C1: UnmaskVectorsIns + deactivate P + P->>C2: + C1->>P: UnmaskVectorsRes + C2->>P: + activate P + P-->>S: key shares + deactivate P + end The :code:`LightSecAgg` abstraction @@ -199,73 +200,74 @@ In this implementation, each client will be assigned with a unique index (int) f The Flower server will execute and process received results in the following order: .. mermaid:: - sequenceDiagram - participant S as Flower Server - participant P as LightSecAgg Protocol - participant C1 as Flower Client - participant C2 as Flower Client - participant C3 as Flower Client - - Note left of P: Stage 0:
Setup Config - rect rgb(249, 219, 130) - S->>P: setup_config
clients, config_dict - activate P - P->>C1: LightSecAggSetupConfigIns - deactivate P - P->>C2: - P->>C3: - C1->>P: LightSecAggSetupConfigRes - C2->>P: - C3->>P: - activate P - P-->>S: public keys - deactivate P - end - - Note left of P: Stage 1:
Ask Encrypted Encoded Masks - rect rgb(249, 219, 130) - S->>P: ask_encrypted_encoded_masks
clients, public_keys_dict - activate P - P->>C1: AskEncryptedEncodedMasksIns - deactivate P - P->>C2: - P->>C3: - C1->>P: AskEncryptedEncodedMasksRes - C2->>P: - C3->>P: - activate P - P-->>S: forward packets - deactivate P - end - - Note left of P: Stage 2:
Ask Masked Models - rect rgb(249, 219, 130) - S->>P: share_keys
clients, forward_packet_list_dict - activate P - P->>C1: AskMaskedModelsIns - deactivate P - P->>C2: - P->>C3: - C1->>P: AskMaskedModelsRes - C2->>P: - activate P - P-->>S: masked local models - deactivate P - end - - Note left of P: Stage 3:
Ask Aggregated Encoded Masks - rect rgb(249, 219, 130) - S->>P: ask_aggregated_encoded_masks
clients - activate P - P->>C1: AskAggregatedEncodedMasksIns - deactivate P - P->>C2: - C1->>P: AskAggregatedEncodedMasksRes - C2->>P: - activate P - P-->>S: the aggregated model - deactivate P - end + + sequenceDiagram + participant S as Flower Server + participant P as LightSecAgg Protocol + participant C1 as Flower Client + participant C2 as Flower Client + participant C3 as Flower Client + + Note left of P: Stage 0:
Setup Config + rect rgb(249, 219, 130) + S->>P: setup_config
clients, config_dict + activate P + P->>C1: LightSecAggSetupConfigIns + deactivate P + P->>C2: + P->>C3: + C1->>P: LightSecAggSetupConfigRes + C2->>P: + C3->>P: + activate P + P-->>S: public keys + deactivate P + end + + Note left of P: Stage 1:
Ask Encrypted Encoded Masks + rect rgb(249, 219, 130) + S->>P: ask_encrypted_encoded_masks
clients, public_keys_dict + activate P + P->>C1: AskEncryptedEncodedMasksIns + deactivate P + P->>C2: + P->>C3: + C1->>P: AskEncryptedEncodedMasksRes + C2->>P: + C3->>P: + activate P + P-->>S: forward packets + deactivate P + end + + Note left of P: Stage 2:
Ask Masked Models + rect rgb(249, 219, 130) + S->>P: share_keys
clients, forward_packet_list_dict + activate P + P->>C1: AskMaskedModelsIns + deactivate P + P->>C2: + P->>C3: + C1->>P: AskMaskedModelsRes + C2->>P: + activate P + P-->>S: masked local models + deactivate P + end + + Note left of P: Stage 3:
Ask Aggregated Encoded Masks + rect rgb(249, 219, 130) + S->>P: ask_aggregated_encoded_masks
clients + activate P + P->>C1: AskAggregatedEncodedMasksIns + deactivate P + P->>C2: + C1->>P: AskAggregatedEncodedMasksRes + C2->>P: + activate P + P-->>S: the aggregated model + deactivate P + end Types diff --git a/src/py/flwr/server/app.py b/src/py/flwr/server/app.py index 419bad08d76..ffa830bb857 100644 --- a/src/py/flwr/server/app.py +++ b/src/py/flwr/server/app.py @@ -71,7 +71,7 @@ def start_server( # pylint: disable=too-many-arguments A server implementation, either `flwr.server.Server` or a subclass thereof. If no instance is provided, then `start_server` will create one. - config : ServerConfig (default: None) + config : Optional[ServerConfig] (default: None) Currently supported values are `num_rounds` (int, default: 1) and `round_timeout` in seconds (float, default: None). strategy : Optional[flwr.server.Strategy] (default: None). diff --git a/src/py/flwr/server/strategy/fedadagrad.py b/src/py/flwr/server/strategy/fedadagrad.py index a04d6d56875..a028a9302bd 100644 --- a/src/py/flwr/server/strategy/fedadagrad.py +++ b/src/py/flwr/server/strategy/fedadagrad.py @@ -37,7 +37,7 @@ from .fedopt import FedOpt -# pylint: disable=too-many-locals +# flake8: noqa: E501 class FedAdagrad(FedOpt): """Adaptive Federated Optimization using Adagrad (FedAdagrad) [Reddi et al., 2020] strategy. @@ -45,7 +45,7 @@ class FedAdagrad(FedOpt): Paper: https://arxiv.org/abs/2003.00295 """ - # pylint: disable=too-many-arguments,too-many-instance-attributes + # pylint: disable=too-many-arguments,too-many-locals,too-many-instance-attributes,line-too-long def __init__( self, *, @@ -74,38 +74,38 @@ def __init__( Implementation based on https://arxiv.org/abs/2003.00295v5 - Args: - fraction_fit (float, optional): Fraction of clients used during - training. Defaults to 0.1. - fraction_evaluate (float, optional): Fraction of clients used during - validation. Defaults to 0.1. - min_fit_clients (int, optional): Minimum number of clients used - during training. Defaults to 2. - min_evaluate_clients (int, optional): Minimum number of clients used - during validation. Defaults to 2. - min_available_clients (int, optional): Minimum number of total - clients in the system. Defaults to 2. - evaluate_fn : Optional[ - Callable[ - [int, NDArrays, Dict[str, Scalar]], - Optional[Tuple[float, Dict[str, Scalar]]] - ] - ]: Function used for validation. Defaults to None. - on_fit_config_fn (Callable[[int], Dict[str, str]], optional): - Function used to configure training. Defaults to None. - on_evaluate_config_fn (Callable[[int], Dict[str, str]], optional): - Function used to configure validation. Defaults to None. - accept_failures (bool, optional): Whether or not accept rounds - containing failures. Defaults to True. - initial_parameters (Parameters): Initial set of parameters from the server. - fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] - Metrics aggregation function, optional. - evaluate_metrics_aggregation_fn: Optional[MetricsAggregationFn] - Metrics aggregation function, optional. - eta (float, optional): Server-side learning rate. Defaults to 1e-1. - eta_l (float, optional): Client-side learning rate. Defaults to 1e-1. - tau (float, optional): Controls the algorithm's degree of adaptability. - Defaults to 1e-9. + Parameters + ---------- + fraction_fit : float, optional + Fraction of clients used during training. Defaults to 1.0. + fraction_evaluate : float, optional + Fraction of clients used during validation. Defaults to 1.0. + min_fit_clients : int, optional + Minimum number of clients used during training. Defaults to 2. + min_evaluate_clients : int, optional + Minimum number of clients used during validation. Defaults to 2. + min_available_clients : int, optional + Minimum number of total clients in the system. Defaults to 2. + evaluate_fn : Optional[Callable[[int, NDArrays, Dict[str, Scalar]], Optional[Tuple[float, Dict[str, Scalar]]]]] + Optional function used for validation. Defaults to None. + on_fit_config_fn : Callable[[int], Dict[str, Scalar]], optional + Function used to configure training. Defaults to None. + on_evaluate_config_fn : Callable[[int], Dict[str, Scalar]], optional + Function used to configure validation. Defaults to None. + fit_metrics_aggregation_fn : Optional[MetricsAggregationFn] + Metrics aggregation function, optional. + evaluate_metrics_aggregation_fn: Optional[MetricsAggregationFn] + Metrics aggregation function, optional. + accept_failures : bool, optional + Whether or not accept rounds containing failures. Defaults to True. + initial_parameters : Parameters, optional + Initial global model parameters. + eta : float, optional + Server-side learning rate. Defaults to 1e-1. + eta_l : float, optional + Client-side learning rate. Defaults to 1e-1. + tau : float, optional + Controls the algorithm's degree of adaptability. Defaults to 1e-9. """ super().__init__( fraction_fit=fraction_fit, diff --git a/src/py/flwr/server/strategy/fedadam.py b/src/py/flwr/server/strategy/fedadam.py index 3d0c6429735..d73f69e8980 100644 --- a/src/py/flwr/server/strategy/fedadam.py +++ b/src/py/flwr/server/strategy/fedadam.py @@ -37,6 +37,7 @@ from .fedopt import FedOpt +# flake8: noqa: E501 class FedAdam(FedOpt): """Adaptive Federated Optimization using Adam (FedAdam) [Reddi et al., 2020] strategy. @@ -44,7 +45,7 @@ class FedAdam(FedOpt): Paper: https://arxiv.org/abs/2003.00295 """ - # pylint: disable=too-many-arguments,too-many-instance-attributes,too-many-locals + # pylint: disable=too-many-arguments,too-many-instance-attributes,too-many-locals,line-too-long def __init__( self, *, @@ -75,40 +76,42 @@ def __init__( Implementation based on https://arxiv.org/abs/2003.00295v5 - Args: - fraction_fit (float, optional): Fraction of clients used during - training. Defaults to 0.1. - fraction_evaluate (float, optional): Fraction of clients used during - validation. Defaults to 0.1. - min_fit_clients (int, optional): Minimum number of clients used - during training. Defaults to 2. - min_evaluate_clients (int, optional): Minimum number of clients used - during validation. Defaults to 2. - min_available_clients (int, optional): Minimum number of total - clients in the system. Defaults to 2. - evaluate_fn : Optional[ - Callable[ - [int, NDArrays, Dict[str, Scalar]], - Optional[Tuple[float, Dict[str, Scalar]]] - ] - ]: Function used for validation. Defaults to None. - on_fit_config_fn (Callable[[int], Dict[str, str]], optional): - Function used to configure training. Defaults to None. - on_evaluate_config_fn (Callable[[int], Dict[str, str]], optional): - Function used to configure validation. Defaults to None. - accept_failures (bool, optional): Whether or not accept rounds - containing failures. Defaults to True. - initial_parameters (Parameters): Initial set of parameters from the server. - fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] - Metrics aggregation function, optional. - evaluate_metrics_aggregation_fn: Optional[MetricsAggregationFn] - Metrics aggregation function, optional. - eta (float, optional): Server-side learning rate. Defaults to 1e-1. - eta_l (float, optional): Client-side learning rate. Defaults to 1e-1. - beta_1 (float, optional): Momentum parameter. Defaults to 0.9. - beta_2 (float, optional): Second moment parameter. Defaults to 0.99. - tau (float, optional): Controls the algorithm's degree of adaptability. - Defaults to 1e-9. + Parameters + ---------- + fraction_fit : float, optional + Fraction of clients used during training. Defaults to 1.0. + fraction_evaluate : float, optional + Fraction of clients used during validation. Defaults to 1.0. + min_fit_clients : int, optional + Minimum number of clients used during training. Defaults to 2. + min_evaluate_clients : int, optional + Minimum number of clients used during validation. Defaults to 2. + min_available_clients : int, optional + Minimum number of total clients in the system. Defaults to 2. + evaluate_fn : Optional[Callable[[int, NDArrays, Dict[str, Scalar]], Optional[Tuple[float, Dict[str, Scalar]]]]] + Optional function used for validation. Defaults to None. + on_fit_config_fn : Callable[[int], Dict[str, Scalar]], optional + Function used to configure training. Defaults to None. + on_evaluate_config_fn : Callable[[int], Dict[str, Scalar]], optional + Function used to configure validation. Defaults to None. + accept_failures : bool, optional + Whether or not accept rounds containing failures. Defaults to True. + initial_parameters : Parameters, optional + Initial global model parameters. + fit_metrics_aggregation_fn : Optional[MetricsAggregationFn] + Metrics aggregation function, optional. + evaluate_metrics_aggregation_fn: Optional[MetricsAggregationFn] + Metrics aggregation function, optional. + eta : float, optional + Server-side learning rate. Defaults to 1e-1. + eta_l : float, optional + Client-side learning rate. Defaults to 1e-1. + beta_1 : float, optional + Momentum parameter. Defaults to 0.9. + beta_2 : float, optional + Second moment parameter. Defaults to 0.99. + tau : float, optional + Controls the algorithm's degree of adaptability. Defaults to 1e-9. """ super().__init__( fraction_fit=fraction_fit, diff --git a/src/py/flwr/server/strategy/fedavg.py b/src/py/flwr/server/strategy/fedavg.py index e6771b16760..10320a5a4b3 100644 --- a/src/py/flwr/server/strategy/fedavg.py +++ b/src/py/flwr/server/strategy/fedavg.py @@ -47,11 +47,11 @@ than or equal to the values of `min_fit_clients` and `min_evaluate_clients`. """ - +# flake8: noqa: E501 class FedAvg(Strategy): """Configurable FedAvg strategy implementation.""" - # pylint: disable=too-many-arguments,too-many-instance-attributes + # pylint: disable=too-many-arguments,too-many-instance-attributes,line-too-long def __init__( self, *, @@ -89,12 +89,7 @@ def __init__( Minimum number of clients used during validation. Defaults to 2. min_available_clients : int, optional Minimum number of total clients in the system. Defaults to 2. - evaluate_fn : Optional[ - Callable[ - [int, NDArrays, Dict[str, Scalar]], - Optional[Tuple[float, Dict[str, Scalar]]] - ] - ] + evaluate_fn : Optional[Callable[[int, NDArrays, Dict[str, Scalar]], Optional[Tuple[float, Dict[str, Scalar]]]]] Optional function used for validation. Defaults to None. on_fit_config_fn : Callable[[int], Dict[str, Scalar]], optional Function used to configure training. Defaults to None. @@ -104,9 +99,9 @@ def __init__( Whether or not accept rounds containing failures. Defaults to True. initial_parameters : Parameters, optional Initial global model parameters. - fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] + fit_metrics_aggregation_fn : Optional[MetricsAggregationFn] Metrics aggregation function, optional. - evaluate_metrics_aggregation_fn: Optional[MetricsAggregationFn] + evaluate_metrics_aggregation_fn : Optional[MetricsAggregationFn] Metrics aggregation function, optional. """ super().__init__() diff --git a/src/py/flwr/server/strategy/fedavg_android.py b/src/py/flwr/server/strategy/fedavg_android.py index 97d0bf6f790..6518836ce5c 100644 --- a/src/py/flwr/server/strategy/fedavg_android.py +++ b/src/py/flwr/server/strategy/fedavg_android.py @@ -40,10 +40,11 @@ from .strategy import Strategy +# flake8: noqa: E501 class FedAvgAndroid(Strategy): """Configurable FedAvg strategy implementation.""" - # pylint: disable=too-many-arguments,too-many-instance-attributes + # pylint: disable=too-many-arguments,too-many-instance-attributes,line-too-long def __init__( self, *, @@ -79,12 +80,7 @@ def __init__( Minimum number of clients used during validation. Defaults to 2. min_available_clients : Optional[int] Minimum number of total clients in the system. Defaults to 2. - evaluate_fn : Optional[ - Callable[ - [int, NDArrays, Dict[str, Scalar]], - Optional[Tuple[float, Dict[str, Scalar]]] - ] - ] + evaluate_fn : Optional[Callable[[int, NDArrays, Dict[str, Scalar]],Optional[Tuple[float, Dict[str, Scalar]]]]] Optional function used for validation. Defaults to None. on_fit_config_fn : Optional[Callable[[int], Dict[str, Scalar]]] Function used to configure training. Defaults to None. diff --git a/src/py/flwr/server/strategy/fedavgm.py b/src/py/flwr/server/strategy/fedavgm.py index 7c215cecd82..dcc03f40dce 100644 --- a/src/py/flwr/server/strategy/fedavgm.py +++ b/src/py/flwr/server/strategy/fedavgm.py @@ -44,11 +44,11 @@ than or equal to the values of `min_fit_clients` and `min_evaluate_clients`. """ - +# flake8: noqa: E501 class FedAvgM(FedAvg): """Configurable FedAvg with Momentum strategy implementation.""" - # pylint: disable=too-many-arguments,too-many-instance-attributes + # pylint: disable=too-many-arguments,too-many-instance-attributes,line-too-long def __init__( self, *, @@ -88,12 +88,7 @@ def __init__( Minimum number of clients used during validation. Defaults to 2. min_available_clients : int, optional Minimum number of total clients in the system. Defaults to 2. - evaluate_fn : Optional[ - Callable[ - [int, NDArrays, Dict[str, Scalar]], - Optional[Tuple[float, Dict[str, Scalar]]] - ] - ] + evaluate_fn : Optional[Callable[[int, NDArrays, Dict[str, Scalar]], Optional[Tuple[float, Dict[str, Scalar]]]]] Optional function used for validation. Defaults to None. on_fit_config_fn : Callable[[int], Dict[str, Scalar]], optional Function used to configure training. Defaults to None. diff --git a/src/py/flwr/server/strategy/fedopt.py b/src/py/flwr/server/strategy/fedopt.py index 91df07b6757..5464e0821f9 100644 --- a/src/py/flwr/server/strategy/fedopt.py +++ b/src/py/flwr/server/strategy/fedopt.py @@ -32,10 +32,11 @@ from .fedavg import FedAvg +# flake8: noqa: E501 class FedOpt(FedAvg): """Configurable FedAdagrad strategy implementation.""" - # pylint: disable=too-many-arguments,too-many-instance-attributes,too-many-locals + # pylint: disable=too-many-arguments,too-many-instance-attributes,too-many-locals,line-too-long def __init__( self, *, @@ -68,39 +69,40 @@ def __init__( Parameters ---------- - fraction_fit (float, optional): Fraction of clients used during - training. Defaults to 0.1. - fraction_evaluate (float, optional): Fraction of clients used during - validation. Defaults to 0.1. - min_fit_clients (int, optional): Minimum number of clients used - during training. Defaults to 2. - min_evaluate_clients (int, optional): Minimum number of clients used - during validation. Defaults to 2. - min_available_clients (int, optional): Minimum number of total - clients in the system. Defaults to 2. - evaluate_fn : Optional[ - Callable[ - [int, NDArrays, Dict[str, Scalar]], - Optional[Tuple[float, Dict[str, Scalar]]] - ] - ]: Function used for validation. Defaults to None. - on_fit_config_fn (Callable[[int], Dict[str, str]], optional): + fraction_fit : float, optional + Fraction of clients used during training. Defaults to 1.0. + fraction_evaluate : float, optional + Fraction of clients used during validation. Defaults to 1.0. + min_fit_clients : int, optional + Minimum number of clients used during training. Defaults to 2. + min_evaluate_clients : int, optional + Minimum number of clients used during validation. Defaults to 2. + min_available_clients : int, optional + Minimum number of total clients in the system. Defaults to 2. + evaluate_fn : Optional[Callable[[int, NDArrays, Dict[str, Scalar]], Optional[Tuple[float, Dict[str, Scalar]]]]] + Optional function used for validation. Defaults to None. + on_fit_config_fn : Callable[[int], Dict[str, Scalar]], optional Function used to configure training. Defaults to None. - on_evaluate_config_fn (Callable[[int], Dict[str, str]], optional): + on_evaluate_config_fn : Callable[[int], Dict[str, Scalar]], optional Function used to configure validation. Defaults to None. - accept_failures (bool, optional): Whether or not accept rounds - containing failures. Defaults to True. - initial_parameters (Parameters): Initial set of parameters from the server. - fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] + accept_failures : bool, optional + Whether or not accept rounds containing failures. Defaults to True. + initial_parameters : Parameters, optional + Initial global model parameters. + fit_metrics_aggregation_fn : Optional[MetricsAggregationFn] Metrics aggregation function, optional. evaluate_metrics_aggregation_fn: Optional[MetricsAggregationFn] Metrics aggregation function, optional. - eta (float, optional): Server-side learning rate. Defaults to 1e-1. - eta_l (float, optional): Client-side learning rate. Defaults to 1e-1. - beta_1 (float, optional): Momentum parameter. Defaults to 0.0. - beta_2 (float, optional): Second moment parameter. Defaults to 0.0. - tau (float, optional): Controls the algorithm's degree of adaptability. - Defaults to 1e-9. + eta : float, optional + Server-side learning rate. Defaults to 1e-1. + eta_l : float, optional + Client-side learning rate. Defaults to 1e-1. + beta_1 : float, optional + Momentum parameter. Defaults to 0.0. + beta_2 : float, optional + Second moment parameter. Defaults to 0.0. + tau : float, optional + Controls the algorithm's degree of adaptability. Defaults to 1e-9. """ super().__init__( fraction_fit=fraction_fit, diff --git a/src/py/flwr/server/strategy/fedyogi.py b/src/py/flwr/server/strategy/fedyogi.py index 53deca6afcb..081f7a9b4da 100644 --- a/src/py/flwr/server/strategy/fedyogi.py +++ b/src/py/flwr/server/strategy/fedyogi.py @@ -37,6 +37,7 @@ from .fedopt import FedOpt +# flake8: noqa: E501 class FedYogi(FedOpt): """Adaptive Federated Optimization using Yogi (FedYogi) [Reddi et al., 2020] strategy. @@ -44,7 +45,7 @@ class FedYogi(FedOpt): Paper: https://arxiv.org/abs/2003.00295 """ - # pylint: disable=too-many-arguments,too-many-instance-attributes,too-many-locals + # pylint: disable=too-many-arguments,too-many-instance-attributes,too-many-locals,line-too-long def __init__( self, *, @@ -75,40 +76,43 @@ def __init__( Implementation based on https://arxiv.org/abs/2003.00295v5 - Args: - fraction_fit (float, optional): Fraction of clients used during - training. Defaults to 0.1. - fraction_evaluate (float, optional): Fraction of clients used during - validation. Defaults to 0.1. - min_fit_clients (int, optional): Minimum number of clients used - during training. Defaults to 2. - min_evaluate_clients (int, optional): Minimum number of clients used - during validation. Defaults to 2. - min_available_clients (int, optional): Minimum number of total - clients in the system. Defaults to 2. - evaluate_fn : Optional[ - Callable[ - [int, NDArrays, Dict[str, Scalar]], - Optional[Tuple[float, Dict[str, Scalar]]] - ] - ]: Function used for validation. Defaults to None. - on_fit_config_fn (Callable[[int], Dict[str, str]], optional): - Function used to configure training. Defaults to None. - on_evaluate_config_fn (Callable[[int], Dict[str, str]], optional): - Function used to configure validation. Defaults to None. - accept_failures (bool, optional): Whether or not accept rounds - containing failures. Defaults to True. - initial_parameters (Parameters): Initial set of parameters from the server. - fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] - Metrics aggregation function, optional. - evaluate_metrics_aggregation_fn: Optional[MetricsAggregationFn] - Metrics aggregation function, optional. - eta (float, optional): Server-side learning rate. Defaults to 1e-1. - eta_l (float, optional): Client-side learning rate. Defaults to 1e-1. - beta_1 (float, optional): Momentum parameter. Defaults to 0.9. - beta_2 (float, optional): Second moment parameter. Defaults to 0.99. - tau (float, optional): Controls the algorithm's degree of adaptability. - Defaults to 1e-9. + Parameters + ---------- + fraction_fit : float, optional + Fraction of clients used during training. Defaults to 1.0. + fraction_evaluate : float, optional + Fraction of clients used during validation. Defaults to 1.0. + min_fit_clients : int, optional + Minimum number of clients used during training. Defaults to 2. + min_evaluate_clients : int, optional + Minimum number of clients used during validation. Defaults to 2. + min_available_clients : int, optional + Minimum number of total clients in the system. Defaults to 2. + evaluate_fn : Optional[Callable[[int, NDArrays, Dict[str, Scalar]], Optional[Tuple[float, Dict[str, Scalar]]]]] + Optional function used for validation. Defaults to None. + on_fit_config_fn : Callable[[int], Dict[str, Scalar]], optional + Function used to configure training. Defaults to None. + on_evaluate_config_fn : Callable[[int], Dict[str, Scalar]], optional + Function used to configure validation. Defaults to None. + accept_failures : bool, optional + Whether or not accept rounds containing failures. Defaults to True. + initial_parameters : Parameters, optional + Initial global model parameters. + fit_metrics_aggregation_fn : Optional[MetricsAggregationFn] + Metrics aggregation function, optional. + evaluate_metrics_aggregation_fn: Optional[MetricsAggregationFn] + Metrics aggregation function, optional. + eta : float, optional + Server-side learning rate. Defaults to 1e-1. + eta_l : float, optional + Client-side learning rate. Defaults to 1e-1. + beta_1 : float, optional + Momentum parameter. Defaults to 0.9. + beta_2 : float, optional + Second moment parameter. Defaults to 0.99. + tau : float, optional + Controls the algorithm's degree of adaptability. + Defaults to 1e-9. """ super().__init__( fraction_fit=fraction_fit,