UNPKG

federer

Version:

Experiments in asynchronous federated learning and decentralized learning

55 lines 2.71 kB
/// <reference types="node" /> import * as http from "http"; import * as https from "https"; import * as io from "socket.io"; import { Logger } from "winston"; import { ClientToServerMessages, ServerToClientMessages, SyncServerStartOptions, UploadMessage, Weights } from "../../common"; import { FLRoundState, FLServer } from "../FLServer"; /** Base interface for round states in a synchronous FL algorithm. */ export interface SyncFLState extends FLRoundState { /** * The current round number. For synchronous implementations, it is readonly, * so that the number only can be incremented by re-assigning the whole state. */ readonly roundNumber: number; } /** * Abstract class implementing a server that aggregates weights in rounds. * Subclasses must implement the aggregation and operations on the round state. */ export declare abstract class SyncFLServer<RoundState extends SyncFLState, StartOptions extends SyncServerStartOptions> extends FLServer<RoundState, StartOptions> { /** * Number of clients that should be training per round. This corresponds to * the m parameter in the FedAvg paper. */ private numberClientsPerRound; constructor(server: http.Server | https.Server, initialWeights: Weights, options: StartOptions, logger: Logger); protected registerSocketListeners(socket: io.Socket<ClientToServerMessages, ServerToClientMessages>): void; /** Returns whether we can start learning, if we haven't started already. */ private shouldStartLearning; /** Returns whether we can end the current round. */ private shouldEndRound; /** Ends the current round, and moves on to the next one. */ private endRound; /** Name of the server; used to create a unique filename for saving weights. */ protected abstract serverName: string; /** * Incorporates an {@link UploadMessage} into the current round state * * @param message Message to incorporate into the current round state * @param socketId ID of the socket that sent the message */ protected abstract updateRoundState(message: UploadMessage, socketId: string): void; /** * Increments the round state from an old current round to a new current round * * Note that it if the implementation uses `roundAverage` in its state, it * should `.clone()` it first to avoid the parent class from disposing of it. * * @param roundAverage Averaged weights from the old current round */ protected abstract incrementRoundState(roundAverage: Weights): void; /** Returns the aggregated result of the round. */ protected abstract getRoundAverage(): Weights; } //# sourceMappingURL=SyncFLServer.d.ts.map