Crates.io | xaynet-core |
lib.rs | xaynet-core |
version | 0.2.0 |
source | src |
created_at | 2020-09-22 09:15:02.067042 |
updated_at | 2021-01-18 10:53:16.86698 |
description | The Xayn Network project is building a privacy layer for machine learning so that AI projects can meet compliance such as GDPR and CCPA. The approach relies on Federated Learning as enabling technology that allows production AI applications to be fully privacy compliant. |
homepage | https://xaynet.dev/ |
repository | https://github.com/xaynetwork/xaynet/ |
max_upload_size | |
id | 291465 |
size | 308,295 |
Want a framework that supports federated learning on the edge, in desktop browsers, integrates well with mobile apps, is performant, and preserves privacy? Welcome to XayNet, written entirely in Rust!
Frameworks for machine learning - including those expressly for federated learning - exist already. These frameworks typically facilitate federated learning of cross-silo use cases - for example in collaborative learning across a limited number of hospitals or for instance across multiple banks working on a common use case without the need to share valuable and sensitive data.
This repository focusses on masked cross-device federated learning to enable the orchestration of machine learning in millions of low-power edge devices, such as smartphones or even cars. By doing this, we hope to also increase the pace and scope of adoption of federated learning in practice and especially allow the protection of end user data. All data remains in private local premises, whereby only encrypted AI models get automatically and asynchronously aggregated. Thus, we provide a solution to the AI privacy dilemma and bridge the often-existing gap between privacy and convenience. Imagine, for example, a voice assistant to learn new words directly on device level and sharing this knowledge with all other instances, without recording and collecting your voice input centrally. Or, think about search engine that learns to personalise search results without collecting your often sensitive search queries centrally… There are thousands of such use cases that right today still trade privacy for convenience. We think this shouldn’t be the case and we want to provide an alternative to overcome this dilemma.
Concretely, we provide developers with:
Our framework for federated learning is not only a framework for machine learning as such. Rather, it supports the federation of machine learning that takes place on possibly heterogeneous devices and where use cases involve many such devices.
The programming language in which this framework is written should therefore give us strong support for the following:
Rust is one of the very few choices of modern programming languages that meets these requirements:
rustc 1.48.0
There are a few different ways to run the backend: via docker, or by deploying it to a Kubernetes cluster or by compiling the code and running the binary manually.
docker
and docker-compose
) and/or a working
setup (if you decide to compile the Rust code and run the binary manually).Note:
With Xaynet v0.11
the coordinator needs a connection to a redis instance in order to save its state.
Don't connect the coordinator to a Redis instance that is used in production!
We recommend connecting the coordinator to its own Redis instance. We have invested a lot of time to make sure that the coordinator only deletes its own data but in the current state of development, we cannot guarantee that this will always be the case.
The convenience of using the docker setup is that there's no need to setup a working Rust environment on your system, as everything is done inside the container.
Docker images of the latest releases are provided on Docker Hub.
You can try them out with the default configs/docker-dev.toml
by running:
Xaynet below v0.11
docker run -v ${PWD}/configs/docker-dev.toml:/app/config.toml -p 8081:8081 xaynetwork/xaynet:v0.10.0 /app/coordinator -c /app/config.toml
Xaynet v0.11+
# don't forget to adjust the Redis url in configs/docker-dev.toml
docker run -v ${PWD}/configs/docker-dev.toml:/app/config.toml -p 8081:8081 xaynetwork/xaynet:v0.11.0
The docker image contains a release build of the coordinator without optional features.
Start the coordinator by pointing to the docker/docker-compose.yml
file. It spins up all
infrastructure that is essential to run the coordinator with default or optional features.
Keep in mind that this file is used for development only.
docker-compose -f docker/docker-compose.yml up --build
If you would like, you can create an optimized release build of the coordinator, but keep in mind that the compilation will be slower.
docker build --build-arg RELEASE_BUILD=1 -f ./docker/Dockerfile .
Optional features can be specified via the build argument COORDINATOR_FEATURES
.
docker build --build-arg COORDINATOR_FEATURES=tls,metrics -f ./docker/Dockerfile .
To deploy an instance of the coordinator to your Kubernetes cluster, use the manifests that are
located inside the k8s/coordinator
folder. The manifests rely on kustomize
to be generated
(kustomize
is officially supported by kubectl
since v1.14). We recommend you thoroughly go
through the manifests and adjust them according to your own setup (namespace, ingress, etc.).
Remember to also check (and adjust if necessary) the default configuration for the coordinator, available
at k8s/coordinator/development/config.toml
.
Please adjust the domain used in the k8s/coordinator/development/ingress.yaml
file so it matches
your needs (you can also skip ingress
altogether, just make sure you remove its reference from
k8s/coordinator/development/kustomization.yaml
).
Keep in mind that the ingress
configuration that is shown on k8s/coordinator/development/ingress.yaml
relies on resources that aren't available in this repository, due to their sensitive nature
(TLS key and certificate, for instance).
To verify the generated manifests, run:
kubectl kustomize k8s/coordinator/development
To apply them:
kubectl apply -k k8s/coordinator/development
In case you are not exposing your coordinator via ingress
, you can still reach it using a port-forward.
The example below creates a port-forward at port 8081
assuming the coordinator pod is still using the
app=coordinator
label:
kubectl port-forward $(kubectl get pods -l "app=coordinator" -o jsonpath="{.items[0].metadata.name}") 8081
The coordinator without optional features can be built and started with:
cd rust
cargo run --bin coordinator -- -c ../configs/config.toml
The example can be found under rust/examples/. It uses a dummy model but is network-capable, so it's a good starting point for checking connectivity with the coordinator.
test-drive
Make sure you have a running instance of the coordinator and that the clients you will spawn with the command below are able to reach it through the network.
Here is an example on how to start 20
participants that will connect to a coordinator
running on 127.0.0.1:8081
:
cd rust
RUST_LOG=info cargo run --example test-drive -- -n 20 -u http://127.0.0.1:8081
For more in-depth details on how to run examples, see the accompanying Getting Started guide under rust/xaynet-server/src/examples.rs.
If you have any difficulties running the project, please reach out to us by opening an issue and describing your setup and the problems you're facing.