Skip to content

Commit 853d339

Browse files
committed
Set noImplicitAny in tsconfig
1 parent 3171c58 commit 853d339

9 files changed

+26
-24
lines changed

lib/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ export namespace core {
349349

350350
// Memory management.
351351
function tidy<U>(func: () => U): U;
352-
function dispose(tree: unknown);
352+
function dispose(tree: unknown): void;
353353
function getWrappersCount(): number;
354354

355355
// Metal.

lib/nn/layers/base.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export abstract class Module {
341341
* @returns The module instance after updating the parameters.
342342
*/
343343
update(parameters: NestedDict<mx.array>): this {
344-
const apply = (target: object, parameters: NestedDict<mx.array>) => {
344+
const apply = (target: Record<string, any>, parameters: NestedDict<mx.array>) => {
345345
if (typeof parameters !== 'object')
346346
return;
347347
for (let k in parameters) {
@@ -400,7 +400,7 @@ export abstract class Module {
400400
* @returns The module instance after updating the submodules.
401401
*/
402402
updateModules(modules: NestedDict<Module>): this {
403-
const apply = (target: object, modules: object) => {
403+
const apply = (target: Record<string, any>, modules: Record<string, any>) => {
404404
if (typeof modules !== 'object')
405405
return;
406406
for (let k in modules) {
@@ -602,7 +602,7 @@ export abstract class Module {
602602
}
603603

604604
// Helpers.
605-
function defaultIsLeafFn(m, k, v) {
605+
function defaultIsLeafFn(m: Module, k: string, v: unknown) {
606606
if (typeof v !== 'object')
607607
return true;
608608
return !Array.isArray(v) && !isDict(v);
@@ -643,9 +643,10 @@ function unwrap(model: Module,
643643
if (typeof value === 'object') {
644644
const newValue: Record<string, unknown> = {};
645645
for (let k in value) {
646-
let key = `${valueKey}.${k}`;
647-
if (filterFn(model, key, value[k])) {
648-
newValue[k] = unwrap(model, key, value[k], filterFn, mapFn, isLeafFn);
646+
const key = `${valueKey}.${k}`;
647+
const v = value[k as keyof typeof value];
648+
if (filterFn(model, key, v)) {
649+
newValue[k] = unwrap(model, key, v, filterFn, mapFn, isLeafFn);
649650
} else {
650651
newValue[k] = {};
651652
}

lib/nn/layers/normalization.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export class BatchNorm extends Module {
322322
}
323323
}
324324

325-
override unfreeze(...args): this {
325+
override unfreeze(...args: any[]): this {
326326
super.unfreeze(...args);
327327
this.freeze(false, ['runningMean', 'runningVar']);
328328
return this;

lib/nn/layers/positional-encoding.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,20 @@ export class ALiBi extends Module {
137137
return ALiBi.mask;
138138
}
139139

140-
static createAlibiSlope(numHeads): mx.array {
140+
static createAlibiSlope(numHeads: number): mx.array {
141141
const x = Math.pow(Math.pow(2, 8), 1 / numHeads);
142142
const out = mx.power(x, mx.negative(mx.arange(1, numHeads + 1)));
143143
return mx.expandDims(out, [-1, -2]);
144144
}
145145

146-
forward(attentionScores: mx.array, offset = 0, mask = null): mx.array {
146+
forward(attentionScores: mx.array, offset = 0, mask?: mx.array): mx.array {
147147
let alibiMask = ALiBi.createAlibiMatrix(
148148
attentionScores.shape[attentionScores.shape.length - 2] + offset,
149149
attentionScores.shape[attentionScores.shape.length - 1],
150150
attentionScores.shape[1],
151151
offset,
152152
attentionScores.dtype);
153-
if (mask !== null) {
153+
if (mask) {
154154
alibiMask = mx.add(alibiMask, mask);
155155
}
156156
return mx.add(attentionScores, alibiMask);

lib/nn/layers/quantized.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export class QuantizedLinear extends Module {
211211

212212
// Wrap unfreeze so that we unfreeze any layers we might contain but
213213
// our parameters will remain frozen.
214-
override unfreeze(...args): this {
214+
override unfreeze(...args: any[]): this {
215215
super.unfreeze(...args);
216216
return this.freeze(false);
217217
}

lib/nn/layers/upsample.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export function upsampleNearest(x: mx.array,
216216

217217
function interpolate(x: mx.array,
218218
scaleFactor: number[],
219-
indicesFn,
219+
indicesFn: (N: number, scale: number, alignCorners: boolean, dim: number, ndims: number) => [mx.array, mx.array][],
220220
alignCorners = false): mx.array {
221221
const dims = x.ndim - 2;
222222
if (dims !== scaleFactor.length) {

lib/optimizers/optimizers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export abstract class Optimizer {
5454
*/
5555
init(parameters: Nested<mx.array>): void {
5656
// Iniatilize the optimizer state to match the parameter state.
57-
function updateState(params: Nested<mx.array>, state: Nested<unknown>) {
57+
function updateState(params: Nested<mx.array>, state: Record<string, any>) {
5858
if (Array.isArray(params) && Array.isArray(state)) {
5959
for (let i = 0; i < state.length; ++i)
6060
state[i] = updateState(params[i], state[i]);

lib/utils.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
* @returns An Object with the new values returned by `fn`.
3333
*/
3434
export function treeMap(func: (...args: any[]) => unknown,
35-
tree: unknown,
36-
rest?: object[],
35+
tree: Record<string, any>,
36+
rest?: Record<string, any>[],
3737
isLeaf?: (node: unknown) => boolean): unknown {
3838
if (isLeaf && isLeaf(tree)) {
3939
if (rest)
@@ -43,7 +43,7 @@ export function treeMap(func: (...args: any[]) => unknown,
4343
} else if (Array.isArray(tree)) {
4444
return tree.map((child, i) => treeMap(func, child, rest?.map(r => r[i]), isLeaf));
4545
} else if (typeof tree === 'object' && isDict(tree)) {
46-
const newTree = {};
46+
const newTree: Record<string, any> = {};
4747
for (const k in tree) {
4848
newTree[k] = treeMap(func, tree[k], rest?.map(r => r[k]), isLeaf);
4949
}
@@ -84,8 +84,8 @@ export function treeMap(func: (...args: any[]) => unknown,
8484
* ```
8585
*/
8686
export function treeMapWithPath(fn: (path?: string, ...args: unknown[]) => unknown,
87-
tree: unknown,
88-
rest?: object[],
87+
tree: Record<string, any>,
88+
rest?: Record<string, any>[],
8989
isLeaf?: (node: unknown) => boolean,
9090
path?: string): unknown {
9191
if (isLeaf && isLeaf(tree)) {
@@ -96,7 +96,7 @@ export function treeMapWithPath(fn: (path?: string, ...args: unknown[]) => unkno
9696
} else if (Array.isArray(tree)) {
9797
return tree.map((child, i) => treeMapWithPath(fn, child, rest?.map(r => r[i]), isLeaf, path ? `${path}.${i}` : `${i}`));
9898
} else if (typeof tree === 'object' && isDict(tree)) {
99-
const newTree = {};
99+
const newTree: Record<string, any> = {};
100100
for (const k in tree) {
101101
newTree[k] = treeMapWithPath(fn, tree[k], rest?.map(r => r[k]), isLeaf, path ? `${path}.${k}` : `${k}`);
102102
}
@@ -138,7 +138,7 @@ export function treeMapWithPath(fn: (path?: string, ...args: unknown[]) => unkno
138138
* // Outputs: [['hello.0.0.0', 0]]
139139
* ```
140140
*/
141-
export function treeFlatten(tree: unknown,
141+
export function treeFlatten(tree: Record<string, any>,
142142
prefix: string = '',
143143
isLeaf?: (node: unknown) => boolean,
144144
convertKey?: (key: string) => string): [string, unknown][] {
@@ -199,12 +199,12 @@ export function treeUnflatten(tree: [string, unknown][],
199199
// Recursively map them to the original container.
200200
if (isList) {
201201
const keys = Object.keys(children).sort().map((idx) => [ parseInt(idx), idx ]);
202-
const newList = [];
202+
const newList: any[] = [];
203203
for (const [i, k] of keys)
204-
newList[i] = treeUnflatten(children[k], convertKey);
204+
newList[i as number] = treeUnflatten(children[k], convertKey);
205205
return newList;
206206
} else {
207-
const newTree = {};
207+
const newTree: Record<string, any> = {};
208208
for (let k in children) {
209209
const key = convertKey ? convertKey(k) : k;
210210
newTree[key] = treeUnflatten(children[k], convertKey);

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"outDir": "dist",
44
"rootDir": "lib",
55
"noImplicitOverride": true,
6+
"noImplicitAny": true,
67
"module": "commonjs",
78
"esModuleInterop": true,
89
"target": "es2022",

0 commit comments

Comments
 (0)