@epfml/discojs 2.1.1 → 2.1.2-p20240506085037.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/dist/aggregator/base.d.ts +180 -0
- package/dist/aggregator/base.js +236 -0
- package/dist/aggregator/get.d.ts +16 -0
- package/dist/aggregator/get.js +31 -0
- package/dist/aggregator/index.d.ts +7 -0
- package/dist/aggregator/index.js +4 -0
- package/dist/aggregator/mean.d.ts +23 -0
- package/dist/aggregator/mean.js +69 -0
- package/dist/aggregator/secure.d.ts +27 -0
- package/dist/aggregator/secure.js +91 -0
- package/dist/async_informant.d.ts +15 -0
- package/dist/async_informant.js +42 -0
- package/dist/client/base.d.ts +76 -0
- package/dist/client/base.js +88 -0
- package/dist/client/decentralized/base.d.ts +32 -0
- package/dist/client/decentralized/base.js +192 -0
- package/dist/client/decentralized/index.d.ts +2 -0
- package/dist/client/decentralized/index.js +2 -0
- package/dist/client/decentralized/messages.d.ts +28 -0
- package/dist/client/decentralized/messages.js +44 -0
- package/dist/client/decentralized/peer.d.ts +40 -0
- package/dist/client/decentralized/peer.js +189 -0
- package/dist/client/decentralized/peer_pool.d.ts +12 -0
- package/dist/client/decentralized/peer_pool.js +44 -0
- package/dist/client/event_connection.d.ts +34 -0
- package/dist/client/event_connection.js +105 -0
- package/dist/client/federated/base.d.ts +54 -0
- package/dist/client/federated/base.js +151 -0
- package/dist/client/federated/index.d.ts +2 -0
- package/dist/client/federated/index.js +2 -0
- package/dist/client/federated/messages.d.ts +30 -0
- package/dist/client/federated/messages.js +24 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.js +8 -0
- package/dist/client/local.d.ts +3 -0
- package/dist/client/local.js +3 -0
- package/dist/client/messages.d.ts +30 -0
- package/dist/client/messages.js +26 -0
- package/dist/client/types.d.ts +2 -0
- package/dist/client/types.js +4 -0
- package/dist/client/utils.d.ts +2 -0
- package/dist/client/utils.js +7 -0
- package/dist/dataset/data/data.d.ts +48 -0
- package/dist/dataset/data/data.js +72 -0
- package/dist/dataset/data/data_split.d.ts +8 -0
- package/dist/dataset/data/data_split.js +1 -0
- package/dist/dataset/data/image_data.d.ts +11 -0
- package/dist/dataset/data/image_data.js +38 -0
- package/dist/dataset/data/index.d.ts +6 -0
- package/dist/dataset/data/index.js +5 -0
- package/dist/dataset/data/preprocessing/base.d.ts +16 -0
- package/dist/dataset/data/preprocessing/base.js +1 -0
- package/dist/dataset/data/preprocessing/image_preprocessing.d.ts +13 -0
- package/dist/dataset/data/preprocessing/image_preprocessing.js +40 -0
- package/dist/dataset/data/preprocessing/index.d.ts +4 -0
- package/dist/dataset/data/preprocessing/index.js +3 -0
- package/dist/dataset/data/preprocessing/tabular_preprocessing.d.ts +13 -0
- package/dist/dataset/data/preprocessing/tabular_preprocessing.js +45 -0
- package/dist/dataset/data/preprocessing/text_preprocessing.d.ts +13 -0
- package/dist/dataset/data/preprocessing/text_preprocessing.js +85 -0
- package/dist/dataset/data/tabular_data.d.ts +11 -0
- package/dist/dataset/data/tabular_data.js +25 -0
- package/dist/dataset/data/text_data.d.ts +11 -0
- package/dist/dataset/data/text_data.js +14 -0
- package/dist/{core/dataset → dataset}/data_loader/data_loader.d.ts +3 -5
- package/dist/dataset/data_loader/data_loader.js +2 -0
- package/dist/dataset/data_loader/image_loader.d.ts +20 -3
- package/dist/dataset/data_loader/image_loader.js +98 -23
- package/dist/dataset/data_loader/index.d.ts +5 -2
- package/dist/dataset/data_loader/index.js +4 -7
- package/dist/dataset/data_loader/tabular_loader.d.ts +34 -3
- package/dist/dataset/data_loader/tabular_loader.js +75 -15
- package/dist/dataset/data_loader/text_loader.d.ts +14 -0
- package/dist/dataset/data_loader/text_loader.js +25 -0
- package/dist/dataset/dataset.d.ts +5 -0
- package/dist/dataset/dataset.js +1 -0
- package/dist/dataset/dataset_builder.d.ts +60 -0
- package/dist/dataset/dataset_builder.js +142 -0
- package/dist/dataset/index.d.ts +5 -0
- package/dist/dataset/index.js +3 -0
- package/dist/default_tasks/cifar10/index.d.ts +2 -0
- package/dist/{core/default_tasks/cifar10.js → default_tasks/cifar10/index.js} +28 -36
- package/dist/default_tasks/cifar10/model.d.ts +434 -0
- package/dist/default_tasks/cifar10/model.js +2385 -0
- package/dist/default_tasks/geotags/index.d.ts +2 -0
- package/dist/default_tasks/geotags/index.js +65 -0
- package/dist/default_tasks/geotags/model.d.ts +593 -0
- package/dist/default_tasks/geotags/model.js +4715 -0
- package/dist/default_tasks/index.d.ts +8 -0
- package/dist/default_tasks/index.js +8 -0
- package/dist/default_tasks/lus_covid.d.ts +2 -0
- package/dist/default_tasks/lus_covid.js +89 -0
- package/dist/default_tasks/mnist.d.ts +2 -0
- package/dist/{core/default_tasks → default_tasks}/mnist.js +26 -34
- package/dist/default_tasks/simple_face/index.d.ts +2 -0
- package/dist/{core/default_tasks/simple_face.js → default_tasks/simple_face/index.js} +17 -22
- package/dist/default_tasks/simple_face/model.d.ts +513 -0
- package/dist/default_tasks/simple_face/model.js +4301 -0
- package/dist/default_tasks/skin_mnist.d.ts +2 -0
- package/dist/default_tasks/skin_mnist.js +80 -0
- package/dist/default_tasks/titanic.d.ts +2 -0
- package/dist/{core/default_tasks → default_tasks}/titanic.js +24 -33
- package/dist/default_tasks/wikitext.d.ts +2 -0
- package/dist/default_tasks/wikitext.js +38 -0
- package/dist/index.d.ts +18 -2
- package/dist/index.js +18 -6
- package/dist/{core/informant → informant}/graph_informant.d.ts +1 -1
- package/dist/informant/graph_informant.js +20 -0
- package/dist/informant/index.d.ts +1 -0
- package/dist/informant/index.js +1 -0
- package/dist/{core/logging → logging}/console_logger.d.ts +2 -2
- package/dist/logging/console_logger.js +22 -0
- package/dist/logging/index.d.ts +2 -0
- package/dist/logging/index.js +1 -0
- package/dist/{core/logging → logging}/logger.d.ts +3 -3
- package/dist/logging/logger.js +1 -0
- package/dist/memory/base.d.ts +119 -0
- package/dist/memory/base.js +9 -0
- package/dist/memory/empty.d.ts +20 -0
- package/dist/memory/empty.js +43 -0
- package/dist/memory/index.d.ts +3 -1
- package/dist/memory/index.js +3 -5
- package/dist/memory/model_type.d.ts +9 -0
- package/dist/memory/model_type.js +10 -0
- package/dist/{core/privacy.d.ts → privacy.d.ts} +1 -1
- package/dist/{core/privacy.js → privacy.js} +11 -16
- package/dist/serialization/index.d.ts +2 -0
- package/dist/serialization/index.js +2 -0
- package/dist/serialization/model.d.ts +5 -0
- package/dist/serialization/model.js +67 -0
- package/dist/{core/serialization → serialization}/weights.d.ts +2 -2
- package/dist/serialization/weights.js +37 -0
- package/dist/task/data_example.js +14 -0
- package/dist/task/digest.js +14 -0
- package/dist/{core/task → task}/display_information.d.ts +5 -3
- package/dist/task/display_information.js +46 -0
- package/dist/task/index.d.ts +7 -0
- package/dist/task/index.js +5 -0
- package/dist/task/label_type.d.ts +9 -0
- package/dist/task/label_type.js +28 -0
- package/dist/task/summary.js +13 -0
- package/dist/{core/task → task}/task.d.ts +7 -7
- package/dist/task/task.js +22 -0
- package/dist/task/task_handler.d.ts +5 -0
- package/dist/task/task_handler.js +20 -0
- package/dist/task/task_provider.d.ts +5 -0
- package/dist/task/task_provider.js +1 -0
- package/dist/{core/task → task}/training_information.d.ts +9 -10
- package/dist/task/training_information.js +88 -0
- package/dist/training/disco.d.ts +40 -0
- package/dist/training/disco.js +107 -0
- package/dist/training/index.d.ts +2 -0
- package/dist/training/index.js +1 -0
- package/dist/training/trainer/distributed_trainer.d.ts +20 -0
- package/dist/training/trainer/distributed_trainer.js +36 -0
- package/dist/training/trainer/local_trainer.d.ts +12 -0
- package/dist/training/trainer/local_trainer.js +19 -0
- package/dist/training/trainer/trainer.d.ts +33 -0
- package/dist/training/trainer/trainer.js +52 -0
- package/dist/{core/training → training}/trainer/trainer_builder.d.ts +5 -7
- package/dist/training/trainer/trainer_builder.js +43 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.js +1 -0
- package/dist/utils/event_emitter.d.ts +40 -0
- package/dist/utils/event_emitter.js +57 -0
- package/dist/validation/index.d.ts +1 -0
- package/dist/validation/index.js +1 -0
- package/dist/validation/validator.d.ts +28 -0
- package/dist/validation/validator.js +132 -0
- package/dist/weights/aggregation.d.ts +21 -0
- package/dist/weights/aggregation.js +44 -0
- package/dist/weights/index.d.ts +2 -0
- package/dist/weights/index.js +2 -0
- package/dist/weights/weights_container.d.ts +68 -0
- package/dist/weights/weights_container.js +96 -0
- package/package.json +24 -15
- package/README.md +0 -53
- package/dist/core/async_buffer.d.ts +0 -41
- package/dist/core/async_buffer.js +0 -97
- package/dist/core/async_informant.d.ts +0 -20
- package/dist/core/async_informant.js +0 -69
- package/dist/core/client/base.d.ts +0 -33
- package/dist/core/client/base.js +0 -35
- package/dist/core/client/decentralized/base.d.ts +0 -32
- package/dist/core/client/decentralized/base.js +0 -212
- package/dist/core/client/decentralized/clear_text.d.ts +0 -14
- package/dist/core/client/decentralized/clear_text.js +0 -96
- package/dist/core/client/decentralized/index.d.ts +0 -4
- package/dist/core/client/decentralized/index.js +0 -9
- package/dist/core/client/decentralized/messages.d.ts +0 -41
- package/dist/core/client/decentralized/messages.js +0 -54
- package/dist/core/client/decentralized/peer.d.ts +0 -26
- package/dist/core/client/decentralized/peer.js +0 -210
- package/dist/core/client/decentralized/peer_pool.d.ts +0 -14
- package/dist/core/client/decentralized/peer_pool.js +0 -92
- package/dist/core/client/decentralized/sec_agg.d.ts +0 -22
- package/dist/core/client/decentralized/sec_agg.js +0 -190
- package/dist/core/client/decentralized/secret_shares.d.ts +0 -3
- package/dist/core/client/decentralized/secret_shares.js +0 -39
- package/dist/core/client/decentralized/types.d.ts +0 -2
- package/dist/core/client/decentralized/types.js +0 -7
- package/dist/core/client/event_connection.d.ts +0 -37
- package/dist/core/client/event_connection.js +0 -158
- package/dist/core/client/federated/client.d.ts +0 -37
- package/dist/core/client/federated/client.js +0 -273
- package/dist/core/client/federated/index.d.ts +0 -2
- package/dist/core/client/federated/index.js +0 -7
- package/dist/core/client/federated/messages.d.ts +0 -38
- package/dist/core/client/federated/messages.js +0 -25
- package/dist/core/client/index.d.ts +0 -5
- package/dist/core/client/index.js +0 -11
- package/dist/core/client/local.d.ts +0 -8
- package/dist/core/client/local.js +0 -36
- package/dist/core/client/messages.d.ts +0 -28
- package/dist/core/client/messages.js +0 -33
- package/dist/core/client/utils.d.ts +0 -2
- package/dist/core/client/utils.js +0 -19
- package/dist/core/dataset/data/data.d.ts +0 -11
- package/dist/core/dataset/data/data.js +0 -20
- package/dist/core/dataset/data/data_split.d.ts +0 -5
- package/dist/core/dataset/data/data_split.js +0 -2
- package/dist/core/dataset/data/image_data.d.ts +0 -8
- package/dist/core/dataset/data/image_data.js +0 -64
- package/dist/core/dataset/data/index.d.ts +0 -5
- package/dist/core/dataset/data/index.js +0 -11
- package/dist/core/dataset/data/preprocessing.d.ts +0 -13
- package/dist/core/dataset/data/preprocessing.js +0 -33
- package/dist/core/dataset/data/tabular_data.d.ts +0 -8
- package/dist/core/dataset/data/tabular_data.js +0 -40
- package/dist/core/dataset/data_loader/data_loader.js +0 -10
- package/dist/core/dataset/data_loader/image_loader.d.ts +0 -17
- package/dist/core/dataset/data_loader/image_loader.js +0 -141
- package/dist/core/dataset/data_loader/index.d.ts +0 -3
- package/dist/core/dataset/data_loader/index.js +0 -9
- package/dist/core/dataset/data_loader/tabular_loader.d.ts +0 -29
- package/dist/core/dataset/data_loader/tabular_loader.js +0 -101
- package/dist/core/dataset/dataset.d.ts +0 -2
- package/dist/core/dataset/dataset.js +0 -2
- package/dist/core/dataset/dataset_builder.d.ts +0 -18
- package/dist/core/dataset/dataset_builder.js +0 -96
- package/dist/core/dataset/index.d.ts +0 -4
- package/dist/core/dataset/index.js +0 -14
- package/dist/core/default_tasks/cifar10.d.ts +0 -2
- package/dist/core/default_tasks/geotags.d.ts +0 -2
- package/dist/core/default_tasks/geotags.js +0 -69
- package/dist/core/default_tasks/index.d.ts +0 -6
- package/dist/core/default_tasks/index.js +0 -15
- package/dist/core/default_tasks/lus_covid.d.ts +0 -2
- package/dist/core/default_tasks/lus_covid.js +0 -96
- package/dist/core/default_tasks/mnist.d.ts +0 -2
- package/dist/core/default_tasks/simple_face.d.ts +0 -2
- package/dist/core/default_tasks/titanic.d.ts +0 -2
- package/dist/core/index.d.ts +0 -18
- package/dist/core/index.js +0 -39
- package/dist/core/informant/graph_informant.js +0 -23
- package/dist/core/informant/index.d.ts +0 -3
- package/dist/core/informant/index.js +0 -9
- package/dist/core/informant/training_informant/base.d.ts +0 -31
- package/dist/core/informant/training_informant/base.js +0 -83
- package/dist/core/informant/training_informant/decentralized.d.ts +0 -5
- package/dist/core/informant/training_informant/decentralized.js +0 -22
- package/dist/core/informant/training_informant/federated.d.ts +0 -14
- package/dist/core/informant/training_informant/federated.js +0 -32
- package/dist/core/informant/training_informant/index.d.ts +0 -4
- package/dist/core/informant/training_informant/index.js +0 -11
- package/dist/core/informant/training_informant/local.d.ts +0 -6
- package/dist/core/informant/training_informant/local.js +0 -20
- package/dist/core/logging/console_logger.js +0 -33
- package/dist/core/logging/index.d.ts +0 -3
- package/dist/core/logging/index.js +0 -9
- package/dist/core/logging/logger.js +0 -9
- package/dist/core/logging/trainer_logger.d.ts +0 -24
- package/dist/core/logging/trainer_logger.js +0 -59
- package/dist/core/memory/base.d.ts +0 -22
- package/dist/core/memory/base.js +0 -9
- package/dist/core/memory/empty.d.ts +0 -14
- package/dist/core/memory/empty.js +0 -75
- package/dist/core/memory/index.d.ts +0 -3
- package/dist/core/memory/index.js +0 -9
- package/dist/core/memory/model_type.d.ts +0 -4
- package/dist/core/memory/model_type.js +0 -9
- package/dist/core/serialization/index.d.ts +0 -2
- package/dist/core/serialization/index.js +0 -6
- package/dist/core/serialization/model.d.ts +0 -5
- package/dist/core/serialization/model.js +0 -55
- package/dist/core/serialization/weights.js +0 -64
- package/dist/core/task/data_example.js +0 -24
- package/dist/core/task/digest.js +0 -18
- package/dist/core/task/display_information.js +0 -49
- package/dist/core/task/index.d.ts +0 -6
- package/dist/core/task/index.js +0 -15
- package/dist/core/task/model_compile_data.d.ts +0 -6
- package/dist/core/task/model_compile_data.js +0 -22
- package/dist/core/task/summary.js +0 -19
- package/dist/core/task/task.js +0 -35
- package/dist/core/task/task_handler.d.ts +0 -5
- package/dist/core/task/task_handler.js +0 -53
- package/dist/core/task/task_provider.d.ts +0 -6
- package/dist/core/task/task_provider.js +0 -13
- package/dist/core/task/training_information.js +0 -66
- package/dist/core/training/disco.d.ts +0 -23
- package/dist/core/training/disco.js +0 -130
- package/dist/core/training/index.d.ts +0 -2
- package/dist/core/training/index.js +0 -7
- package/dist/core/training/trainer/distributed_trainer.d.ts +0 -20
- package/dist/core/training/trainer/distributed_trainer.js +0 -65
- package/dist/core/training/trainer/local_trainer.d.ts +0 -11
- package/dist/core/training/trainer/local_trainer.js +0 -34
- package/dist/core/training/trainer/round_tracker.d.ts +0 -30
- package/dist/core/training/trainer/round_tracker.js +0 -47
- package/dist/core/training/trainer/trainer.d.ts +0 -65
- package/dist/core/training/trainer/trainer.js +0 -160
- package/dist/core/training/trainer/trainer_builder.js +0 -95
- package/dist/core/training/training_schemes.d.ts +0 -5
- package/dist/core/training/training_schemes.js +0 -10
- package/dist/core/types.d.ts +0 -4
- package/dist/core/types.js +0 -2
- package/dist/core/validation/index.d.ts +0 -1
- package/dist/core/validation/index.js +0 -5
- package/dist/core/validation/validator.d.ts +0 -17
- package/dist/core/validation/validator.js +0 -104
- package/dist/core/weights/aggregation.d.ts +0 -7
- package/dist/core/weights/aggregation.js +0 -72
- package/dist/core/weights/index.d.ts +0 -2
- package/dist/core/weights/index.js +0 -7
- package/dist/core/weights/weights_container.d.ts +0 -19
- package/dist/core/weights/weights_container.js +0 -64
- package/dist/imports.d.ts +0 -2
- package/dist/imports.js +0 -7
- package/dist/memory/memory.d.ts +0 -26
- package/dist/memory/memory.js +0 -160
- package/dist/{core/task → task}/data_example.d.ts +1 -1
- package/dist/{core/task → task}/digest.d.ts +0 -0
- package/dist/{core/task → task}/summary.d.ts +1 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { List } from 'immutable';
|
|
2
|
+
import * as tf from '@tensorflow/tfjs';
|
|
3
|
+
import { WeightsContainer } from './weights_container.js';
|
|
4
|
+
function parseWeights(weights) {
|
|
5
|
+
const r = List(weights).map((w) => w instanceof WeightsContainer ? w : new WeightsContainer(w));
|
|
6
|
+
const size = r.first()?.weights.length;
|
|
7
|
+
if (size === undefined) {
|
|
8
|
+
throw new Error('no weights to work with');
|
|
9
|
+
}
|
|
10
|
+
r.rest().forEach((w) => {
|
|
11
|
+
const actual = w.weights.length;
|
|
12
|
+
if (actual !== size) {
|
|
13
|
+
throw new Error(`weights dimensions are different for some of the operands: expected ${size} but found ${actual}`);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return r;
|
|
17
|
+
}
|
|
18
|
+
function reduce(weights, fn) {
|
|
19
|
+
return parseWeights(weights).reduce((acc, ws) => acc.mapWith(ws, fn));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Sums the given iterable of weights entry-wise.
|
|
23
|
+
* @param weights The list of weights to sum
|
|
24
|
+
* @returns The summed weights
|
|
25
|
+
*/
|
|
26
|
+
export function sum(weights) {
|
|
27
|
+
return reduce(weights, tf.add);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Computes the successive entry-wise difference between the weights of the given iterable.
|
|
31
|
+
* The operation is not commutative w.r.t. the iterable's ordering.
|
|
32
|
+
*/
|
|
33
|
+
export function diff(weights) {
|
|
34
|
+
return reduce(weights, tf.sub);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Averages the given iterable of weights entry-wise.
|
|
38
|
+
* @param weights The list of weights to average
|
|
39
|
+
* @returns The averaged weights
|
|
40
|
+
*/
|
|
41
|
+
export function avg(weights) {
|
|
42
|
+
const ws = List(weights);
|
|
43
|
+
return sum(ws).map((w) => w.div(ws.size));
|
|
44
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as tf from '@tensorflow/tfjs';
|
|
2
|
+
type Weights = tf.Tensor[];
|
|
3
|
+
export type TensorLike = tf.Tensor | ArrayLike<number>;
|
|
4
|
+
/**
|
|
5
|
+
* Convenient wrapper object representing an immutable list of TF.js tensors.
|
|
6
|
+
*/
|
|
7
|
+
export declare class WeightsContainer {
|
|
8
|
+
private readonly _weights;
|
|
9
|
+
/**
|
|
10
|
+
* Constructs a weights container based on the given weights iterable.
|
|
11
|
+
* The iterable's elements can either be regular TF.js tensors or number arrays.
|
|
12
|
+
* @param weights The weights iterable to build the weights container from
|
|
13
|
+
*/
|
|
14
|
+
constructor(weights: Iterable<TensorLike>);
|
|
15
|
+
get weights(): Weights;
|
|
16
|
+
/**
|
|
17
|
+
* Adds this weights container with another one. The addition is performed entry-wise.
|
|
18
|
+
* The weights containers must be of the same shape.
|
|
19
|
+
* @param other The other weights container
|
|
20
|
+
* @returns A new subtracted weights container
|
|
21
|
+
*/
|
|
22
|
+
add(other: WeightsContainer): WeightsContainer;
|
|
23
|
+
/**
|
|
24
|
+
* Subtracts another weights container from this one. The subtraction is performed entry-wise.
|
|
25
|
+
* The weights containers must be of the same shape.
|
|
26
|
+
* @param other The other weights container
|
|
27
|
+
* @returns A new subtracted weights container
|
|
28
|
+
*/
|
|
29
|
+
sub(other: WeightsContainer): WeightsContainer;
|
|
30
|
+
/**
|
|
31
|
+
* Multiplies this weights container with this one. The multiplication is performed entry-wise.
|
|
32
|
+
* The weights containers must be of the same shape.
|
|
33
|
+
* @param other The other weights container
|
|
34
|
+
* @returns A new multiplied weights container
|
|
35
|
+
*/
|
|
36
|
+
mul(other: TensorLike | number): WeightsContainer;
|
|
37
|
+
/**
|
|
38
|
+
* Zips this weights container with another one and applies the given binary operator to the
|
|
39
|
+
* coupled entries.
|
|
40
|
+
* @param other The other weights container
|
|
41
|
+
* @param fn The binary operator
|
|
42
|
+
* @returns The mapping's result
|
|
43
|
+
*/
|
|
44
|
+
mapWith(other: WeightsContainer, fn: (a: tf.Tensor, b: tf.Tensor) => tf.Tensor): WeightsContainer;
|
|
45
|
+
map(fn: (t: tf.Tensor, i: number) => tf.Tensor): WeightsContainer;
|
|
46
|
+
map(fn: (t: tf.Tensor) => tf.Tensor): WeightsContainer;
|
|
47
|
+
reduce(fn: (acc: tf.Tensor, t: tf.Tensor) => tf.Tensor): tf.Tensor;
|
|
48
|
+
/**
|
|
49
|
+
* Access the TF.js tensor located at the given index.
|
|
50
|
+
* @param index The tensor's index
|
|
51
|
+
* @returns The tensor located at the index
|
|
52
|
+
*/
|
|
53
|
+
get(index: number): tf.Tensor | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Computes the weights container's Frobenius norm
|
|
56
|
+
* @returns The Frobenius norm
|
|
57
|
+
*/
|
|
58
|
+
frobeniusNorm(): number;
|
|
59
|
+
concat(other: WeightsContainer): WeightsContainer;
|
|
60
|
+
equals(other: WeightsContainer, margin?: number): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Instantiates a new weights container from the given tensors or arrays of numbers.
|
|
63
|
+
* @param weights The tensors or number arrays
|
|
64
|
+
* @returns The instantiated weights container
|
|
65
|
+
*/
|
|
66
|
+
static of(...weights: TensorLike[]): WeightsContainer;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { List } from 'immutable';
|
|
2
|
+
import * as tf from '@tensorflow/tfjs';
|
|
3
|
+
/**
|
|
4
|
+
* Convenient wrapper object representing an immutable list of TF.js tensors.
|
|
5
|
+
*/
|
|
6
|
+
export class WeightsContainer {
|
|
7
|
+
_weights;
|
|
8
|
+
/**
|
|
9
|
+
* Constructs a weights container based on the given weights iterable.
|
|
10
|
+
* The iterable's elements can either be regular TF.js tensors or number arrays.
|
|
11
|
+
* @param weights The weights iterable to build the weights container from
|
|
12
|
+
*/
|
|
13
|
+
constructor(weights) {
|
|
14
|
+
this._weights = List(weights).map((w) => w instanceof tf.Tensor ? w : tf.tensor(w));
|
|
15
|
+
}
|
|
16
|
+
get weights() {
|
|
17
|
+
return this._weights.toArray();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Adds this weights container with another one. The addition is performed entry-wise.
|
|
21
|
+
* The weights containers must be of the same shape.
|
|
22
|
+
* @param other The other weights container
|
|
23
|
+
* @returns A new subtracted weights container
|
|
24
|
+
*/
|
|
25
|
+
add(other) {
|
|
26
|
+
return this.mapWith(other, tf.add);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Subtracts another weights container from this one. The subtraction is performed entry-wise.
|
|
30
|
+
* The weights containers must be of the same shape.
|
|
31
|
+
* @param other The other weights container
|
|
32
|
+
* @returns A new subtracted weights container
|
|
33
|
+
*/
|
|
34
|
+
sub(other) {
|
|
35
|
+
return this.mapWith(other, tf.sub);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Multiplies this weights container with this one. The multiplication is performed entry-wise.
|
|
39
|
+
* The weights containers must be of the same shape.
|
|
40
|
+
* @param other The other weights container
|
|
41
|
+
* @returns A new multiplied weights container
|
|
42
|
+
*/
|
|
43
|
+
mul(other) {
|
|
44
|
+
return new WeightsContainer(this._weights
|
|
45
|
+
.map(w => w.mul(other)));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Zips this weights container with another one and applies the given binary operator to the
|
|
49
|
+
* coupled entries.
|
|
50
|
+
* @param other The other weights container
|
|
51
|
+
* @param fn The binary operator
|
|
52
|
+
* @returns The mapping's result
|
|
53
|
+
*/
|
|
54
|
+
mapWith(other, fn) {
|
|
55
|
+
return new WeightsContainer(this._weights
|
|
56
|
+
.zip(other._weights)
|
|
57
|
+
.map(([w1, w2]) => fn(w1, w2)));
|
|
58
|
+
}
|
|
59
|
+
map(fn) {
|
|
60
|
+
return new WeightsContainer(this._weights.map(fn));
|
|
61
|
+
}
|
|
62
|
+
reduce(fn) {
|
|
63
|
+
return this._weights.reduce(fn);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Access the TF.js tensor located at the given index.
|
|
67
|
+
* @param index The tensor's index
|
|
68
|
+
* @returns The tensor located at the index
|
|
69
|
+
*/
|
|
70
|
+
get(index) {
|
|
71
|
+
return this._weights.get(index);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Computes the weights container's Frobenius norm
|
|
75
|
+
* @returns The Frobenius norm
|
|
76
|
+
*/
|
|
77
|
+
frobeniusNorm() {
|
|
78
|
+
return Math.sqrt(this.map((w) => w.square().sum()).reduce((a, b) => a.add(b)).dataSync()[0]);
|
|
79
|
+
}
|
|
80
|
+
concat(other) {
|
|
81
|
+
return WeightsContainer.of(...this.weights, ...other.weights);
|
|
82
|
+
}
|
|
83
|
+
equals(other, margin = 0) {
|
|
84
|
+
return this._weights
|
|
85
|
+
.zip(other._weights)
|
|
86
|
+
.every(([w1, w2]) => w1.sub(w2).abs().lessEqual(margin).all().dataSync()[0] === 1);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Instantiates a new weights container from the given tensors or arrays of numbers.
|
|
90
|
+
* @param weights The tensors or number arrays
|
|
91
|
+
* @returns The instantiated weights container
|
|
92
|
+
*/
|
|
93
|
+
static of(...weights) {
|
|
94
|
+
return new this(weights);
|
|
95
|
+
}
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@epfml/discojs",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2-p20240506085037.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "dist/index.js",
|
|
5
6
|
"types": "dist/index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"build
|
|
9
|
-
"
|
|
10
|
-
"
|
|
8
|
+
"watch": "nodemon --ext ts --ignore dist --exec npm run",
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"lint": "npx eslint .",
|
|
11
|
+
"test": "mocha"
|
|
11
12
|
},
|
|
12
13
|
"repository": {
|
|
13
14
|
"type": "git",
|
|
@@ -18,17 +19,25 @@
|
|
|
18
19
|
},
|
|
19
20
|
"homepage": "https://github.com/epfml/disco#readme",
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"msgpack-lite": "0.1",
|
|
22
|
-
"immutable": "4",
|
|
23
22
|
"@tensorflow/tfjs": "4",
|
|
23
|
+
"@xenova/transformers": "2",
|
|
24
|
+
"axios": "1",
|
|
25
|
+
"immutable": "4",
|
|
26
|
+
"isomorphic-wrtc": "1",
|
|
27
|
+
"isomorphic-ws": "5",
|
|
28
|
+
"msgpack-lite": "0.1",
|
|
29
|
+
"simple-peer": "9",
|
|
24
30
|
"tslib": "2",
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
"@types/
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
31
|
+
"ws": "8"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@tensorflow/tfjs-node": "4",
|
|
35
|
+
"@types/chai": "4",
|
|
36
|
+
"@types/mocha": "10",
|
|
37
|
+
"@types/simple-peer": "9",
|
|
38
|
+
"chai": "5",
|
|
39
|
+
"mocha": "10",
|
|
40
|
+
"nodemon": "3",
|
|
41
|
+
"ts-node": "10"
|
|
33
42
|
}
|
|
34
43
|
}
|
package/README.md
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# Disco.js Web Module
|
|
2
|
-
|
|
3
|
-
`discojs-web` contains the browser-only code of Disco.js, based off and extending `discojs-core`.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
The `discojs-web` project is available as the `@epfml/discojs` NPM package, which can be installed with
|
|
8
|
-
`npm i @epfml/discojs`.
|
|
9
|
-
|
|
10
|
-
### Development Environment
|
|
11
|
-
|
|
12
|
-
The dev tools run on Node.js and require `npm`, a package manager for the Node.js runtime environment.
|
|
13
|
-
We recommend using [nvm](https://github.com/nvm-sh/nvm) for installing both Node.js and NPM.
|
|
14
|
-
|
|
15
|
-
To install the project's dependencies, run:
|
|
16
|
-
|
|
17
|
-
```
|
|
18
|
-
cd ..
|
|
19
|
-
npm ci
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Since the dependencies of `discojs-core`, `discojs-web` and `discojs-node` are the same, they are specified in a top-level `package.json` file, to ease installation and building.
|
|
23
|
-
|
|
24
|
-
> **⚠ WARNING: Apple Silicon.**
|
|
25
|
-
> `TensorFlow.js` version `3` do support M1 processors for macs. To do so, make sure you have an `arm` Node.js executable installed (not `x86_64`). It can be checked using:
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
node -p "process.arch"
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
which should return something similar to `arm64`.
|
|
32
|
-
|
|
33
|
-
## Build
|
|
34
|
-
|
|
35
|
-
The server and CLI modules, as well as all unit tests (except Cypress) use the `discojs-web` interface, i.e. they all run on Node.js. This Disco.js Node module is build on top of and extends `discojs-core`, whose code is [symlinked](https://en.wikipedia.org/wiki/Symbolic_link) into `discojs-web/src/core`. To build this project:
|
|
36
|
-
|
|
37
|
-
```
|
|
38
|
-
npm run build
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
This invokes the TypeScript compiler (`tsc`). It will output the compilation files of `discojs-web` in a `dist/` directory. To recompile from stratch, simply `rm -rf dist/` before running `npm run build` again.
|
|
42
|
-
|
|
43
|
-
## Development
|
|
44
|
-
|
|
45
|
-
### Contributing
|
|
46
|
-
|
|
47
|
-
Contributions to `discojs-web` must only include browser-specific code. Code common to both the browser and Node.js must be added to `discojs-core` instead.
|
|
48
|
-
|
|
49
|
-
As a rule of thumb, the `src/core/` directory must never be modified when modifying `discojs-web`, since it is [symlinked](https://en.wikipedia.org/wiki/Symbolic_link) to `discojs-core`.
|
|
50
|
-
|
|
51
|
-
If you wish to add a new file or submodule to the project, please do so in a similar way as `src/core/` is structured. That is, [adding a new task](../../docs/TASK.md) to `discojs-web` would mean adding a new file to `src/tasks/` and modifying `src/tasks/index.ts` (NOT `src/core/tasks/...`).
|
|
52
|
-
|
|
53
|
-
Note that, if you end up making calls to the Tensorflow.js API, you must import it from the root index. This is to ensure the Node version of TF.js is loaded, and only once.
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Map } from 'immutable';
|
|
2
|
-
import { TaskID, AsyncInformant } from '.';
|
|
3
|
-
/**
|
|
4
|
-
* The AsyncWeightsBuffer class holds and manipulates information about the
|
|
5
|
-
* async weights buffer. It works as follows:
|
|
6
|
-
*
|
|
7
|
-
* Setup: Init round to zero and create empty buffer (a map from user id to weights)
|
|
8
|
-
*
|
|
9
|
-
* - When a user adds weights only do so when they are recent weights: i.e. this.round - round <= roundCutoff.
|
|
10
|
-
* - If a user already added weights, update them. (-> there can be at most one entry of weights per id in a buffer).
|
|
11
|
-
* - When the buffer is full, call aggregateAndStoreWeights with the weights in the buffer and then increment round by one and reset the buffer.
|
|
12
|
-
*
|
|
13
|
-
* @remarks
|
|
14
|
-
* taskID: corresponds to the task that weights correspond to.
|
|
15
|
-
* bufferCapacity: size of the buffer.
|
|
16
|
-
* buffer: holds a map of users to their added weights.
|
|
17
|
-
* round: the latest round of the weight buffer.
|
|
18
|
-
* roundCutoff: cutoff for accepted rounds.
|
|
19
|
-
*/
|
|
20
|
-
export declare class AsyncBuffer<T> {
|
|
21
|
-
readonly taskID: TaskID;
|
|
22
|
-
private readonly bufferCapacity;
|
|
23
|
-
private readonly aggregateAndStoreWeights;
|
|
24
|
-
private readonly roundCutoff;
|
|
25
|
-
buffer: Map<string, T>;
|
|
26
|
-
round: number;
|
|
27
|
-
private observer;
|
|
28
|
-
constructor(taskID: TaskID, bufferCapacity: number, aggregateAndStoreWeights: (weights: Iterable<T>) => Promise<void>, roundCutoff?: number);
|
|
29
|
-
registerObserver(observer: AsyncInformant<T>): void;
|
|
30
|
-
bufferIsFull(): boolean;
|
|
31
|
-
private updateWeightsIfBufferIsFull;
|
|
32
|
-
isNotWithinRoundCutoff(round: number): boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Add weights originating from weights of a given round.
|
|
35
|
-
* Only add to buffer if the given round is not old.
|
|
36
|
-
* @param weights
|
|
37
|
-
* @param round
|
|
38
|
-
* @returns true if weights were added, and false otherwise
|
|
39
|
-
*/
|
|
40
|
-
add(id: string, weights: T, round: number): Promise<boolean>;
|
|
41
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AsyncBuffer = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var immutable_1 = require("immutable");
|
|
6
|
-
/**
|
|
7
|
-
* The AsyncWeightsBuffer class holds and manipulates information about the
|
|
8
|
-
* async weights buffer. It works as follows:
|
|
9
|
-
*
|
|
10
|
-
* Setup: Init round to zero and create empty buffer (a map from user id to weights)
|
|
11
|
-
*
|
|
12
|
-
* - When a user adds weights only do so when they are recent weights: i.e. this.round - round <= roundCutoff.
|
|
13
|
-
* - If a user already added weights, update them. (-> there can be at most one entry of weights per id in a buffer).
|
|
14
|
-
* - When the buffer is full, call aggregateAndStoreWeights with the weights in the buffer and then increment round by one and reset the buffer.
|
|
15
|
-
*
|
|
16
|
-
* @remarks
|
|
17
|
-
* taskID: corresponds to the task that weights correspond to.
|
|
18
|
-
* bufferCapacity: size of the buffer.
|
|
19
|
-
* buffer: holds a map of users to their added weights.
|
|
20
|
-
* round: the latest round of the weight buffer.
|
|
21
|
-
* roundCutoff: cutoff for accepted rounds.
|
|
22
|
-
*/
|
|
23
|
-
var AsyncBuffer = /** @class */ (function () {
|
|
24
|
-
function AsyncBuffer(taskID, bufferCapacity, aggregateAndStoreWeights, roundCutoff) {
|
|
25
|
-
if (roundCutoff === void 0) { roundCutoff = 0; }
|
|
26
|
-
this.taskID = taskID;
|
|
27
|
-
this.bufferCapacity = bufferCapacity;
|
|
28
|
-
this.aggregateAndStoreWeights = aggregateAndStoreWeights;
|
|
29
|
-
this.roundCutoff = roundCutoff;
|
|
30
|
-
this.buffer = (0, immutable_1.Map)();
|
|
31
|
-
this.round = 0;
|
|
32
|
-
}
|
|
33
|
-
AsyncBuffer.prototype.registerObserver = function (observer) {
|
|
34
|
-
this.observer = observer;
|
|
35
|
-
};
|
|
36
|
-
// TODO do not test private
|
|
37
|
-
AsyncBuffer.prototype.bufferIsFull = function () {
|
|
38
|
-
return this.buffer.size >= this.bufferCapacity;
|
|
39
|
-
};
|
|
40
|
-
AsyncBuffer.prototype.updateWeightsIfBufferIsFull = function () {
|
|
41
|
-
var _a;
|
|
42
|
-
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
43
|
-
return (0, tslib_1.__generator)(this, function (_b) {
|
|
44
|
-
switch (_b.label) {
|
|
45
|
-
case 0:
|
|
46
|
-
if (!this.bufferIsFull()) return [3 /*break*/, 2];
|
|
47
|
-
return [4 /*yield*/, this.aggregateAndStoreWeights(this.buffer.values())];
|
|
48
|
-
case 1:
|
|
49
|
-
_b.sent();
|
|
50
|
-
this.round += 1;
|
|
51
|
-
(_a = this.observer) === null || _a === void 0 ? void 0 : _a.update();
|
|
52
|
-
this.buffer = (0, immutable_1.Map)();
|
|
53
|
-
console.log('\n************************************************************');
|
|
54
|
-
console.log("Buffer is full; Aggregating weights and starting round: " + this.round + "\n");
|
|
55
|
-
_b.label = 2;
|
|
56
|
-
case 2: return [2 /*return*/];
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
// TODO do not test private
|
|
62
|
-
AsyncBuffer.prototype.isNotWithinRoundCutoff = function (round) {
|
|
63
|
-
// Note that always this.round >= round
|
|
64
|
-
return this.round - round > this.roundCutoff;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Add weights originating from weights of a given round.
|
|
68
|
-
* Only add to buffer if the given round is not old.
|
|
69
|
-
* @param weights
|
|
70
|
-
* @param round
|
|
71
|
-
* @returns true if weights were added, and false otherwise
|
|
72
|
-
*/
|
|
73
|
-
AsyncBuffer.prototype.add = function (id, weights, round) {
|
|
74
|
-
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
75
|
-
var weightsUpdatedByUser, msg;
|
|
76
|
-
return (0, tslib_1.__generator)(this, function (_a) {
|
|
77
|
-
switch (_a.label) {
|
|
78
|
-
case 0:
|
|
79
|
-
if (this.isNotWithinRoundCutoff(round)) {
|
|
80
|
-
console.log("Did not add weights of " + id + " to buffer. Due to old round update: " + round + ", current round is " + this.round);
|
|
81
|
-
return [2 /*return*/, false];
|
|
82
|
-
}
|
|
83
|
-
weightsUpdatedByUser = this.buffer.has(id);
|
|
84
|
-
msg = weightsUpdatedByUser ? '\tUpdating' : '-> Adding new';
|
|
85
|
-
console.log(msg + " weights of " + id + " to buffer.");
|
|
86
|
-
this.buffer = this.buffer.set(id, weights);
|
|
87
|
-
return [4 /*yield*/, this.updateWeightsIfBufferIsFull()];
|
|
88
|
-
case 1:
|
|
89
|
-
_a.sent();
|
|
90
|
-
return [2 /*return*/, true];
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
return AsyncBuffer;
|
|
96
|
-
}());
|
|
97
|
-
exports.AsyncBuffer = AsyncBuffer;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { AsyncBuffer } from './async_buffer';
|
|
2
|
-
export declare class AsyncInformant<T> {
|
|
3
|
-
private readonly asyncBuffer;
|
|
4
|
-
private round;
|
|
5
|
-
private currentNumberOfParticipants;
|
|
6
|
-
private totalNumberOfParticipants;
|
|
7
|
-
private averageNumberOfParticipants;
|
|
8
|
-
constructor(asyncBuffer: AsyncBuffer<T>);
|
|
9
|
-
update(): void;
|
|
10
|
-
private updateRound;
|
|
11
|
-
private updateNumberOfParticipants;
|
|
12
|
-
private updateAverageNumberOfParticipants;
|
|
13
|
-
private updateTotalNumberOfParticipants;
|
|
14
|
-
getCurrentRound(): number;
|
|
15
|
-
getNumberOfParticipants(): number;
|
|
16
|
-
getTotalNumberOfParticipants(): number;
|
|
17
|
-
getAverageNumberOfParticipants(): number;
|
|
18
|
-
getAllStatistics(): Record<'round' | 'currentNumberOfParticipants' | 'totalNumberOfParticipants' | 'averageNumberOfParticipants', number>;
|
|
19
|
-
printAllInfos(): void;
|
|
20
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AsyncInformant = void 0;
|
|
4
|
-
var AsyncInformant = /** @class */ (function () {
|
|
5
|
-
function AsyncInformant(asyncBuffer) {
|
|
6
|
-
this.asyncBuffer = asyncBuffer;
|
|
7
|
-
this.round = 0;
|
|
8
|
-
this.currentNumberOfParticipants = 0;
|
|
9
|
-
this.totalNumberOfParticipants = 0;
|
|
10
|
-
this.averageNumberOfParticipants = 0;
|
|
11
|
-
this.asyncBuffer.registerObserver(this);
|
|
12
|
-
}
|
|
13
|
-
// Update functions
|
|
14
|
-
AsyncInformant.prototype.update = function () {
|
|
15
|
-
// DEBUG
|
|
16
|
-
console.log('Before update');
|
|
17
|
-
this.printAllInfos();
|
|
18
|
-
this.updateRound();
|
|
19
|
-
this.updateNumberOfParticipants();
|
|
20
|
-
// DEBUG
|
|
21
|
-
console.log('After update');
|
|
22
|
-
this.printAllInfos();
|
|
23
|
-
};
|
|
24
|
-
AsyncInformant.prototype.updateRound = function () {
|
|
25
|
-
this.round = this.asyncBuffer.round;
|
|
26
|
-
};
|
|
27
|
-
AsyncInformant.prototype.updateNumberOfParticipants = function () {
|
|
28
|
-
this.currentNumberOfParticipants = this.asyncBuffer.buffer.size;
|
|
29
|
-
this.updateTotalNumberOfParticipants(this.currentNumberOfParticipants);
|
|
30
|
-
this.updateAverageNumberOfParticipants();
|
|
31
|
-
};
|
|
32
|
-
AsyncInformant.prototype.updateAverageNumberOfParticipants = function () {
|
|
33
|
-
this.averageNumberOfParticipants = this.totalNumberOfParticipants / this.round;
|
|
34
|
-
};
|
|
35
|
-
AsyncInformant.prototype.updateTotalNumberOfParticipants = function (currentNumberOfParticipants) {
|
|
36
|
-
this.totalNumberOfParticipants += currentNumberOfParticipants;
|
|
37
|
-
};
|
|
38
|
-
// Getter functions
|
|
39
|
-
AsyncInformant.prototype.getCurrentRound = function () {
|
|
40
|
-
return this.round;
|
|
41
|
-
};
|
|
42
|
-
AsyncInformant.prototype.getNumberOfParticipants = function () {
|
|
43
|
-
return this.currentNumberOfParticipants;
|
|
44
|
-
};
|
|
45
|
-
AsyncInformant.prototype.getTotalNumberOfParticipants = function () {
|
|
46
|
-
return this.totalNumberOfParticipants;
|
|
47
|
-
};
|
|
48
|
-
AsyncInformant.prototype.getAverageNumberOfParticipants = function () {
|
|
49
|
-
return this.averageNumberOfParticipants;
|
|
50
|
-
};
|
|
51
|
-
AsyncInformant.prototype.getAllStatistics = function () {
|
|
52
|
-
return {
|
|
53
|
-
round: this.getCurrentRound(),
|
|
54
|
-
currentNumberOfParticipants: this.getNumberOfParticipants(),
|
|
55
|
-
totalNumberOfParticipants: this.getTotalNumberOfParticipants(),
|
|
56
|
-
averageNumberOfParticipants: this.getAverageNumberOfParticipants()
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
// Debug
|
|
60
|
-
AsyncInformant.prototype.printAllInfos = function () {
|
|
61
|
-
console.log('task : ', this.asyncBuffer.taskID);
|
|
62
|
-
console.log('round : ', this.getCurrentRound());
|
|
63
|
-
console.log('participants : ', this.getNumberOfParticipants());
|
|
64
|
-
console.log('total : ', this.getTotalNumberOfParticipants());
|
|
65
|
-
console.log('average : ', this.getAverageNumberOfParticipants());
|
|
66
|
-
};
|
|
67
|
-
return AsyncInformant;
|
|
68
|
-
}());
|
|
69
|
-
exports.AsyncInformant = AsyncInformant;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { tf, WeightsContainer, Task, TrainingInformant } from '..';
|
|
2
|
-
export declare abstract class Base {
|
|
3
|
-
readonly url: URL;
|
|
4
|
-
readonly task: Task;
|
|
5
|
-
protected connected: boolean;
|
|
6
|
-
constructor(url: URL, task: Task);
|
|
7
|
-
/**
|
|
8
|
-
* Handles the connection process from the client to any sort of
|
|
9
|
-
* centralized server.
|
|
10
|
-
*/
|
|
11
|
-
abstract connect(): Promise<void>;
|
|
12
|
-
/**
|
|
13
|
-
* Handles the disconnection process of the client from any sort
|
|
14
|
-
* of centralized server.
|
|
15
|
-
*/
|
|
16
|
-
abstract disconnect(): Promise<void>;
|
|
17
|
-
getLatestModel(): Promise<tf.LayersModel>;
|
|
18
|
-
/**
|
|
19
|
-
* The training manager matches this function with the training loop's
|
|
20
|
-
* onTrainEnd callback when training a TFJS model object. See the
|
|
21
|
-
* training manager for more details.
|
|
22
|
-
*/
|
|
23
|
-
abstract onTrainEndCommunication(weights: WeightsContainer, trainingInformant: TrainingInformant): Promise<void>;
|
|
24
|
-
/**
|
|
25
|
-
* This function will be called whenever a local round has ended.
|
|
26
|
-
*
|
|
27
|
-
* @param updatedWeights
|
|
28
|
-
* @param staleWeights
|
|
29
|
-
* @param round
|
|
30
|
-
* @param trainingInformant
|
|
31
|
-
*/
|
|
32
|
-
abstract onRoundEndCommunication(updatedWeights: WeightsContainer, staleWeights: WeightsContainer, round: number, trainingInformant: TrainingInformant): Promise<WeightsContainer>;
|
|
33
|
-
}
|
package/dist/core/client/base.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Base = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var axios_1 = (0, tslib_1.__importDefault)(require("axios"));
|
|
6
|
-
var __1 = require("..");
|
|
7
|
-
var Base = /** @class */ (function () {
|
|
8
|
-
function Base(url, task) {
|
|
9
|
-
this.url = url;
|
|
10
|
-
this.task = task;
|
|
11
|
-
this.connected = false;
|
|
12
|
-
}
|
|
13
|
-
Base.prototype.getLatestModel = function () {
|
|
14
|
-
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
15
|
-
var url, response;
|
|
16
|
-
return (0, tslib_1.__generator)(this, function (_a) {
|
|
17
|
-
switch (_a.label) {
|
|
18
|
-
case 0:
|
|
19
|
-
url = new URL('', this.url.href);
|
|
20
|
-
if (!url.pathname.endsWith('/')) {
|
|
21
|
-
url.pathname += '/';
|
|
22
|
-
}
|
|
23
|
-
url.pathname += "tasks/" + this.task.taskID + "/model.json";
|
|
24
|
-
return [4 /*yield*/, axios_1.default.get(url.href)];
|
|
25
|
-
case 1:
|
|
26
|
-
response = _a.sent();
|
|
27
|
-
return [4 /*yield*/, __1.serialization.model.decode(response.data)];
|
|
28
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
return Base;
|
|
34
|
-
}());
|
|
35
|
-
exports.Base = Base;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { List, Map } from 'immutable';
|
|
2
|
-
import { TrainingInformant, WeightsContainer, Task } from '../..';
|
|
3
|
-
import { Base as ClientBase } from '../base';
|
|
4
|
-
import { PeerID } from './types';
|
|
5
|
-
import * as messages from './messages';
|
|
6
|
-
import { PeerConnection } from '../event_connection';
|
|
7
|
-
/**
|
|
8
|
-
* Abstract class for decentralized clients, executes onRoundEndCommunication as well as connecting
|
|
9
|
-
* to the signaling server
|
|
10
|
-
*/
|
|
11
|
-
export declare abstract class Base extends ClientBase {
|
|
12
|
-
readonly url: URL;
|
|
13
|
-
readonly task: Task;
|
|
14
|
-
protected readonly minimumReadyPeers: number;
|
|
15
|
-
private server?;
|
|
16
|
-
private peers?;
|
|
17
|
-
private ID?;
|
|
18
|
-
private pool?;
|
|
19
|
-
constructor(url: URL, task: Task);
|
|
20
|
-
private waitForPeers;
|
|
21
|
-
protected sendMessagetoPeer(peer: PeerConnection, msg: messages.PeerMessage): void;
|
|
22
|
-
private connectServer;
|
|
23
|
-
/**
|
|
24
|
-
* Initialize the connection to the peers and to the other nodes.
|
|
25
|
-
*/
|
|
26
|
-
connect(): Promise<void>;
|
|
27
|
-
disconnect(): Promise<void>;
|
|
28
|
-
onTrainEndCommunication(_: WeightsContainer, trainingInformant: TrainingInformant): Promise<void>;
|
|
29
|
-
onRoundEndCommunication(updatedWeights: WeightsContainer, staleWeights: WeightsContainer, round: number, trainingInformant: TrainingInformant): Promise<WeightsContainer>;
|
|
30
|
-
abstract sendAndReceiveWeights(peers: Map<PeerID, PeerConnection>, noisyWeights: WeightsContainer, round: number, trainingInformant: TrainingInformant): Promise<List<WeightsContainer>>;
|
|
31
|
-
abstract clientHandle(peers: Map<PeerID, PeerConnection>): void;
|
|
32
|
-
}
|