/simple-fl

This repository contains a simplified federated learning codebase designed mainly for personal or educational purposes. You can use the code from this repo for a commercial use too. However, we will not be responsible for any issues, or damages caused by using the code. For TieSet's official version of STADLE platform, please visit www.stadle.ai

Primary LanguagePython

Simple Federated Learning System: Educational Version

This repo is the free trial version of a simple federated learning system that is designed with only for educational and R&D purposes to understand the basics of federated learning with minimum architectures and functionalities. For a commercial version, please contact TieSet Inc. at info@tie-set.com.

Federated Learning (FL) solves many problems of privacy and communication load, which commonly appear in ML systems. FL does not require users to upload raw data to cloud servers.

  • Privacy: FL improves the privacy-preserving aspect of AI systems by not collecting data in the cloud while producing collective intelligence based on uploaded user ML models.
  • Communication load: The amount of traffic generated by FL dramatically decreases from classical AI systems due to the difference in data type exchanged.

There are a lot more merits that federated learning systems can provide.

Table of Contents

Simple FL Package

examples directory

Sample ML Engine codes that integrate FL client side libraries.

fl_main directory

Agent, aggregator, database codes together with supporting libraries.

setups directory

Configulation files with JSON format and installation yaml files.

Install

For all the environments of FL Server (Aggregator), FL Client (Agent), and Database Server, please create conda environment and activate it.

# macOS
conda env create -n federatedenv -f ./setups/federatedenv.yaml
# Linux
conda env create -n federatedenv -f ./setups/federatedenv_linux.yaml

Be sure to do conda activate federatedenv when you run the codes.

Note: The environment has Python 3.7.4. There is some known issues of ipfshttpclient with Python 3.7.2 and older.

Usage

Running Database and Aggregator

Here is how to configure the FL server side modules of database and aggregator.

  1. Edit the configuration files in the setups folder. The configuration details are explained here.
  2. Run the following 2 modules as separated processes in the order of pseudo_db -> server_th.
python -m fl_main.pseudodb.pseudo_db
python -m fl_main.aggregator.server_th

This sample does not have actual training. This could be used as a template for user implementation of ML Engine.

Sample Execution

  1. Edit the configuration files (config_agent.json) in the setups folder. The configuration details are explained here.
  2. Make sure the Database and Aggregator servers are running already. Then, run the minimal example as follows.
python -m examples.minimal.minimal_MLEngine

Simulation

FL systems can be run multiple agents for simulation within the same machine by specifying the port numbers for agents.

Agent side
python -m examples.minimal.minimal_MLEngine [simulation_flag] [gm_recv_port] [agent_name]
  • simulation_flag: 1 if it's simulation
  • gm_recv_port: Port number waiting for global models from the aggregator. This will be communicated to the aggregator via a participate message.
  • agent_name: Name of the local agent and directory name storing the state and model files. This needs to be unique for every agent.

For example:

# First agent
python -m examples.minimal.minimal_MLEngine 1 50001 a1
# Second agent
python -m examples.minimal.minimal_MLEngine 1 50002 a2
  1. Edit the configuration files in json format in the setups folder. In particular, the agg_threshold can be 1 in this case.
  2. After running the database and aggregator servers, run the minimal_MLEngine

This sample provides a simple example of integrating this FL framework into "actual" ML training. Please go to the prototype directory for more details.

Contributing

Please reach out to our technical support team via support@tie-set.com for any issues or bugs.