UNPKG

federer

Version:

Experiments in asynchronous federated learning and decentralized learning

30 lines 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BatchedFedAsyncServer = void 0; const common_1 = require("../../common"); const SemiSyncFLServer_1 = require("./SemiSyncFLServer"); class BatchedFedAsyncServer extends SemiSyncFLServer_1.SemiSyncFLServer { constructor() { super(...arguments); this.serverName = "batched-fedasync"; this.expectDeltaUpdates = true; } getGlobalWeights() { return this.currentRound.weights.clone(); // weights updated in place } /** Incorporates an upload message into the state. */ updateRoundState(socket, message) { common_1.assertNoLeakingTensors("updateRoundState", () => { const staleness = this.currentRound.roundNumber - message.round; const alphaT = this.options.alpha * (1 - this.options.alpha) ** staleness; const oldWeights = this.currentRound.weights; this.currentRound.weights = common_1.tidy(() => this.currentRound.weights.add(common_1.Weights.deserialize(message.weights).mul(alphaT))); if (message.round === this.currentRound.roundNumber) { this.currentRound.replied.add(socket.id); } oldWeights.dispose(); }); } } exports.BatchedFedAsyncServer = BatchedFedAsyncServer; //# sourceMappingURL=BatchedFedAsyncServer.js.map