Use Baselines¶
Warning
We are changing the way we structure the Flower baselines. While we complete the transition to the new format, you can still find the existing baselines and use them: baselines (old). Currently, you can make use of baselines for FedAvg, FedOpt, and LEAF-FEMNIST.
Structure¶
All baselines are available in the directory baselines with each baseline directory being fully self-contained in terms of source code. In addition, each baseline uses its very own Python environment as designed by the contributors of such baseline in order to replicate the experiments in the paper. Each baseline directory contains the following structure:
flower/baselines/<baseline_name>/
├── LICENSE
├── README.md
├── pyproject.toml # defines dependencies
├── _static # optionally a directory to save plots
└── <baseline_name>
└── *.py # several .py files
Setting up your machine¶
Tip
Flower baselines are designed to run on Ubuntu 22.04 and Python 3.10. While a GPU is not required to run the baselines, some of the more computationally demanding ones do benefit from GPU acceleration. All baselines are expected to make use of pyenv.
Note
We are in the process of migrating all baselines to use flwr run. Those that haven’t yet been migrated still make use of Poetry, a tool to manage Python dependencies. Identifying whether the baseline you want to run requires Poetry or not is easy: check if the Environment Setup section in the baseline readme mentions Poetry. Follow the instructions later in this section if you need to setup Poetry in your system.
Let’s begin by installing pyenv
. We’ll be following the standard procedure. Please refer to the pyenv docs for alternative ways of installing it, including for platforms other than Ubuntu.
# first install a few packages needed later for pyenv
sudo apt install build-essential zlib1g-dev libssl-dev libsqlite3-dev \
libreadline-dev libbz2-dev libffi-dev liblzma-dev
# now clone pyenv into your home directory (this is the default way of installing pyenv)
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
# Then add pyenv to your path by adding the below to your .bashrc/.zshrc
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
Verify your installation by opening a new terminal and
# check python versions available
pyenv versions
# * system (...) # <-- it should just show one
Then you can proceed and install any version of Python. Baselines use Python 3.10, so we’ll be installing a recent version of it.
pyenv install 3.10.14
# this will take a little while
# once done, you should see that that version is available
pyenv versions
# system
# * 3.10.14 # <-- you just installed this
Next, let’s install the virtualenv
plugin. Check the documentation for alternative installation methods.
# Clone `pyenv-virtualenv`
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
# Restart your shell
exec "$SHELL"
Using pyenv
¶
Creating a virtual environment can be done as follows:
# Create an environment for Python 3.10.14 named test-env
pyenv virtualenv 3.10.14 test-env
# Then activate it
pyenv activate test-env
# Deactivate it as follows
pyenv deactivate
(optional) Setup Poetry¶
Now that we have pyenv
installed, we are ready to install poetry
. It can be done from a single command:
curl -sSL https://install.python-poetry.org | python3 -
# add to path by putting this line at the end of your .zshrc/.bashrc
export PATH="$HOME/.local/bin:$PATH"
To install Poetry from source, to customise your installation, or to further integrate Poetry with your shell after installation, please check the Poetry documentation.
Using a Flower Baseline¶
To use Flower Baselines you need first to install pyenv
and, depending on the baselines, also Poetry
, then:
Clone the flower repository
git clone https://github.com/adap/flower.git && cd flower
Navigate inside the directory of the baseline you’d like to run
Follow the
[Environment Setup]
instructions in theREADME.md
.Run the baseline as indicated in the
[Running the Experiments]
section in theREADME.md
or in the[Expected Results]
section to reproduce the experiments in the paper.