Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/google/fedjax
FedJAX is a JAX-based open source library for Federated Learning simulations that emphasizes ease-of-use in research.
https://github.com/google/fedjax
federated-learning jax
Last synced: about 1 month ago
JSON representation
FedJAX is a JAX-based open source library for Federated Learning simulations that emphasizes ease-of-use in research.
- Host: GitHub
- URL: https://github.com/google/fedjax
- Owner: google
- License: apache-2.0
- Created: 2020-12-22T14:44:03.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-21T17:51:34.000Z (4 months ago)
- Last Synced: 2024-09-21T21:39:40.114Z (3 months ago)
- Topics: federated-learning, jax
- Language: Python
- Homepage:
- Size: 837 KB
- Stars: 252
- Watchers: 11
- Forks: 42
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: docs/contributing.md
- License: LICENSE
Awesome Lists containing this project
- awesome-privacy-engineering - FedJAX - Google's JAX-based open source library for federated learning simulations that emphasizes ease-of-use in research. (Awesome Privacy Engineering [![Awesome](https://awesome.re/badge.svg)](https://awesome.re) / Differential Privacy and Federated Learning)
- awesome-jax - FedJAX - Federated learning in JAX, built on Optax and Haiku. <img src="https://img.shields.io/github/stars/google/fedjax?style=social" align="center"> (Libraries / New Libraries)
README
# FedJAX: Federated learning simulation with JAX
[![Build and minimal test](https://github.com/google/fedjax/actions/workflows/build_and_minimal_test.yml/badge.svg)](https://github.com/google/fedjax/actions/workflows/build_and_minimal_test.yml)
[![Documentation Status](https://readthedocs.org/projects/fedjax/badge/?version=latest)](https://fedjax.readthedocs.io/en/latest/?badge=latest)
![PyPI version](https://img.shields.io/pypi/v/fedjax)[**Documentation**](https://fedjax.readthedocs.io/) |
[**Paper**](https://arxiv.org/abs/2108.02117)NOTE: FedJAX is not an officially supported Google product. FedJAX is still in
the early stages and the API will likely continue to change.## What is FedJAX?
FedJAX is a [JAX]-based open source library for
[Federated Learning](https://ai.googleblog.com/2017/04/federated-learning-collaborative.html)
simulations that emphasizes ease-of-use in research. With its simple primitives
for implementing federated learning algorithms, prepackaged datasets, models and
algorithms, and fast simulation speed, FedJAX aims to make developing and
evaluating federated algorithms faster and easier for researchers. FedJAX works
on accelerators (GPU and TPU) without much additional effort. Additional details
and benchmarks can be found in our [paper](https://arxiv.org/abs/2108.02117).## Installation
You will need a moderately recent version of Python. Please check
[the PyPI page](https://pypi.org/project/fedjax/) for the up to date version
requirement.First, install JAX. For a CPU-only version:
```
pip install --upgrade pip
pip install --upgrade jax jaxlib # CPU-only version
```For other devices (e.g. GPU), follow
[these instructions](https://github.com/google/jax#installation).Then, install FedJAX from PyPI:
```
pip install fedjax
```Or, to upgrade to the latest version of FedJAX:
```
pip install --upgrade git+https://github.com/google/fedjax.git
```## Getting Started
Below is a simple example to verify FedJAX is installed correctly.
```python
import fedjax
import jax
import jax.numpy as jnp
import numpy as np# {'client_id': client_dataset}.
fd = fedjax.InMemoryFederatedData({
'a': {
'x': np.array([1.0, 2.0, 3.0]),
'y': np.array([2.0, 4.0, 6.0]),
},
'b': {
'x': np.array([4.0]),
'y': np.array([12.0])
}
})
# Initial model parameters.
params = jnp.array(0.5)
# Mean squared error.
mse_loss = lambda params, batch: jnp.mean(
(jnp.dot(batch['x'], params) - batch['y'])**2)
# Loss for clients 'a' and 'b'.
print(f"client a loss = {mse_loss(params, fd.get_client('a').all_examples())}")
print(f"client b loss = {mse_loss(params, fd.get_client('b').all_examples())}")
```The following tutorial notebooks provide an introduction to FedJAX:
* [Federated datasets](https://fedjax.readthedocs.io/en/latest/notebooks/dataset_tutorial.html)
* [Working with models in FedJAX](https://fedjax.readthedocs.io/en/latest/notebooks/model_tutorial.html)
* [Federated learning algorithms](https://fedjax.readthedocs.io/en/latest/notebooks/algorithms_tutorial.html)You can also take a look at some of our working examples:
* [Federated Averaging](examples/fed_avg.py)
* [Full EMNIST example](examples/emnist_fed_avg.py)## Citing FedJAX
To cite this repository:
```
@article{fedjax2021,
title={{F}ed{JAX}: Federated learning simulation with {JAX}},
author={Jae Hun Ro and Ananda Theertha Suresh and Ke Wu},
journal={arXiv preprint arXiv:2108.02117},
year={2021}
}
```## Useful pointers
* https://jax.readthedocs.io/en/latest/index.html
* https://jax.readthedocs.io/en/latest/notebooks/Common_Gotchas_in_JAX.html
* https://jax.readthedocs.io/en/latest/notebooks/How_JAX_primitives_work.html
* https://dm-haiku.readthedocs.io/en/latest/[JAX]: https://github.com/google/jax
[Haiku]: https://github.com/deepmind/dm-haiku
[Stax]: https://github.com/google/jax/blob/main/jax/example_libraries/stax.py
[Optax]: https://github.com/deepmind/optax