# TensorFlow Federated Tutorials

<br />

These [colab-based](https://colab.research.google.com/) tutorials walk you
through the main TFF concepts and APIs using practical examples. Reference
documentation can be found in the [TFF guides](https://www.tensorflow.org/federated/get_started).

> [!NOTE]
> **Note:** TFF currently requires Python 3.9 or later, but [Google Colaboratory](https://research.google.com/colaboratory/)'s hosted runtimes currently use Python 3.7, and so in order to run these notebooks you will need to use a [custom local runtime](https://research.google.com/colaboratory/local-runtimes.html).

**Getting started with federated learning**

- [Federated Learning for image classification](https://www.tensorflow.org/federated/tutorials/federated_learning_for_image_classification) introduces the key parts of the Federated Learning (FL) API, and demonstrates how to use TFF to simulate federated learning on federated MNIST-like data.
- [Federated Learning for text generation](https://www.tensorflow.org/federated/tutorials/federated_learning_for_text_generation) further demonstrates how to use TFF's FL API to refine a serialized pre-trained model for a language modeling task.
- [Tuning recommended aggregations for learning](https://www.tensorflow.org/federated/tutorials/tuning_recommended_aggregators) shows how the basic FL computations in [`tff.learning`](https://www.tensorflow.org/federated/api_docs/python/tff/learning) can be combined with specialized aggregation routines offering robustness, differential privacy, compression, and more.

**Getting started with federated analytics**

- [Private Heavy Hitters](https://www.tensorflow.org/federated/tutorials/private_heavy_hitters) shows how to use [`tff.analytics.heavy_hitters`](https://www.tensorflow.org/federated/api_docs/python/tff/analytics/heavy_hitters) to build a federated analytics computation to discover private heavy hitters.

**Writing custom federated computations**

- [Building Your Own Federated Learning Algorithm](https://www.tensorflow.org/federated/tutorials/building_your_own_federated_learning_algorithm) shows how to use the TFF Core APIs to implement federated learning algorithms, using Federated Averaging as an example.
- [Composing Learning Algorithms](https://www.tensorflow.org/federated/tutorials/composing_learning_algorithms) shows how to use the TFF Learning API to easily implement new federated learning algorithms, especially variants of Federated Averaging.
- [Custom Federated Algorithms, Part 1: Introduction to the Federated Core](https://www.tensorflow.org/federated/tutorials/custom_federated_algorithms_1) and [Part 2: Implementing Federated Averaging](https://www.tensorflow.org/federated/tutorials/custom_federated_algorithms_2) introduce the key concepts and interfaces offered by the Federated Core API (FC API).
- [Implementing Custom Aggregations](https://www.tensorflow.org/federated/tutorials/custom_aggregators) explains the design principles behind the [`tff.aggregators`](https://www.tensorflow.org/federated/api_docs/python/tff/aggregators) module and best practices for implementing custom aggregation of values from clients to server.

**Simulation best practices**

- [TFF simulation with accelerators (GPU)](https://www.tensorflow.org/federated/tutorials/simulations_with_accelerators)
  shows how TFF's high-performance runtime can be used with GPUs.

- [Working with ClientData](https://www.tensorflow.org/federated/tutorials/working_with_client_data) gives best
  practices for integrating TFF's
  [ClientData](https://www.tensorflow.org/federated/api_docs/python/tff/simulation/datasets/ClientData)-based
  simulation datasets into TFF computations.

**Intermediate and advanced tutorials**

- [Random noise generation](https://www.tensorflow.org/federated/tutorials/random_noise_generation) points out some
  subtleties with using randomness in decentralized computations, and proposes
  best practices and recommend patterns.

- [Sending Different Data To Particular Clients With
  federated_language.federated_select](https://www.tensorflow.org/federated/tutorials/federated_select) introduces the
  `federated_language.federated_select` operator and gives a simple example of
  a custom federated algorithm that sends different data to different clients.

- [Client-efficient large-model federated learning via federated_select and
  sparse aggregation](https://www.tensorflow.org/federated/tutorials/sparse_federated_learning) shows how TFF can be
  used to train a very large model where each client device only downloads and
  updates a small part of the model, using
  `federated_language.federated_select` and sparse aggregation.

- [Federated Learning with Differential Privacy in TFF](https://www.tensorflow.org/federated/tutorials/federated_learning_with_differential_privacy)
  demonstrates how to use TFF to train models with user-level differential
  privacy.