Skip to content

Latest commit

 

History

History
110 lines (79 loc) · 3.07 KB

quickstart-mac.md

File metadata and controls

110 lines (79 loc) · 3.07 KB

Quickstart

Prerequisites

Local MQTT Broker

Since the flame system uses an MQTT broker to exchange messages during federated learning, to run the python library locally, you may install a local MQTT broker as shown below.

brew install mosquitto
brew services info mosquitto

The last command should display something similar to this:

mosquitto (homebrew.mxcl.mosquitto)
Running: ✔
Loaded: ✔
Schedulable: ✘
...

That confirms that the mosquitto service is active.

You can use the following commands to stop and start the mosquitto service:

# start mosquitto
brew services start mosquitto
# stop mosquitto
brew services stop mosquitto
# restart mosquitto
brew services restart mosquitto

Go ahead and change the two config files flame/lib/python/examples/mnist/trainer/config.json and flame/lib/python/examples/mnist/aggregator/config.json to set backend to mqtt.

    "backend": "mqtt",
    "brokers": [
        {
            "host": "localhost",
            "sort": "mqtt"
        },
	{
	    "host": "localhost:10104",
	    "sort": "p2p"
	}
    ]

Note that if you also want to use the local mqtt broker for other examples you should make sure that the mqtt broker has host set to localhost.

Environment Setup

We recommend setting up your environment with conda. Within the cloned flame directory, run the following to activate and setup the flame environment:

# Run within the cloned flame directory
cd lib/python/flame
conda create -n flame python=3.9
conda activate flame

pip install google
pip install tensorflow
pip install torch
pip install torchvision

cd ..
make install

To install flame in editable development mode, run the following instead of the make install command:

python -m pip install -e .

Running an Example

We will run the MNIST example with one aggregator and one trainer.

Open two terminal windows.

In the first terminal, once you are in flame/lib/python/examples/mnist/trainer, run:

conda activate flame

python keras/main.py config.json

Open another terminal in flame/lib/python/examples/mnist/aggregator and run:

conda activate flame

python keras/main.py config.json

In this example, we have one aggregator and one trainer that runs with the same job ID and different task IDs. After running, you will see the aggregator (second terminal) sending a global model to the trainer (first terminal), and the trainer sending the updated local model back to the aggregator.

This completes one round of communication between the aggregator and trainer.

The current example is set to 20 rounds (see the hyperparameters section of the flame/lib/python/examples/mnist/aggregator/config.json file), meaning the communication protocol described earlier will repeat 20 times.