Join us at TensorFlow World, Oct 28-31. Use code TF20 for 20% off select passes. Register now

Install TensorFlow Federated

There are a few ways to set up your environment to use TensorFlow Federated (TFF):

  • The easiest way to learn and use TFF requires no installation—run the TensorFlow Federated tutorials directly in your browser using Google Colaboratory.
  • To use TensorFlow Federated on a local machine, install the TFF package with Python's pip package manager.
  • If you have a unique machine configuration, build TensorFlow Federated from source.

Install TensorFlow Federated using pip

1. Install the Python development environment.

On Ubuntu:

sudo apt update
sudo apt install python3-dev python3-pip  # Python 3
sudo pip3 install --upgrade virtualenv  # system-wide install

On macOS:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
brew update
brew install python  # Python 3
sudo pip3 install --upgrade virtualenv  # system-wide install

2. Create a virtual environment.

virtualenv --python python3 "venv"
source "venv/bin/activate"
pip install --upgrade pip

3. Install the TensorFlow Federated pip package.

pip install --upgrade tensorflow_federated

4. (Optional) Test Tensorflow Federated.

python -c "import tensorflow_federated as tff; print(tff.federated_computation(lambda: 'Hello World')())"

Build the TensorFlow Federated pip package

1. Install the Python development environment.

On Ubuntu:

sudo apt update
sudo apt install python3-dev python3-pip  # Python 3
sudo pip3 install --upgrade virtualenv  # system-wide install

On macOS:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
brew update
brew install python  # Python 3
sudo pip3 install --upgrade virtualenv  # system-wide install

2. Install Bazel.

Install Bazel, the build tool used to compile Tensorflow Federated.

3. Clone the Tensorflow Federated repository.

git clone https://github.com/tensorflow/federated.git
cd "federated"

4. Create a virtual environment.

virtualenv --python python3 "venv"
source "venv/bin/activate"
pip install --upgrade pip

5. Install Tensorflow Federated dependencies.

pip install --requirement "requirements.txt"

6. (Optional) Test Tensorflow Federated.

bazel test //tensorflow_federated/...

7. Build the pip package.

mkdir "/tmp/tensorflow_federated"
bazel build //tensorflow_federated/tools/development:build_pip_package
bazel-bin/tensorflow_federated/tools/development/build_pip_package "/tmp/tensorflow_federated"

8. Create a new project.

mkdir "/tmp/project"
cd "/tmp/project"

virtualenv --python python3 "venv"
source "venv/bin/activate"
pip install --upgrade pip

9. Install the pip package.

pip install --upgrade "/tmp/tensorflow_federated/tensorflow_federated-"*".whl"

10. Test Tensorflow Federated.

python -c "import tensorflow_federated as tff; print(tff.federated_computation(lambda: 'Hello World')())"

Using Docker

Create a Tensorflow Federated development environment using Docker on Ubuntu or macOS.

1. Install Docker.

Install Docker on your local machine.

2. Clone the latest Tensorflow Federated source.

git clone https://github.com/tensorflow/federated.git
cd "federated"

3. Build a Docker image.

docker build . \
    --tag tensorflow_federated:latest

4. Start a Docker container.

docker run -it \
    --workdir /federated \
    --volume $(pwd):/federated \
    tensorflow_federated:latest \
    bash

5. (Optional) Test Tensorflow Federated.

bazel test //tensorflow_federated/...