Skip to content

Commit

Permalink
major refactor docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Wrede committed Aug 17, 2023
1 parent da71775 commit 134ba91
Show file tree
Hide file tree
Showing 27 changed files with 1,029 additions and 228 deletions.
8 changes: 7 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ build:
python: "3.9"

sphinx:
configuration: docs/conf.py
configuration: docs/conf.py

python:
version: 3.6
install:
- method: setuptools
path: ./fedn
4 changes: 4 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FEDn is using sphinx with reStructuredText.

sphinx-apidoc --ext-autodoc --module-first -o _source ../fedn/fedn ../*tests* ../*exceptions* ../*common* ../ ../fedn/fedn/network/api/server.py ../fedn/fedn/network/controller/controlbase.py
sphinx-build . _build
66 changes: 38 additions & 28 deletions docs/architecture.rst
Original file line number Diff line number Diff line change
@@ -1,53 +1,63 @@
Architecture overview
=====================

Constructing a federated model with FEDn amounts to a) specifying the details of the client-side training code and data integrations, and b) deploying the reducer-combiner network. A FEDn network, as illustrated in the picture below, is made up of three main components: the *Reducer*, one or more *Combiners*, and a number of *Clients*. The combiner network forms the backbone of the FedML orchestration mechanism, while the Reducer provides discovery services and provides controls to coordinate training over the combiner network. By horizontally scaling the combiner network, one can meet the needs of a growing number of clients.
Constructing a federated model with FEDn amounts to a) specifying the details of the client-side training code and data integrations, and b) deploying the federated network. A FEDn network, as illustrated in the picture below, is made up of components into three different tiers: the *Controller* tier (1), one or more *Combiners* in second tier (2), and a number of *Clients* in tier (3).
The combiners forms the backbone of the federated ML orchestration mechanism, while the Controller tier provides discovery services and controls to coordinate training over the federated network.
By horizontally scaling the number of combiners, one can meet the needs of a growing number of clients.

.. image:: img/overview.png
.. image:: img/FEDn_network.png
:alt: FEDn network
:width: 100%
:align: center

Main components
---------------

Client
......

A Client is a data node, holding private data and connecting to a Combiner to receive model update requests and model validation requests during training rounds. Importantly, clients do not require any open ingress ports. A client receives the code to be executed from the Reducer upon connecting to the network, and thus they only need to be configured prior to connection to read the local datasets during training and validation. Python3 client implementation is provided out of the box, and it is possible to write clients in a variety of languages to target different software and hardware requirements.

Combiner
........
The clients: tier 1
...................

A combiner is an actor whose main role is to orchestrate and aggregate model updates from a number of clients during a training round. When and how to trigger such orchestration rounds are specified in the overall *compute plan* laid out by the Reducer. Each combiner in the network runs an independent gRPC server, providing RPCs for interacting with the alliance subsystem it controls. Hence, the total number of clients that can be accommodated in a FEDn network is proportional to the number of active combiners in the FEDn network. Combiners can be deployed anywhere, e.g. in a cloud or on a fog node to provide aggregation services near the cloud edge.
A Client (gRPC client) is a data node, holding private data and connecting to a Combiner (gRPC server) to receive model update requests and model validation requests during training sessions.
Importantly, clients uses remote procedure calls (RPC) to ask for model updates tasks, thus the clients not require any open ingress ports! A client receives the code (called package or compute package) to be executed from the *Controller*
upon connecting to the network, and thus they only need to be configured prior to connection to read the local datasets during training and validation. The package is based on entry points in the client code, and can be customized to fit the needs of the user.
This allows for a high degree of flexibility in terms of what kind of training and validation tasks that can be performed on the client side. Such as different types of machine learning models and framework, and even programming languages.
A python3 client implementation is provided out of the box, and it is possible to write clients in a variety of languages to target different software and hardware requirements.

Reducer
.......
The combiners: tier 2
.....................

The reducer fills three main roles in the FEDn network: 1.) it lays out the overall, global training strategy and communicates that to the combiner network. It also dictates the strategy to aggregate model updates from individual combiners into a single global model, 2.) it handles global state and maintains the *model trail* - an immutable trail of global model updates uniquely defining the FedML training timeline, and 3.) it provides discovery services, mediating connections between clients and combiners. For this purpose, the Reducer exposes a standard REST API.
A combiner is an actor whose main role is to orchestrate and aggregate model updates from a number of clients during a training session.
When and how to trigger such orchestration are specified in the overall *compute plan* laid out by the *Controller*.
Each combiner in the network runs an independent gRPC server, providing RPCs for interacting with the federated network it controls.
Hence, the total number of clients that can be accommodated in a FEDn network is proportional to the number of active combiners in the FEDn network.
Combiners can be deployed anywhere, e.g. in a cloud or on a fog node to provide aggregation services near the cloud edge.

Services and communication
--------------------------
The controller: tier 3
......................

The figure below provides a logical architecture view of the services provided by each agent and how they interact.
Tier 3 does actually contain several components and services, but we tend to associate it with the *Controller* the most. The *Controller* fills three main roles in the FEDn network:

.. image:: img/FEDn-arch-overview.png
:alt: FEDn architecture overview
:width: 100%
:align: center
1. it lays out the overall, global training strategy and communicates that to the combiner network.
It also dictates the strategy to aggregate model updates from individual combiners into a single global model,
2. it handles global state and maintains the *model trail* - an immutable trail of global model updates uniquely defining the federated ML training timeline, and
3. it provides discovery services, mediating connections between clients and combiners. For this purpose, the *Controller* exposes a standard REST API both for RPC clients and servers, but also for user interfaces and other services.

Tier 3 also contain a *Reducer* component, which is responsible for aggregating combiner-level models into a single global model. Further, it contains a *StateStore* database,
which is responsible for storing various states of the network and training sessions. The final global model trail from a traning session is stored in the *ModelRegistry* database.


Control flows and algorithms
----------------------------
Notes on aggregating algorithms
...............................

FEDn is designed to allow customization of the FedML algorithm, following a specified pattern, or programming model. Model aggregation happens on two levels in the system. First, each Combiner can be configured with a custom orchestration and aggregation implementation, that reduces model updates from Clients into a single, *combiner level* model. Then, a configurable aggregation protocol on the Reducer level is responsible for combining the combiner-level models into a global model. By varying the aggregation schemes on the two levels in the system, many different possible outcomes can be achieved. Good staring configurations are provided out-of-the-box to help the user get started.
FEDn is designed to allow customization of the FedML algorithm, following a specified pattern, or programming model.
Model aggregation happens on two levels in the network. First, each Combiner can be configured with a custom orchestration and aggregation implementation, that reduces model updates from Clients into a single, *combiner level* model.
Then, a configurable aggregation protocol on the *Controller* level is responsible for combining the combiner-level models into a global model. By varying the aggregation schemes on the two levels in the system,
many different possible outcomes can be achieved. Good starting configurations are provided out-of-the-box to help the user get started. See API reference for more details.

Hierarchical Federated Averaging
................................

The currently implemented default scheme uses a local SGD strategy on the Combiner level aggregation and a simple average of models on the reducer level. This results in a highly horizontally scalable FedAvg scheme. The strategy works well with most artificial neural network (ANNs) models, and can in general be applied to models where it is possible and makes sense to form mean values of model parameters (for example SVMs). Additional FedML training protocols, including support for various types of federated ensemble models, are in active development.
The currently implemented default scheme uses a local SGD strategy on the Combiner level aggregation and a simple average of models on the reducer level.
This results in a highly horizontally scalable FedAvg scheme. The strategy works well with most artificial neural network (ANNs) models,
and can in general be applied to models where it is possible and makes sense to form mean values of model parameters (for example SVMs).


.. image:: img/HFedAvg.png
:alt: FEDn architecture overview
:width: 100%
:align: center
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,5 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}

pygments_style = 'sphinx'
4 changes: 2 additions & 2 deletions docs/deployment.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Deployment
Distributed Deployment
======================

This guide serves as reference deployment for setting up a FEDn network consisting of:
Expand Down Expand Up @@ -29,7 +29,7 @@ The reducer and clients need to be able to resolve the hostname for the combiner
we show how this can be achieved if no external DNS resolution is available, by setting "extra host" in the Docker containers for the Reducer and client. Note that there are many other possible ways to achieve this, depending on your setup.

1. Deploy storage and database services (MinIO, MongoDB and MongoExpress)
--------------------------------------------------------------------
-------------------------------------------------------------------------

First, deploy MinIO and Mongo services on one of the hosts. Edit the `docker-compose.yaml` file to change the default passwords and ports.

Expand Down
2 changes: 1 addition & 1 deletion docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Q: How can I configure the round validity policy:
In the main control implementation https://github.com/scaleoutsystems/fedn/blob/master/fedn/fedn/clients/reducer/control.py you can modify or replace the wiwmethod "check_round_validity_policy". As we expand with more implementations of this policy, we plan to make it runtime configurable.

Q: Can I start a client listening only to training requests or only on validation requests?:
-------------------------------------------------
--------------------------------------------------------------------------------------------

Yes! From FEDn 0.3.0 there is an option to toggle which message streams a client subscibes to. For example, to start a pure validation client:

Expand Down
34 changes: 34 additions & 0 deletions docs/fedn.network.api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
fedn.network.api package
========================

.. automodule:: fedn.network.api
:members:
:undoc-members:
:show-inheritance:

Submodules
----------

fedn.network.api.client module
------------------------------

.. automodule:: fedn.network.api.client
:members:
:undoc-members:
:show-inheritance:

fedn.network.api.interface module
---------------------------------

.. automodule:: fedn.network.api.interface
:members:
:undoc-members:
:show-inheritance:

fedn.network.api.network module
-------------------------------

.. automodule:: fedn.network.api.network
:members:
:undoc-members:
:show-inheritance:
42 changes: 42 additions & 0 deletions docs/fedn.network.clients.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
fedn.network.clients package
============================

.. automodule:: fedn.network.clients
:members:
:undoc-members:
:show-inheritance:

Submodules
----------

fedn.network.clients.client module
----------------------------------

.. automodule:: fedn.network.clients.client
:members:
:undoc-members:
:show-inheritance:

fedn.network.clients.connect module
-----------------------------------

.. automodule:: fedn.network.clients.connect
:members:
:undoc-members:
:show-inheritance:

fedn.network.clients.package module
-----------------------------------

.. automodule:: fedn.network.clients.package
:members:
:undoc-members:
:show-inheritance:

fedn.network.clients.state module
---------------------------------

.. automodule:: fedn.network.clients.state
:members:
:undoc-members:
:show-inheritance:
26 changes: 26 additions & 0 deletions docs/fedn.network.combiner.aggregators.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
fedn.network.combiner.aggregators package
=========================================

.. automodule:: fedn.network.combiner.aggregators
:members:
:undoc-members:
:show-inheritance:

Submodules
----------

fedn.network.combiner.aggregators.aggregatorbase module
-------------------------------------------------------

.. automodule:: fedn.network.combiner.aggregators.aggregatorbase
:members:
:undoc-members:
:show-inheritance:

fedn.network.combiner.aggregators.fedavg module
-----------------------------------------------

.. automodule:: fedn.network.combiner.aggregators.fedavg
:members:
:undoc-members:
:show-inheritance:
58 changes: 58 additions & 0 deletions docs/fedn.network.combiner.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
fedn.network.combiner package
=============================

.. automodule:: fedn.network.combiner
:members:
:undoc-members:
:show-inheritance:

Subpackages
-----------

.. toctree::
:maxdepth: 4

fedn.network.combiner.aggregators

Submodules
----------

fedn.network.combiner.connect module
------------------------------------

.. automodule:: fedn.network.combiner.connect
:members:
:undoc-members:
:show-inheritance:

fedn.network.combiner.interfaces module
---------------------------------------

.. automodule:: fedn.network.combiner.interfaces
:members:
:undoc-members:
:show-inheritance:

fedn.network.combiner.modelservice module
-----------------------------------------

.. automodule:: fedn.network.combiner.modelservice
:members:
:undoc-members:
:show-inheritance:

fedn.network.combiner.round module
----------------------------------

.. automodule:: fedn.network.combiner.round
:members:
:undoc-members:
:show-inheritance:

fedn.network.combiner.server module
-----------------------------------

.. automodule:: fedn.network.combiner.server
:members:
:undoc-members:
:show-inheritance:
18 changes: 18 additions & 0 deletions docs/fedn.network.controller.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
fedn.network.controller package
===============================

.. automodule:: fedn.network.controller
:members:
:undoc-members:
:show-inheritance:

Submodules
----------

fedn.network.controller.control module
--------------------------------------

.. automodule:: fedn.network.controller.control
:members:
:undoc-members:
:show-inheritance:
26 changes: 26 additions & 0 deletions docs/fedn.network.dashboard.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
fedn.network.dashboard package
==============================

.. automodule:: fedn.network.dashboard
:members:
:undoc-members:
:show-inheritance:

Submodules
----------

fedn.network.dashboard.plots module
-----------------------------------

.. automodule:: fedn.network.dashboard.plots
:members:
:undoc-members:
:show-inheritance:

fedn.network.dashboard.restservice module
-----------------------------------------

.. automodule:: fedn.network.dashboard.restservice
:members:
:undoc-members:
:show-inheritance:
34 changes: 34 additions & 0 deletions docs/fedn.network.loadbalancer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
fedn.network.loadbalancer package
=================================

.. automodule:: fedn.network.loadbalancer
:members:
:undoc-members:
:show-inheritance:

Submodules
----------

fedn.network.loadbalancer.firstavailable module
-----------------------------------------------

.. automodule:: fedn.network.loadbalancer.firstavailable
:members:
:undoc-members:
:show-inheritance:

fedn.network.loadbalancer.leastpacked module
--------------------------------------------

.. automodule:: fedn.network.loadbalancer.leastpacked
:members:
:undoc-members:
:show-inheritance:

fedn.network.loadbalancer.loadbalancerbase module
-------------------------------------------------

.. automodule:: fedn.network.loadbalancer.loadbalancerbase
:members:
:undoc-members:
:show-inheritance:
Loading

0 comments on commit 134ba91

Please sign in to comment.