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
pippackage manager. - If you have a unique machine configuration, build the TFF package from source.
On Ubuntu:
sudo apt updatesudo apt install python3-dev python3-pip # Python 3sudo pip3 install --user --upgrade virtualenv
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 updatebrew install python # Python 3sudo pip3 install --user --upgrade virtualenv
virtualenv --python python3 "venv"source "venv/bin/activate"pip install --upgrade pip
Note: To exit the virtual environment, run deactivate.
pip install --upgrade tensorflow-federated
pip install --upgrade tensorflow-federated-nightly
python -c "import tensorflow_federated as tff; print(tff.federated_computation(lambda: 'Hello World')())"
Success: The latest TensorFlow Federated Python package is now installed.
Building a TensorFlow Federated Python package from source is helpful when you want to:
- Make changes to TensorFlow Federated and test those changes in a component that uses TensorFlow Federated before those changes are submitted or released.
- Use changes that have been submitted to TensorFlow Federated but have not been released.
Note: an easier approach to use the new feature not in the released package might be pip installing the nightly package
On Ubuntu:
sudo apt updatesudo apt install python3-dev python3-pip # Python 3sudo pip3 install --user --upgrade virtualenv
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 updatebrew install python # Python 3sudo pip3 install --user --upgrade virtualenv
Install Bazel, the build tool used to compile Tensorflow Federated.
git clone https://github.com/tensorflow/federated.gitcd "federated"
mkdir "/tmp/tensorflow_federated"bazel run //tensorflow_federated/tools/python_package:build_python_package -- \ --nightly \ --output_dir="/tmp/tensorflow_federated"
mkdir "/tmp/project"cd "/tmp/project"
virtualenv --python python3 "venv"source "venv/bin/activate"pip install --upgrade pip
Note: To exit the virtual environment run deactivate.
pip install --upgrade "/tmp/tensorflow_federated/"*".whl"
python -c "import tensorflow_federated as tff; print(tff.federated_computation(lambda: 'Hello World')())"
Success: A TensorFlow Federated Python package is now built from source and installed.