@epfml/discojs 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -11
- package/dist/aggregation.d.ts +4 -2
- package/dist/aggregation.js +20 -6
- package/dist/client/base.d.ts +1 -1
- package/dist/client/decentralized/base.d.ts +43 -0
- package/dist/client/decentralized/base.js +243 -0
- package/dist/client/decentralized/clear_text.d.ts +13 -0
- package/dist/client/decentralized/clear_text.js +78 -0
- package/dist/client/decentralized/index.d.ts +4 -0
- package/dist/client/decentralized/index.js +9 -0
- package/dist/client/decentralized/messages.d.ts +37 -0
- package/dist/client/decentralized/messages.js +15 -0
- package/dist/client/decentralized/sec_agg.d.ts +18 -0
- package/dist/client/decentralized/sec_agg.js +169 -0
- package/dist/client/decentralized/secret_shares.d.ts +5 -0
- package/dist/client/decentralized/secret_shares.js +58 -0
- package/dist/client/decentralized/types.d.ts +1 -0
- package/dist/client/decentralized/types.js +2 -0
- package/dist/client/federated.d.ts +4 -4
- package/dist/client/federated.js +5 -8
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +3 -3
- package/dist/client/local.js +5 -3
- package/dist/dataset/data_loader/data_loader.d.ts +7 -1
- package/dist/dataset/data_loader/image_loader.d.ts +5 -3
- package/dist/dataset/data_loader/image_loader.js +64 -18
- package/dist/dataset/data_loader/index.d.ts +1 -1
- package/dist/dataset/data_loader/tabular_loader.d.ts +3 -3
- package/dist/dataset/data_loader/tabular_loader.js +27 -18
- package/dist/dataset/dataset_builder.d.ts +3 -2
- package/dist/dataset/dataset_builder.js +29 -17
- package/dist/index.d.ts +6 -4
- package/dist/index.js +13 -5
- package/dist/informant/graph_informant.d.ts +10 -0
- package/dist/informant/graph_informant.js +23 -0
- package/dist/informant/index.d.ts +3 -0
- package/dist/informant/index.js +9 -0
- package/dist/informant/training_informant/base.d.ts +31 -0
- package/dist/informant/training_informant/base.js +82 -0
- package/dist/informant/training_informant/decentralized.d.ts +5 -0
- package/dist/informant/training_informant/decentralized.js +22 -0
- package/dist/informant/training_informant/federated.d.ts +14 -0
- package/dist/informant/training_informant/federated.js +32 -0
- package/dist/informant/training_informant/index.d.ts +4 -0
- package/dist/informant/training_informant/index.js +11 -0
- package/dist/informant/training_informant/local.d.ts +6 -0
- package/dist/informant/training_informant/local.js +20 -0
- package/dist/logging/index.d.ts +1 -0
- package/dist/logging/index.js +3 -1
- package/dist/logging/trainer_logger.d.ts +1 -1
- package/dist/logging/trainer_logger.js +5 -5
- package/dist/memory/base.d.ts +17 -48
- package/dist/memory/empty.d.ts +6 -4
- package/dist/memory/empty.js +8 -2
- package/dist/memory/index.d.ts +1 -1
- package/dist/privacy.js +3 -3
- package/dist/serialization/model.d.ts +1 -1
- package/dist/serialization/model.js +2 -2
- package/dist/serialization/weights.js +2 -2
- package/dist/task/display_information.d.ts +2 -2
- package/dist/task/display_information.js +6 -5
- package/dist/task/summary.d.ts +5 -0
- package/dist/task/summary.js +23 -0
- package/dist/task/training_information.d.ts +3 -0
- package/dist/tasks/cifar10.js +5 -3
- package/dist/tasks/lus_covid.d.ts +1 -1
- package/dist/tasks/lus_covid.js +50 -13
- package/dist/tasks/mnist.js +4 -2
- package/dist/tasks/simple_face.d.ts +1 -1
- package/dist/tasks/simple_face.js +13 -17
- package/dist/tasks/titanic.js +9 -7
- package/dist/tfjs.d.ts +2 -0
- package/dist/tfjs.js +6 -0
- package/dist/training/disco.d.ts +3 -1
- package/dist/training/disco.js +14 -6
- package/dist/training/trainer/distributed_trainer.d.ts +1 -1
- package/dist/training/trainer/distributed_trainer.js +5 -1
- package/dist/training/trainer/local_trainer.d.ts +4 -3
- package/dist/training/trainer/local_trainer.js +6 -9
- package/dist/training/trainer/round_tracker.js +3 -0
- package/dist/training/trainer/trainer.d.ts +15 -15
- package/dist/training/trainer/trainer.js +57 -43
- package/dist/training/trainer/trainer_builder.js +8 -15
- package/dist/types.d.ts +1 -1
- package/dist/validation/index.d.ts +1 -0
- package/dist/validation/index.js +5 -0
- package/dist/validation/validator.d.ts +20 -0
- package/dist/validation/validator.js +106 -0
- package/package.json +2 -3
- package/dist/client/decentralized.d.ts +0 -23
- package/dist/client/decentralized.js +0 -275
- package/dist/testing/tester.d.ts +0 -5
- package/dist/testing/tester.js +0 -21
- package/dist/training_informant.d.ts +0 -88
- package/dist/training_informant.js +0 -135
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Decentralized = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var immutable_1 = require("immutable");
|
|
6
|
-
var isomorphic_ws_1 = (0, tslib_1.__importDefault)(require("isomorphic-ws"));
|
|
7
|
-
var msgpack_lite_1 = (0, tslib_1.__importDefault)(require("msgpack-lite"));
|
|
8
|
-
var simple_peer_1 = (0, tslib_1.__importDefault)(require("simple-peer"));
|
|
9
|
-
var url_1 = require("url");
|
|
10
|
-
var __1 = require("..");
|
|
11
|
-
var base_1 = require("./base");
|
|
12
|
-
function isPeerMessage(data) {
|
|
13
|
-
if (typeof data !== 'object') {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
if (data === null) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
if (!(0, immutable_1.Set)(Object.keys(data)).equals(immutable_1.Set.of('epoch', 'weights'))) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
var _a = data, epoch = _a.epoch, weights = _a.weights;
|
|
23
|
-
if (typeof epoch !== 'number' ||
|
|
24
|
-
!__1.serialization.weights.isEncoded(weights)) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
28
|
-
var _ = { epoch: epoch, weights: weights };
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
function isServerOpeningMessage(msg) {
|
|
32
|
-
if (!(msg instanceof Array)) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
if (!msg.every(function (elem) { return typeof elem === 'number'; })) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
|
-
var _ = msg;
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
function isServerPeerMessage(msg) {
|
|
43
|
-
if (!(msg instanceof Array)) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
if (msg.length !== 2) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
var _a = (0, tslib_1.__read)(msg, 2), id = _a[0], signal = _a[1];
|
|
50
|
-
if (typeof id !== 'number') {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
if (!(signal instanceof Uint8Array)) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
57
|
-
var _ = [id, signal];
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
// Time to wait between network checks in milliseconds.
|
|
61
|
-
var TICK = 100;
|
|
62
|
-
// Time to wait for the others in milliseconds.
|
|
63
|
-
var MAX_WAIT_PER_ROUND = 10000;
|
|
64
|
-
/**
|
|
65
|
-
* Class that deals with communication with the PeerJS server.
|
|
66
|
-
* Collects the list of receivers currently connected to the PeerJS server.
|
|
67
|
-
*/
|
|
68
|
-
var Decentralized = /** @class */ (function (_super) {
|
|
69
|
-
(0, tslib_1.__extends)(Decentralized, _super);
|
|
70
|
-
function Decentralized() {
|
|
71
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
72
|
-
_this.peers = (0, immutable_1.Map)();
|
|
73
|
-
_this.weights = (0, immutable_1.Map)();
|
|
74
|
-
return _this;
|
|
75
|
-
}
|
|
76
|
-
Decentralized.prototype.connectServer = function (url) {
|
|
77
|
-
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
78
|
-
var ws;
|
|
79
|
-
var _this = this;
|
|
80
|
-
return (0, tslib_1.__generator)(this, function (_a) {
|
|
81
|
-
switch (_a.label) {
|
|
82
|
-
case 0:
|
|
83
|
-
ws = new isomorphic_ws_1.default.WebSocket(url);
|
|
84
|
-
ws.binaryType = 'arraybuffer';
|
|
85
|
-
ws.onmessage = function (event) {
|
|
86
|
-
if (!(event.data instanceof ArrayBuffer)) {
|
|
87
|
-
throw new Error('server did not send an ArrayBuffer');
|
|
88
|
-
}
|
|
89
|
-
var msg = msgpack_lite_1.default.decode(new Uint8Array(event.data));
|
|
90
|
-
if (isServerOpeningMessage(msg)) {
|
|
91
|
-
console.debug('server sent us the list of peer to connect to:', msg);
|
|
92
|
-
if (_this.peers.size !== 0) {
|
|
93
|
-
throw new Error('server already gave us a list of peers');
|
|
94
|
-
}
|
|
95
|
-
_this.peers = (0, immutable_1.Map)((0, immutable_1.List)(msg)
|
|
96
|
-
.map(function (id) { return [id, _this.connectNewPeer(id, true)]; }));
|
|
97
|
-
}
|
|
98
|
-
else if (isServerPeerMessage(msg)) {
|
|
99
|
-
var _a = (0, tslib_1.__read)(msg, 2), peerID = _a[0], encodedSignal = _a[1];
|
|
100
|
-
var signal = msgpack_lite_1.default.decode(encodedSignal);
|
|
101
|
-
console.debug('server on behalf of', peerID, 'sent', signal);
|
|
102
|
-
var peer = _this.peers.get(peerID);
|
|
103
|
-
if (peer === undefined) {
|
|
104
|
-
peer = _this.connectNewPeer(peerID, false);
|
|
105
|
-
_this.peers = _this.peers.set(peerID, peer);
|
|
106
|
-
}
|
|
107
|
-
peer.signal(signal);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
throw new Error('send sent an invalid msg');
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
114
|
-
ws.onerror = function (err) { return reject(new Error("connecting server: " + err)); };
|
|
115
|
-
ws.onopen = function () { return resolve(ws); };
|
|
116
|
-
})];
|
|
117
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
// connect a new peer
|
|
123
|
-
//
|
|
124
|
-
// if initiator is true, we start the connection on our side
|
|
125
|
-
// see SimplePeer.Options.initiator for more info
|
|
126
|
-
Decentralized.prototype.connectNewPeer = function (peerID, initiator) {
|
|
127
|
-
var _this = this;
|
|
128
|
-
console.debug('connect new peer with initiator: ', initiator);
|
|
129
|
-
var peer = new simple_peer_1.default({
|
|
130
|
-
initiator: initiator,
|
|
131
|
-
config: {
|
|
132
|
-
iceServers: (0, immutable_1.List)(simple_peer_1.default.config.iceServers)
|
|
133
|
-
/* .push({
|
|
134
|
-
urls: 'turn:34.77.172.69:3478',
|
|
135
|
-
credential: 'deai',
|
|
136
|
-
username: 'deai'
|
|
137
|
-
}) */
|
|
138
|
-
.toArray()
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
peer.on('signal', function (signal) {
|
|
142
|
-
console.debug('local', peerID, 'is signaling', signal);
|
|
143
|
-
if (_this.server === undefined) {
|
|
144
|
-
throw new Error('server closed but received a signal');
|
|
145
|
-
}
|
|
146
|
-
var msg = [peerID, msgpack_lite_1.default.encode(signal)];
|
|
147
|
-
_this.server.send(msgpack_lite_1.default.encode(msg));
|
|
148
|
-
});
|
|
149
|
-
peer.on('data', function (data) {
|
|
150
|
-
var _a;
|
|
151
|
-
var message = msgpack_lite_1.default.decode(data);
|
|
152
|
-
if (!isPeerMessage(message)) {
|
|
153
|
-
throw new Error("invalid message received from " + peerID);
|
|
154
|
-
}
|
|
155
|
-
var weights = __1.serialization.weights.decode(message.weights);
|
|
156
|
-
console.debug('peer', peerID, 'sent weights', weights);
|
|
157
|
-
if (((_a = _this.weights.get(peer)) === null || _a === void 0 ? void 0 : _a.get(message.epoch)) !== undefined) {
|
|
158
|
-
throw new Error("weights from " + peerID + " already received");
|
|
159
|
-
}
|
|
160
|
-
_this.weights.set(peer, _this.weights.get(peer, (0, immutable_1.List)())
|
|
161
|
-
.set(message.epoch, weights));
|
|
162
|
-
});
|
|
163
|
-
peer.on('connect', function () { return console.info('connected to peer', peerID); });
|
|
164
|
-
// TODO better error handling
|
|
165
|
-
peer.on('error', function (err) { throw err; });
|
|
166
|
-
return peer;
|
|
167
|
-
};
|
|
168
|
-
/**
|
|
169
|
-
* Initialize the connection to the peers and to the other nodes.
|
|
170
|
-
*/
|
|
171
|
-
Decentralized.prototype.connect = function () {
|
|
172
|
-
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
173
|
-
var serverURL, _a;
|
|
174
|
-
return (0, tslib_1.__generator)(this, function (_b) {
|
|
175
|
-
switch (_b.label) {
|
|
176
|
-
case 0:
|
|
177
|
-
serverURL = new url_1.URL('', this.url.href);
|
|
178
|
-
serverURL.pathname += "/deai/tasks/" + this.task.taskID;
|
|
179
|
-
_a = this;
|
|
180
|
-
return [4 /*yield*/, this.connectServer(serverURL)];
|
|
181
|
-
case 1:
|
|
182
|
-
_a.server = _b.sent();
|
|
183
|
-
return [2 /*return*/];
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
/**
|
|
189
|
-
* Disconnection process when user quits the task.
|
|
190
|
-
*/
|
|
191
|
-
Decentralized.prototype.disconnect = function () {
|
|
192
|
-
var _a;
|
|
193
|
-
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
194
|
-
return (0, tslib_1.__generator)(this, function (_b) {
|
|
195
|
-
this.peers.forEach(function (peer) { return peer.destroy(); });
|
|
196
|
-
this.peers = (0, immutable_1.Map)();
|
|
197
|
-
(_a = this.server) === null || _a === void 0 ? void 0 : _a.close();
|
|
198
|
-
this.server = undefined;
|
|
199
|
-
return [2 /*return*/];
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
};
|
|
203
|
-
Decentralized.prototype.onRoundEndCommunication = function (updatedWeights, staleWeights, epoch, trainingInformant) {
|
|
204
|
-
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
205
|
-
var noisyWeights, msg, encodedMsg, getWeights, timeoutError, receivedWeights;
|
|
206
|
-
var _a;
|
|
207
|
-
var _this = this;
|
|
208
|
-
return (0, tslib_1.__generator)(this, function (_b) {
|
|
209
|
-
switch (_b.label) {
|
|
210
|
-
case 0:
|
|
211
|
-
noisyWeights = __1.privacy.addDifferentialPrivacy(updatedWeights, staleWeights, this.task);
|
|
212
|
-
_a = {
|
|
213
|
-
epoch: epoch
|
|
214
|
-
};
|
|
215
|
-
return [4 /*yield*/, __1.serialization.weights.encode(noisyWeights)];
|
|
216
|
-
case 1:
|
|
217
|
-
msg = (_a.weights = _b.sent(),
|
|
218
|
-
_a);
|
|
219
|
-
encodedMsg = msgpack_lite_1.default.encode(msg);
|
|
220
|
-
this.peers
|
|
221
|
-
.filter(function (peer) { return peer.connected; })
|
|
222
|
-
.forEach(function (peer, peerID) {
|
|
223
|
-
trainingInformant.addMessage("Sending weights to peer " + peerID);
|
|
224
|
-
trainingInformant.updateWhoReceivedMyModel("peer " + peerID);
|
|
225
|
-
peer.send(encodedMsg);
|
|
226
|
-
});
|
|
227
|
-
getWeights = function () {
|
|
228
|
-
return _this.weights
|
|
229
|
-
.valueSeq()
|
|
230
|
-
.map(function (epochesWeights) { return epochesWeights.get(epoch); });
|
|
231
|
-
};
|
|
232
|
-
timeoutError = new Error('timeout');
|
|
233
|
-
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
234
|
-
var interval = setInterval(function () {
|
|
235
|
-
var gotAllWeights = getWeights().every(function (weights) { return weights !== undefined; });
|
|
236
|
-
if (gotAllWeights) {
|
|
237
|
-
clearInterval(interval);
|
|
238
|
-
resolve();
|
|
239
|
-
}
|
|
240
|
-
}, TICK);
|
|
241
|
-
setTimeout(function () {
|
|
242
|
-
clearInterval(interval);
|
|
243
|
-
reject(timeoutError);
|
|
244
|
-
}, MAX_WAIT_PER_ROUND);
|
|
245
|
-
}).catch(function (err) {
|
|
246
|
-
if (err !== timeoutError) {
|
|
247
|
-
throw err;
|
|
248
|
-
}
|
|
249
|
-
})];
|
|
250
|
-
case 2:
|
|
251
|
-
_b.sent();
|
|
252
|
-
receivedWeights = getWeights()
|
|
253
|
-
.filter(function (weights) { return weights !== undefined; })
|
|
254
|
-
.toSet();
|
|
255
|
-
// Average weights
|
|
256
|
-
trainingInformant.addMessage('Averaging weights');
|
|
257
|
-
trainingInformant.updateNbrUpdatesWithOthers(1);
|
|
258
|
-
// Return the new "received" weights
|
|
259
|
-
return [2 /*return*/, __1.aggregation.averageWeights(receivedWeights)];
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
};
|
|
264
|
-
Decentralized.prototype.onTrainEndCommunication = function (_, trainingInformant) {
|
|
265
|
-
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
266
|
-
return (0, tslib_1.__generator)(this, function (_a) {
|
|
267
|
-
// TODO: enter seeding mode?
|
|
268
|
-
trainingInformant.addMessage('Training finished.');
|
|
269
|
-
return [2 /*return*/];
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
};
|
|
273
|
-
return Decentralized;
|
|
274
|
-
}(base_1.Base));
|
|
275
|
-
exports.Decentralized = Decentralized;
|
package/dist/testing/tester.d.ts
DELETED
package/dist/testing/tester.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Tester = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var model_actor_1 = require("../model_actor");
|
|
6
|
-
var Tester = /** @class */ (function (_super) {
|
|
7
|
-
(0, tslib_1.__extends)(Tester, _super);
|
|
8
|
-
function Tester() {
|
|
9
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
10
|
-
}
|
|
11
|
-
Tester.prototype.testModel = function () {
|
|
12
|
-
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
13
|
-
return (0, tslib_1.__generator)(this, function (_a) {
|
|
14
|
-
return [2 /*return*/, true];
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
return Tester;
|
|
19
|
-
}(model_actor_1.ModelActor));
|
|
20
|
-
exports.Tester = Tester;
|
|
21
|
-
exports.default = Tester;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { List, Set } from 'immutable';
|
|
2
|
-
import { TaskID } from '.';
|
|
3
|
-
import { TrainingSchemes } from './training/training_schemes';
|
|
4
|
-
/**
|
|
5
|
-
* Class that collects information about the status of the training-loop of the model.
|
|
6
|
-
*/
|
|
7
|
-
export declare class TrainingInformant {
|
|
8
|
-
private readonly nbrMessagesToShow;
|
|
9
|
-
readonly taskID: TaskID;
|
|
10
|
-
readonly taskTrainingScheme: TrainingSchemes;
|
|
11
|
-
whoReceivedMyModel: Set<unknown>;
|
|
12
|
-
nbrUpdatesWithOthers: number;
|
|
13
|
-
waitingTime: number;
|
|
14
|
-
nbrWeightRequests: number;
|
|
15
|
-
messages: List<unknown>;
|
|
16
|
-
currentRound: number;
|
|
17
|
-
currentNumberOfParticipants: number;
|
|
18
|
-
totalNumberOfParticipants: number;
|
|
19
|
-
averageNumberOfParticipants: number;
|
|
20
|
-
validationAccuracyChart: unknown;
|
|
21
|
-
validationAccuracy: number;
|
|
22
|
-
trainingAccuracyChart: unknown;
|
|
23
|
-
trainingAccuracy: number;
|
|
24
|
-
displayHeatmap: boolean;
|
|
25
|
-
currentValidationAccuracy: number;
|
|
26
|
-
validationAccuracyDataSerie: List<number>;
|
|
27
|
-
currentTrainingAccuracy: number;
|
|
28
|
-
trainingAccuracyDataSerie: List<number>;
|
|
29
|
-
weightsIn: number;
|
|
30
|
-
weightsOut: number;
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* @param nbrMessagesToShow the number of messages to be kept to inform the users about status of communication with other peers.
|
|
34
|
-
* @param taskID the task's name.
|
|
35
|
-
*/
|
|
36
|
-
constructor(nbrMessagesToShow: number, taskID: TaskID, taskTrainingScheme: TrainingSchemes);
|
|
37
|
-
/**
|
|
38
|
-
* Updates the set of peers who received my model.
|
|
39
|
-
* @param {String} peerName the peer's name to whom I recently shared my model to.
|
|
40
|
-
*/
|
|
41
|
-
updateWhoReceivedMyModel(peerName: string): void;
|
|
42
|
-
/**
|
|
43
|
-
* Updates the number of updates I did with other peers.
|
|
44
|
-
* @param {Number} nbrUpdates the number of updates I did thanks to other peers contribution since the last update of the parameter.
|
|
45
|
-
*/
|
|
46
|
-
updateNbrUpdatesWithOthers(nbrUpdates: number): void;
|
|
47
|
-
/**
|
|
48
|
-
* Updates the time I waited to receive weights.
|
|
49
|
-
* @param {Number} time
|
|
50
|
-
*/
|
|
51
|
-
updateWaitingTime(time: number): void;
|
|
52
|
-
/**
|
|
53
|
-
* Updates the number of weights request I received.
|
|
54
|
-
* @param {Number} nbrRequests the number of weight requests I received since the last update of the parameter.
|
|
55
|
-
*/
|
|
56
|
-
updateNbrWeightsRequests(nbrRequests: number): void;
|
|
57
|
-
/**
|
|
58
|
-
* Add a new message to the message list.
|
|
59
|
-
* @param {String} msg a message.
|
|
60
|
-
*/
|
|
61
|
-
addMessage(msg: string): void;
|
|
62
|
-
/**
|
|
63
|
-
* Update the server statistics with the JSON received from the server
|
|
64
|
-
* For now it's just the JSON, but we might want to keep it as a dictionnary
|
|
65
|
-
* @param {any} receivedStatistics statistics received from the server.
|
|
66
|
-
*/
|
|
67
|
-
updateWithServerStatistics(receivedStatistics: Record<string, number>): void;
|
|
68
|
-
/**
|
|
69
|
-
* Updates the data to be displayed on the validation accuracy graph.
|
|
70
|
-
* @param {Number} validationAccuracy the current validation accuracy of the model
|
|
71
|
-
*/
|
|
72
|
-
updateValidationAccuracyGraph(validationAccuracy: number): void;
|
|
73
|
-
/**
|
|
74
|
-
* Returns wether or not the Task's training scheme is Decentralized
|
|
75
|
-
* @returns Boolean value
|
|
76
|
-
*/
|
|
77
|
-
isTaskTrainingSchemeDecentralized(): boolean;
|
|
78
|
-
/**
|
|
79
|
-
* Returns wether or not the Task's training scheme is Federated
|
|
80
|
-
* @returns Boolean value
|
|
81
|
-
*/
|
|
82
|
-
isTaskTrainingSchemeFederated(): boolean;
|
|
83
|
-
/**
|
|
84
|
-
* Updates the data to be displayed on the training accuracy graph.
|
|
85
|
-
* @param {Number} trainingAccuracy the current training accuracy of the model
|
|
86
|
-
*/
|
|
87
|
-
updateTrainingAccuracyGraph(trainingAccuracy: number): void;
|
|
88
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TrainingInformant = void 0;
|
|
4
|
-
var immutable_1 = require("immutable");
|
|
5
|
-
var training_schemes_1 = require("./training/training_schemes");
|
|
6
|
-
var nbEpochsOnGraphs = 10;
|
|
7
|
-
/**
|
|
8
|
-
* Class that collects information about the status of the training-loop of the model.
|
|
9
|
-
*/
|
|
10
|
-
var TrainingInformant = /** @class */ (function () {
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @param nbrMessagesToShow the number of messages to be kept to inform the users about status of communication with other peers.
|
|
14
|
-
* @param taskID the task's name.
|
|
15
|
-
*/
|
|
16
|
-
function TrainingInformant(nbrMessagesToShow, taskID, taskTrainingScheme) {
|
|
17
|
-
this.nbrMessagesToShow = nbrMessagesToShow;
|
|
18
|
-
this.taskID = taskID;
|
|
19
|
-
this.taskTrainingScheme = taskTrainingScheme;
|
|
20
|
-
// Decentralized Informations
|
|
21
|
-
// number of people with whom I've shared my model
|
|
22
|
-
this.whoReceivedMyModel = (0, immutable_1.Set)();
|
|
23
|
-
// message feedback from peer-to-peer training
|
|
24
|
-
this.messages = (0, immutable_1.List)();
|
|
25
|
-
this.validationAccuracyDataSerie = (0, immutable_1.Repeat)(0, nbEpochsOnGraphs).toList();
|
|
26
|
-
this.trainingAccuracyDataSerie = (0, immutable_1.Repeat)(0, nbEpochsOnGraphs).toList();
|
|
27
|
-
this.weightsIn = 0;
|
|
28
|
-
this.weightsOut = 0;
|
|
29
|
-
// how many times the model has been averaged with someone's else model
|
|
30
|
-
this.nbrUpdatesWithOthers = 0;
|
|
31
|
-
// how much time I've been waiting for a model
|
|
32
|
-
this.waitingTime = 0;
|
|
33
|
-
// number of weight requests I've responded to
|
|
34
|
-
this.nbrWeightRequests = 0;
|
|
35
|
-
// statistics received from the server
|
|
36
|
-
this.currentRound = 0;
|
|
37
|
-
this.currentNumberOfParticipants = 0;
|
|
38
|
-
this.totalNumberOfParticipants = 0;
|
|
39
|
-
this.averageNumberOfParticipants = 0;
|
|
40
|
-
// validation accuracy chart
|
|
41
|
-
this.validationAccuracyChart = null; // new TrainingChart("validationAccuracy_".concat(taskID), "Validation Accuracy")
|
|
42
|
-
this.validationAccuracy = 0;
|
|
43
|
-
// training accuracy chart
|
|
44
|
-
this.trainingAccuracyChart = null; // new TrainingChart("trainingAccuracy_".concat(taskID), "Training Accuracy")
|
|
45
|
-
this.trainingAccuracy = 0;
|
|
46
|
-
// is the model using Interoperability (default to false)
|
|
47
|
-
this.displayHeatmap = false;
|
|
48
|
-
// default values for the validation and training charts
|
|
49
|
-
this.currentValidationAccuracy = 0;
|
|
50
|
-
this.currentTrainingAccuracy = 0;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Updates the set of peers who received my model.
|
|
54
|
-
* @param {String} peerName the peer's name to whom I recently shared my model to.
|
|
55
|
-
*/
|
|
56
|
-
TrainingInformant.prototype.updateWhoReceivedMyModel = function (peerName) {
|
|
57
|
-
this.whoReceivedMyModel = this.whoReceivedMyModel.add(peerName);
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Updates the number of updates I did with other peers.
|
|
61
|
-
* @param {Number} nbrUpdates the number of updates I did thanks to other peers contribution since the last update of the parameter.
|
|
62
|
-
*/
|
|
63
|
-
TrainingInformant.prototype.updateNbrUpdatesWithOthers = function (nbrUpdates) {
|
|
64
|
-
this.nbrUpdatesWithOthers += nbrUpdates;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Updates the time I waited to receive weights.
|
|
68
|
-
* @param {Number} time
|
|
69
|
-
*/
|
|
70
|
-
TrainingInformant.prototype.updateWaitingTime = function (time) {
|
|
71
|
-
this.waitingTime += time;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Updates the number of weights request I received.
|
|
75
|
-
* @param {Number} nbrRequests the number of weight requests I received since the last update of the parameter.
|
|
76
|
-
*/
|
|
77
|
-
TrainingInformant.prototype.updateNbrWeightsRequests = function (nbrRequests) {
|
|
78
|
-
this.nbrWeightRequests += nbrRequests;
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* Add a new message to the message list.
|
|
82
|
-
* @param {String} msg a message.
|
|
83
|
-
*/
|
|
84
|
-
TrainingInformant.prototype.addMessage = function (msg) {
|
|
85
|
-
if (this.messages.size >= this.nbrMessagesToShow) {
|
|
86
|
-
this.messages = this.messages.shift();
|
|
87
|
-
}
|
|
88
|
-
this.messages = this.messages.push(msg);
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Update the server statistics with the JSON received from the server
|
|
92
|
-
* For now it's just the JSON, but we might want to keep it as a dictionnary
|
|
93
|
-
* @param {any} receivedStatistics statistics received from the server.
|
|
94
|
-
*/
|
|
95
|
-
TrainingInformant.prototype.updateWithServerStatistics = function (receivedStatistics) {
|
|
96
|
-
this.currentRound = receivedStatistics.round;
|
|
97
|
-
this.currentNumberOfParticipants = receivedStatistics.currentNumberOfParticipants;
|
|
98
|
-
this.totalNumberOfParticipants = receivedStatistics.totalNumberOfParticipants;
|
|
99
|
-
this.averageNumberOfParticipants = receivedStatistics.averageNumberOfParticipants;
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Updates the data to be displayed on the validation accuracy graph.
|
|
103
|
-
* @param {Number} validationAccuracy the current validation accuracy of the model
|
|
104
|
-
*/
|
|
105
|
-
TrainingInformant.prototype.updateValidationAccuracyGraph = function (validationAccuracy) {
|
|
106
|
-
this.validationAccuracyDataSerie =
|
|
107
|
-
this.validationAccuracyDataSerie.shift().push(validationAccuracy);
|
|
108
|
-
this.currentValidationAccuracy = validationAccuracy;
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* Returns wether or not the Task's training scheme is Decentralized
|
|
112
|
-
* @returns Boolean value
|
|
113
|
-
*/
|
|
114
|
-
TrainingInformant.prototype.isTaskTrainingSchemeDecentralized = function () {
|
|
115
|
-
return this.taskTrainingScheme === training_schemes_1.TrainingSchemes.DECENTRALIZED;
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Returns wether or not the Task's training scheme is Federated
|
|
119
|
-
* @returns Boolean value
|
|
120
|
-
*/
|
|
121
|
-
TrainingInformant.prototype.isTaskTrainingSchemeFederated = function () {
|
|
122
|
-
return this.taskTrainingScheme === training_schemes_1.TrainingSchemes.FEDERATED;
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* Updates the data to be displayed on the training accuracy graph.
|
|
126
|
-
* @param {Number} trainingAccuracy the current training accuracy of the model
|
|
127
|
-
*/
|
|
128
|
-
TrainingInformant.prototype.updateTrainingAccuracyGraph = function (trainingAccuracy) {
|
|
129
|
-
this.trainingAccuracyDataSerie =
|
|
130
|
-
this.trainingAccuracyDataSerie.shift().push(trainingAccuracy);
|
|
131
|
-
this.currentTrainingAccuracy = trainingAccuracy;
|
|
132
|
-
};
|
|
133
|
-
return TrainingInformant;
|
|
134
|
-
}());
|
|
135
|
-
exports.TrainingInformant = TrainingInformant;
|