This crate provides building blocks for implementing participants for the Xaynet Federated Learning platform.
The PET protocol states that in any given round of federated learning, each participant of the protocol may be selected to carry out one of two tasks:
- update: participants selected for the update task (a.k.a. update participants) are responsible for sending a machine learning model they trained
- sum: participants selected for the sum task (a.k.a. sum participants) are responsible for computing a global mask from local mask seeds sent by the update participants
Participants may also not be selected for any of these tasks, in which case they simply wait for the next round.
Running a participant
The communication with the Xaynet coordinator is managed by a
background task that runs the PET protocol. We call it the PET
agent. In practice, the agent is a simple wrapper around the
[StateMachine
].
To run a participant, you need to start an agent, and interact with it. There are two types of interactions:
- reacting to notifications for the agents, which include:
- start of a new round of training
- selection for the sum task
- selection for the update task
- end of a task
- providing the agent with a Machine Learning model and a corresponding scalar for aggregation when the participant takes part the update task
Implementing an agent
A simple agent can be implemented as a function.
use Duration;
use delay_for;
use ;
async
This agent needs to be fed a [StateMachine
] in order to run. A
state machine requires found components:
- PET settings: a cryptographic key identifying the participant and a
masking configuration. This is provided by [
settings::PetSettings
] - a store from which it can load a model when the participant is
selected for the updat etask. This can be any type that
implements the [
ModelStore
] trait. In our case, we'll use a dummy in-memory store that always returns the same model. - a client to talk with the Xaynet coordinator. This can be any
type that implements the [
XaynetClient
] trait. For this we're going to use theClient
that is available when compiling with--features reqwest-client
. - a notifier that the state machine can use to send
notifications. This can be any type that implements the
[
Notify
] trait. We'll use channels for this.
Finally we can start our agent and log the events it emits. Here is the full code:
use ;
use async_trait;
use delay_for;
use ;
use ;
async
// Our notifier is a simple wrapper around a channel.
;
// Our store will always load the same model.
// In practice the model should be updated with
// the model the participant trains when it is selected
// for the update task.
;
async