Skip to content

Commit

Permalink
TMP eslint 2022
Browse files Browse the repository at this point in the history
  • Loading branch information
tharvik committed Mar 20, 2024
1 parent d6406da commit 94be14d
Show file tree
Hide file tree
Showing 32 changed files with 386 additions and 140 deletions.
14 changes: 0 additions & 14 deletions .eslintrc.js

This file was deleted.

5 changes: 0 additions & 5 deletions cli/.eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"watch": "nodemon --ext ts --ignore dist --watch ../discojs/discojs-node/dist --watch ../server/dist --watch . --exec npm run",
"start": "npm run build && node dist/cli.js",
"build": "tsc",
"lint": "npx eslint --ext ts --max-warnings 0 .",
"lint": "npx eslint .",
"test": ": nothing"
},
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion discojs/discojs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"watch": "nodemon --ext ts --ignore dist --exec npm run",
"build": "tsc",
"lint": "npx eslint --ext ts --max-warnings 0 .",
"lint": "npx eslint .",
"test": "mocha",
"docs": "typedoc ./src/index.ts --theme oxide"
},
Expand Down
4 changes: 2 additions & 2 deletions discojs/discojs-core/src/models/gpt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ export class GPT extends Model {
}
}

override async predict (input: Sample): Promise<Prediction> {
override predict (input: Sample): Promise<Prediction> {
const ret = this.model.predict(input)
if (Array.isArray(ret)) {
throw new Error('prediction yield many Tensors but should have only returned one')
}

return ret
return Promise.resolve(ret)
}

static deserialize (weights: WeightsContainer): Model {
Expand Down
2 changes: 1 addition & 1 deletion discojs/discojs-core/src/models/gpt/train.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function getCustomAdam (model: tf.LayersModel, c: Required<GPTConfig>): tf.Optim
const excludeFromWeightDecay: string[] = []

// TODO unsafe cast
const namedWeights = (model as unknown as any).getNamedWeights() as Array<{ name: string, tensor: tf.Tensor }>
const namedWeights = (model as unknown as Record<'getNamedWeights', () => Array<{ name: string, tensor: tf.Tensor }>>).getNamedWeights()

namedWeights.forEach((v) => {
if (
Expand Down
12 changes: 6 additions & 6 deletions discojs/discojs-core/src/models/tfjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ export class TFJS extends Model {
}
}

override async predict (input: Sample): Promise<Prediction> {
override predict (input: Sample): Promise<Prediction> {
const ret = this.model.predict(input)
if (Array.isArray(ret)) {
throw new Error('prediction yield many Tensors but should have only returned one')
}

return ret
return Promise.resolve(ret)
}

static async deserialize (raw: tf.io.ModelArtifacts): Promise<Model> {
return new this(await tf.loadLayersModel({
load: async () => raw
load: () => Promise.resolve(raw)
}))
}

Expand All @@ -71,14 +71,14 @@ export class TFJS extends Model {
const ret = new Promise<tf.io.ModelArtifacts>((resolve) => { resolveArtifacts = resolve })

await this.model.save({
save: async (artifacts) => {
save: (artifacts) => {
resolveArtifacts(artifacts)
return {
return Promise.resolve({
modelArtifactsInfo: {
dateSaved: new Date(),
modelTopologyType: 'JSON'
}
}
})
}
}, {
includeOptimizer: true // keep model compiled
Expand Down
9 changes: 7 additions & 2 deletions discojs/discojs-core/src/serialization/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import type tf from '@tensorflow/tfjs'
import type { Model } from '../index.js'
import { models, serialization } from '../index.js'

const enum Type { TFJS, GPT }
const Type = {
TFJS: 0,
GPT: 1
} as const

export type Encoded = Uint8Array

Expand Down Expand Up @@ -37,7 +40,7 @@ export async function decode (encoded: unknown): Promise<Model> {
}
const [type, rawModel] = raw as [unknown, unknown]

if (typeof type !== 'number' || (type !== Type.TFJS && type !== Type.GPT)) {
if (typeof type !== 'number') {
throw new Error('invalid encoding')
}
switch (type) {
Expand All @@ -57,5 +60,7 @@ export async function decode (encoded: unknown): Promise<Model> {
const serialized = serialization.weights.decode(nums)
return models.GPT.deserialize(serialized)
}
default:
throw new Error('invalid encoding')
}
}
3 changes: 1 addition & 2 deletions discojs/discojs-core/src/serialization/weights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function isSerialized (raw: unknown): raw is Serialized {
return false
}

// eslint-disable-next-line
const _: Serialized = {shape, data}

return true
Expand All @@ -48,7 +47,7 @@ export async function encode (weights: WeightsContainer): Promise<Encoded> {
}

export function decode (encoded: Encoded): WeightsContainer {
const raw = msgpack.decode(encoded)
const raw: unknown = msgpack.decode(encoded)

if (!(Array.isArray(raw) && raw.every(isSerialized))) {
throw new Error('expected to decode an array of serialized weights')
Expand Down
2 changes: 1 addition & 1 deletion discojs/discojs-core/src/task/digest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function isDigest (raw: unknown): raw is Digest {
return false
}

const { algorithm, value }: Partial<Record<string, unknown>> = raw
const { algorithm, value }: Partial<Record<keyof Digest, unknown>> = raw

if (!(
typeof algorithm === 'string' &&
Expand Down
4 changes: 2 additions & 2 deletions discojs/discojs-core/src/task/training_information.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type AggregatorChoice } from '../aggregator/get.js'
import { type Preprocessing } from '../dataset/data/preprocessing/index.js'
import type { AggregatorChoice } from '../aggregator/get.js'
import type { Preprocessing } from '../dataset/data/preprocessing/index.js'

export interface TrainingInformation {
// modelID: unique ID for the model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export class DistributedTrainer extends Trainer {
await this.client.onTrainBeginCommunication(this.model.weights, this.trainingInformant)
}

async onRoundBegin (accuracy: number): Promise<void> {
async onRoundBegin (): Promise<void> {
await this.client.onRoundBeginCommunication(this.model.weights, this.roundTracker.round, this.trainingInformant)
}

/**
* Callback called every time a round is over
*/
async onRoundEnd (accuracy: number): Promise<void> {
async onRoundEnd (): Promise<void> {
await this.client.onRoundEndCommunication(this.model.weights, this.roundTracker.round, this.trainingInformant)
if (this.aggregator.model !== undefined) {
// The aggregator's own aggregation is async. The trainer updates its model to match the aggregator's
Expand Down
6 changes: 4 additions & 2 deletions discojs/discojs-core/src/training/trainer/local_trainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { Trainer } from './trainer.js'
* without any collaborators.
*/
export class LocalTrainer extends Trainer {
async onRoundBegin (accuracy: number): Promise<void> {}
async onRoundBegin (): Promise<void> {
return await Promise.resolve()
}

async onRoundEnd (accuracy: number): Promise<void> {
async onRoundEnd (): Promise<void> {
console.log('on round end')
await this.memory.updateWorkingModel(
{ taskID: this.task.id, name: this.task.trainingInformation.modelID },
Expand Down
9 changes: 6 additions & 3 deletions discojs/discojs-core/src/training/trainer/trainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export abstract class Trainer {
}
}

protected onEpochBegin (epoch: number, logs?: tf.Logs): void {}
// TODO never used
protected onEpochBegin (_epoch: number, _logs?: tf.Logs): void {}

/**
* We update the training graph, this needs to be done on epoch end as there is no validation accuracy onBatchEnd.
Expand All @@ -88,15 +89,17 @@ export abstract class Trainer {
}
}

protected async onTrainBegin (logs?: tf.Logs): Promise<void> {
protected async onTrainBegin (_logs?: tf.Logs): Promise<void> {
this.trainingInformant.addMessage('Training started.')
return await Promise.resolve()
}

/**
* When the training ends this function will be call
*/
protected async onTrainEnd (logs?: tf.Logs): Promise<void> {
protected async onTrainEnd (_logs?: tf.Logs): Promise<void> {
this.trainingInformant.addMessage('Training finished.')
return await Promise.resolve()
}

/**
Expand Down
4 changes: 2 additions & 2 deletions discojs/discojs-core/src/validation/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export class Validator {
[],
0
).arraySync()
} catch (e: any) {
console.error(e instanceof Error ? e.message : e.toString())
} catch (e) {
console.error(e instanceof Error ? e.message : e)
throw new Error('Failed to compute the confusion matrix')
}
}
Expand Down
6 changes: 3 additions & 3 deletions discojs/discojs-core/src/weights/aggregation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { assert } from 'chai'
import { WeightsContainer, aggregation } from './index.js'

describe('weights aggregation', () => {
it('avg of weights with two operands', async () => {
it('avg of weights with two operands', () => {
const actual = aggregation.avg([
WeightsContainer.of([1, 2, 3, -1], [-5, 6]),
WeightsContainer.of([2, 3, 7, 1], [-10, 5]),
Expand All @@ -14,7 +14,7 @@ describe('weights aggregation', () => {
assert.isTrue(actual.equals(expected))
})

it('sum of weights with two operands', async () => {
it('sum of weights with two operands', () => {
const actual = aggregation.sum([
[[3, -4], [9]],
[[2, 13], [0]]
Expand All @@ -24,7 +24,7 @@ describe('weights aggregation', () => {
assert.isTrue(actual.equals(expected))
})

it('diff of weights with two operands', async () => {
it('diff of weights with two operands', () => {
const actual = aggregation.diff([
[[3, -4, 5], [9, 1]],
[[2, 13, 4], [0, 1]]
Expand Down
5 changes: 0 additions & 5 deletions discojs/discojs-node/.eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion discojs/discojs-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"watch": "nodemon --ext ts --ignore dist --watch ../discojs-core/dist --watch . --exec npm run",
"build": "tsc",
"lint": "npx eslint --ext ts --max-warnings 0 .",
"lint": "npx eslint .",
"test": "mocha",
"docs": "typedoc ./src/imports.ts --theme oxide"
},
Expand Down
5 changes: 0 additions & 5 deletions discojs/discojs-web/.eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion discojs/discojs-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"watch": "nodemon --ext ts --ignore dist --watch ../discojs-core/dist --watch . --exec npm run",
"build": "tsc",
"lint": "npx eslint --ext ts --max-warnings 0 .",
"lint": "npx eslint .",
"test": ": nothing",
"docs": "typedoc ./src/index.ts --theme oxide"
},
Expand Down
18 changes: 0 additions & 18 deletions docs/examples/.eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions docs/examples/custom_task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const customTask: TaskProvider = {
}
},

async getModel () {
getModel () {
const model = tf.sequential()

model.add(
Expand All @@ -52,7 +52,7 @@ const customTask: TaskProvider = {
metrics: ['accuracy']
})

return new models.TFJS(model)
return Promise.resolve(new models.TFJS(model))
}
}

Expand Down
5 changes: 3 additions & 2 deletions eslint.config.js → docs/examples/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
files: ['*.ts'],
languageOptions: {
parserOptions: {
project: './tsconfig.eslint.json',
project: true,
tsconfigRootDir: import.meta.dirname
}
}
},
{ ignores: ['**/dist/*'] }
{ ignores: ['eslint.config.js', 'dist/*'] }
)
10 changes: 3 additions & 7 deletions docs/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"train": "npm run build && node dist/training.js",
"custom_task": "npm run build && node dist/custom_task.js",
"build": "tsc",
"lint": "npx eslint --ext ts --max-warnings 0 .",
"lint": "npx eslint .",
"test": "npm run train"
},
"license": "ISC",
Expand All @@ -17,12 +17,8 @@
"@epfml/discojs-node": "*"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "6",
"eslint": "8",
"eslint-config-standard-with-typescript": "43",
"eslint-plugin-import": "2",
"eslint-plugin-n": "15",
"eslint-plugin-promise": "6",
"typescript": "4"
"typescript": "4",
"typescript-eslint": "7"
}
}
2 changes: 1 addition & 1 deletion docs/examples/training.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function loadSimpleFaceData (task: Task): Promise<data.DataSplit> {

const filesPerFolder = [youngFiles, oldFiles]

const labels = filesPerFolder.flatMap((files, index) => Array(files.length).fill(index))
const labels = filesPerFolder.flatMap((files, index) => Array<string>(files.length).fill(`${index}`))
const files = filesPerFolder.flat()

return await new NodeImageLoader(task).loadAll(files, { labels })
Expand Down
4 changes: 0 additions & 4 deletions docs/examples/tsconfig.eslint.json

This file was deleted.

Loading

0 comments on commit 94be14d

Please sign in to comment.