Skip to content

Commit

Permalink
*: upgrade to ES2022 modules
Browse files Browse the repository at this point in the history
  • Loading branch information
tharvik committed Mar 20, 2024
1 parent 355c271 commit d6406da
Show file tree
Hide file tree
Showing 154 changed files with 477 additions and 517 deletions.
1 change: 1 addition & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@epfml/disco-cli",
"private": true,
"type": "module",
"main": "dist/cli.js",
"scripts": {
"watch": "nodemon --ext ts --ignore dist --watch ../discojs/discojs-node/dist --watch ../server/dist --watch . --exec npm run",
Expand Down
1 change: 1 addition & 0 deletions cli/src/args.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { parse } from 'ts-command-line-args'
import { Map } from 'immutable'

import type { Task } from '@epfml/discojs-core'
import { defaultTasks } from '@epfml/discojs-core'

Expand Down
6 changes: 3 additions & 3 deletions cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { TrainerLog, data, Task } from '@epfml/discojs-core'
import { Disco, aggregator as aggregators, client as clients } from '@epfml/discojs-core'
import { startServer } from '@epfml/disco-server'

import { saveLog } from './utils'
import { getTaskData } from './data'
import { args } from './args'
import { saveLog } from './utils.js'
import { getTaskData } from './data.js'
import { args } from './args.js'

async function runUser (task: Task, url: URL, data: data.DataSplit): Promise<TrainerLog> {
const client = new clients.federated.FederatedClient(url, task, new aggregators.MeanAggregator())
Expand Down
1 change: 0 additions & 1 deletion cli/src/index.ts

This file was deleted.

18 changes: 2 additions & 16 deletions cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
{
"compilerOptions": {
"target": "ES5",
"lib": ["ES5"],

"strict": true,

"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "node",
"downlevelIteration": true, // needed by <ES6

"declaration": true,

"baseUrl": "src",
"outDir": "dist",
},
"extends": "../tsconfig.base.json",
"compilerOptions": { "outDir": "dist" },
"include": ["src"],
}
1 change: 1 addition & 0 deletions discojs/discojs-core/.mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"spec": ["src"],
"recursive": true,
"extension": ["ts"],
"loader": "ts-node/esm",
"require": "ts-node/register"
}
1 change: 1 addition & 0 deletions discojs/discojs-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@epfml/discojs-core",
"version": "2.1.1",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions discojs/discojs-core/src/aggregator/base.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Map, Set } from 'immutable'

import type { client, Model, AsyncInformant } from '..'
import type { client, Model, AsyncInformant } from '../index.js'

import { EventEmitter } from '../utils/event_emitter'
import { EventEmitter } from '../utils/event_emitter.js'

export enum AggregationStep {
ADD,
Expand Down
3 changes: 2 additions & 1 deletion discojs/discojs-core/src/aggregator/get.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { aggregator, type Task } from '..'
import type { Task } from '../index.js'
import { aggregator } from '../index.js'

/**
* Enumeration of the available types of aggregator.
Expand Down
14 changes: 7 additions & 7 deletions discojs/discojs-core/src/aggregator/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { WeightsContainer } from '../weights'
import type { Base } from './base'
import type { WeightsContainer } from '../weights/index.js'
import type { Base } from './base.js'

export { Base as AggregatorBase, AggregationStep } from './base'
export { MeanAggregator } from './mean'
export { RobustAggregator } from './robust'
export { SecureAggregator } from './secure'
export { Base as AggregatorBase, AggregationStep } from './base.js'
export { MeanAggregator } from './mean.js'
export { RobustAggregator } from './robust.js'
export { SecureAggregator } from './secure.js'

export { getAggregator, AggregatorChoice } from './get'
export { getAggregator, AggregatorChoice } from './get.js'

export type Aggregator = Base<WeightsContainer>
6 changes: 3 additions & 3 deletions discojs/discojs-core/src/aggregator/mean.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { assert, expect } from 'chai'
import type { Map } from 'immutable'

import type { client, Model } from '..'
import { aggregator, defaultTasks } from '..'
import { AggregationStep } from './base'
import type { client, Model } from '../index.js'
import { aggregator, defaultTasks } from '../index.js'
import { AggregationStep } from './base.js'

const model = defaultTasks.titanic.getModel()
const id = 'a'
Expand Down
6 changes: 3 additions & 3 deletions discojs/discojs-core/src/aggregator/mean.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Map } from 'immutable'

import { AggregationStep, Base as Aggregator } from './base'
import type { Model, WeightsContainer, client } from '..'
import { aggregation } from '..'
import { AggregationStep, Base as Aggregator } from './base.js'
import type { Model, WeightsContainer, client } from '../index.js'
import { aggregation } from '../index.js'

/**
* Mean aggregator whose aggregation step consists in computing the mean of the received weights.
Expand Down
4 changes: 2 additions & 2 deletions discojs/discojs-core/src/aggregator/robust.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Base as Aggregator } from './base'
import type { client, Model, WeightsContainer } from '..'
import { Base as Aggregator } from './base.js'
import type { client, Model, WeightsContainer } from '../index.js'

import type { Map } from 'immutable'

Expand Down
2 changes: 1 addition & 1 deletion discojs/discojs-core/src/aggregator/secure.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { List, Set, Range } from 'immutable'
import { assert } from 'chai'

import { aggregator as aggregators, aggregation, WeightsContainer } from '@epfml/discojs-core'
import { aggregator as aggregators, aggregation, WeightsContainer } from '../index.js'

describe('secret shares test', function () {
const epsilon = 1e-4
Expand Down
17 changes: 9 additions & 8 deletions discojs/discojs-core/src/aggregator/secure.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as crypto from 'crypto'
import { Map, List, Range } from 'immutable'
import tf from '@tensorflow/tfjs'
import * as tf from '@tensorflow/tfjs'

import { AggregationStep, Base as Aggregator } from './base'
import type { Model, WeightsContainer, client } from '..'
import { aggregation } from '..'
import { AggregationStep, Base as Aggregator } from './base.js'
import type { Model, WeightsContainer, client } from '../index.js'
import { aggregation } from '../index.js'

/**
* Aggregator implementing secure multi-party computation for decentralized learning.
Expand All @@ -14,8 +13,6 @@ import { aggregation } from '..'
* Finally, nodes are able to average the received partial sums to establish the aggregation result.
*/
export class SecureAggregator extends Aggregator<WeightsContainer> {
public static readonly MAX_SEED: number = 2 ** 47

constructor (
model?: Model,
private readonly maxShareValue = 100
Expand Down Expand Up @@ -93,7 +90,11 @@ export class SecureAggregator extends Aggregator<WeightsContainer> {
* a uniform distribution between (-maxShareValue, maxShareValue).
*/
public generateRandomShare (secret: WeightsContainer): WeightsContainer {
const seed = crypto.randomInt(SecureAggregator.MAX_SEED)
const MAX_SEED_BITS = 47

const random = crypto.getRandomValues(new BigInt64Array(1))[0]
const seed = Number(BigInt.asUintN(MAX_SEED_BITS, random))

return secret.map((t) =>
tf.randomUniform(t.shape, -this.maxShareValue, this.maxShareValue, 'float32', seed))
}
Expand Down
2 changes: 1 addition & 1 deletion discojs/discojs-core/src/async_informant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AggregatorBase } from './aggregator'
import type { AggregatorBase } from './aggregator/index.js'

export class AsyncInformant<T> {
private _round = 0
Expand Down
10 changes: 5 additions & 5 deletions discojs/discojs-core/src/client/base.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import axios from 'axios'
import type { Set } from 'immutable'

import type { Model, Task, TrainingInformant, WeightsContainer } from '..'
import { serialization } from '..'
import type { NodeID } from './types'
import type { EventConnection } from './event_connection'
import type { Aggregator } from '../aggregator'
import type { Model, Task, TrainingInformant, WeightsContainer } from '../index.js'
import { serialization } from '../index.js'
import type { NodeID } from './types.js'
import type { EventConnection } from './event_connection.js'
import type { Aggregator } from '../aggregator/index.js'

/**
* Main, abstract, class representing a Disco client in a network, which handles
Expand Down
14 changes: 7 additions & 7 deletions discojs/discojs-core/src/client/decentralized/base.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Map, Set } from 'immutable'

import { type TrainingInformant, type WeightsContainer, serialization } from '../..'
import { Client, type NodeID } from '..'
import { type, type ClientConnected } from '../messages'
import { timeout } from '../utils'
import { type EventConnection, WebSocketServer, waitMessage, type PeerConnection, waitMessageWithTimeout } from '../event_connection'
import { PeerPool } from './peer_pool'
import * as messages from './messages'
import { type TrainingInformant, type WeightsContainer, serialization } from '../../index.js'
import { Client, type NodeID } from '../index.js'
import { type, type ClientConnected } from '../messages.js'
import { timeout } from '../utils.js'
import { type EventConnection, WebSocketServer, waitMessage, type PeerConnection, waitMessageWithTimeout } from '../event_connection.js'
import { PeerPool } from './peer_pool.js'
import * as messages from './messages.js'

/**
* Represents a decentralized client in a network of peers. Peers coordinate each other with the
Expand Down
4 changes: 2 additions & 2 deletions discojs/discojs-core/src/client/decentralized/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { Base as DecentralizedClient } from './base'
export * as messages from './messages'
export { Base as DecentralizedClient } from './base.js'
export * as messages from './messages.js'
8 changes: 4 additions & 4 deletions discojs/discojs-core/src/client/decentralized/messages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { weights } from '../../serialization'
import { type SignalData } from './peer'
import { isNodeID, type NodeID } from '../types'
import { type, type ClientConnected, type AssignNodeID, hasMessageType } from '../messages'
import { weights } from '../../serialization/index.js'
import { type SignalData } from './peer.js'
import { isNodeID, type NodeID } from '../types.js'
import { type, type ClientConnected, type AssignNodeID, hasMessageType } from '../messages.js'

/// Phase 0 communication (between server and peers)

Expand Down
2 changes: 1 addition & 1 deletion discojs/discojs-core/src/client/decentralized/peer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert } from 'chai'
import { List, Range, Set } from 'immutable'

import { Peer } from './peer'
import { Peer } from './peer.js'

describe('peer', function () {
let peer1: Peer
Expand Down
8 changes: 5 additions & 3 deletions discojs/discojs-core/src/client/decentralized/peer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { type NodeID } from '../types'

import { List, Map, Range, Seq } from 'immutable'
import wrtc from 'isomorphic-wrtc'
import SimplePeer from 'simple-peer'

import type { NodeID } from '../types.js'

type MessageID = number
type ChunkID = number

Expand All @@ -19,7 +19,9 @@ const TICK = 10
// we can't use the definition in DOM as we're platform independent
export type SignalData =
| { type: 'answer' | 'offer' | 'pranswer' | 'rollback', sdp?: string }
| { type: 'transceiverRequest' | 'renegotiate' | 'candidate' }
| { type: 'transceiverRequest', transceiverRequest: { kind: string } }
| { type: 'renegotiate', renegotiate: true }
| { type: 'candidate', candidate: RTCIceCandidate }

interface Events {
'close': () => void
Expand Down
10 changes: 5 additions & 5 deletions discojs/discojs-core/src/client/decentralized/peer_pool.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { assert } from 'chai'
import { Map, Range } from 'immutable'
import { type messages } from '.'
import { type } from '../messages'
import { type PeerConnection, type EventConnection } from '../event_connection'
import type { messages } from './index.js'
import { type } from '../messages.js'
import type { PeerConnection, EventConnection } from '../event_connection.js'

import { PeerPool } from './peer_pool'
import { type NodeID } from '../types'
import { PeerPool } from './peer_pool.js'
import type { NodeID } from '../types.js'

describe('peer pool', function () {
this.timeout(10_000)
Expand Down
6 changes: 3 additions & 3 deletions discojs/discojs-core/src/client/decentralized/peer_pool.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Map, type Set } from 'immutable'

import { Peer, type SignalData } from './peer'
import { type NodeID } from '../types'
import { PeerConnection, type EventConnection } from '../event_connection'
import { Peer, type SignalData } from './peer.js'
import { type NodeID } from '../types.js'
import { PeerConnection, type EventConnection } from '../event_connection.js'

// TODO cleanup old peers

Expand Down
12 changes: 6 additions & 6 deletions discojs/discojs-core/src/client/event_connection.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import isomorphic from 'isomorphic-ws'
import type { Peer, SignalData } from './decentralized/peer'
import { type NodeID } from './types'
import type { Peer, SignalData } from './decentralized/peer.js'
import { type NodeID } from './types.js'
import msgpack from 'msgpack-lite'
import * as decentralizedMessages from './decentralized/messages'
import { type, type NarrowMessage, type Message } from './messages'
import { timeout } from './utils'
import * as decentralizedMessages from './decentralized/messages.js'
import { type, type NarrowMessage, type Message } from './messages.js'
import { timeout } from './utils.js'

import { EventEmitter } from '../utils/event_emitter'
import { EventEmitter } from '../utils/event_emitter.js'

export interface EventConnection {
on: <K extends type>(type: K, handler: (event: NarrowMessage<K>) => void) => void
Expand Down
12 changes: 6 additions & 6 deletions discojs/discojs-core/src/client/federated/base.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Map } from 'immutable'

import { serialization, type informant, type MetadataKey, type MetadataValue, type WeightsContainer, type TrainingInformant } from '../..'
import { type NodeID } from '../types'
import { Base as Client } from '../base'
import { type, type ClientConnected } from '../messages'
import { type EventConnection, waitMessageWithTimeout, WebSocketServer } from '../event_connection'
import * as messages from './messages'
import { serialization, type informant, type MetadataKey, type MetadataValue, type WeightsContainer, type TrainingInformant } from '../../index.js'
import { type NodeID } from '../types.js'
import { Base as Client } from '../base.js'
import { type, type ClientConnected } from '../messages.js'
import { type EventConnection, waitMessageWithTimeout, WebSocketServer } from '../event_connection.js'
import * as messages from './messages.js'

/**
* Client class that communicates with a centralized, federated server, when training
Expand Down
4 changes: 2 additions & 2 deletions discojs/discojs-core/src/client/federated/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { Base as FederatedClient } from './base'
export * as messages from './messages'
export { Base as FederatedClient } from './base.js'
export * as messages from './messages.js'
6 changes: 3 additions & 3 deletions discojs/discojs-core/src/client/federated/messages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type client, type MetadataKey, type MetadataValue } from '../..'
import { type weights } from '../../serialization'
import { type client, type MetadataKey, type MetadataValue } from '../../index.js'
import { type weights } from '../../serialization/index.js'

import { type, hasMessageType, type AssignNodeID, type ClientConnected } from '../messages'
import { type, hasMessageType, type AssignNodeID, type ClientConnected } from '../messages.js'

export type MessageFederated =
ClientConnected |
Expand Down
16 changes: 8 additions & 8 deletions discojs/discojs-core/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export { Base as Client } from './base'
export { Base as Client } from './base.js'

export * from './types'
export * from './types.js'

export * as aggregator from '../aggregator'
export * as decentralized from './decentralized'
export * as federated from './federated'
export * as messages from './messages'
export * as utils from './utils'
export * as aggregator from '../aggregator/index.js'
export * as decentralized from './decentralized/index.js'
export * as federated from './federated/index.js'
export * as messages from './messages.js'
export * as utils from './utils.js'

export { Local } from './local'
export { Local } from './local.js'
2 changes: 1 addition & 1 deletion discojs/discojs-core/src/client/local.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Base } from './base'
import { Base } from './base.js'

export class Local extends Base {}
6 changes: 3 additions & 3 deletions discojs/discojs-core/src/client/messages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as decentralized from './decentralized/messages'
import type * as federated from './federated/messages'
import { type NodeID } from './types'
import type * as decentralized from './decentralized/messages.js'
import type * as federated from './federated/messages.js'
import { type NodeID } from './types.js'

export enum type {
ClientConnected,
Expand Down
Loading

0 comments on commit d6406da

Please sign in to comment.