Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions index.js

This file was deleted.

23 changes: 23 additions & 0 deletions lib/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// <reference path="../node_mlx.node.d.ts" preserve="true"/>
import core from '../build/Release/node_mlx.node';

// Helper for creating complex number.
core.Complex = (re, im) => {
return { re, im: im ?? 0 };
};

// Implementation of the StreamContext.
core.stream = function stream(s: core.StreamOrDevice): Disposable {
const old = core.defaultStream(core.defaultDevice());
const target = core.toStream(s);
core.setDefaultDevice(target.device);
core.setDefaultStream(target);
return {
[Symbol.dispose]() {
core.setDefaultDevice(old.device);
core.setDefaultStream(old);
},
};
};

export { core, core as mx };
4 changes: 4 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './core';
export * as nn from './nn';
export * as optimizers from './optimizers';
export * as utils from './utils';
16 changes: 1 addition & 15 deletions lib/nn/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
export * from './layers/activations';
export * from './layers/base';
export * from './layers/containers';
export * from './layers/convolution';
export * from './layers/convolution-transpose';
export * from './layers/dropout';
export * from './layers/embedding';
export * from './layers/linear';
export * from './layers/normalization';
export * from './layers/pooling';
export * from './layers/positional-encoding';
export * from './layers/quantized';
export * from './layers/recurrent';
export * from './layers/transformer';
export * from './layers/upsample';
export * from './layers';
export * from './utils';
export * as init from './init';
export * as losses from './losses';
2 changes: 1 addition & 1 deletion lib/nn/init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx} from '../..';
import {core as mx} from '../core';

/**
* An initializer that returns an array filled with `value`.
Expand Down
2 changes: 1 addition & 1 deletion lib/nn/layers/activations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx} from '../../..';
import {core as mx} from '../../core';
import {Module} from './base';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/nn/layers/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx} from '../../..';
import {core as mx} from '../../core';
import {
NestedDict,
deepEqual,
Expand Down
2 changes: 1 addition & 1 deletion lib/nn/layers/containers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx} from '../../..';
import {core as mx} from '../../core';
import {Module} from './base';

interface SequentialModule extends Module {
Expand Down
2 changes: 1 addition & 1 deletion lib/nn/layers/convolution-transpose.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx} from '../../..';
import {core as mx} from '../../core';
import {Module} from './base';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/nn/layers/convolution.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx} from '../../..';
import {core as mx} from '../../core';
import {Module} from './base';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/nn/layers/dropout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx, utils} from '../../..';
import {core as mx} from '../../core';
import {Module} from './base';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/nn/layers/embedding.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx} from '../../..';
import {core as mx} from '../../core';
import {Module} from './base';
import {QuantizedEmbedding} from './quantized';

Expand Down
15 changes: 15 additions & 0 deletions lib/nn/layers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export * from './activations';
export * from './base';
export * from './containers';
export * from './convolution';
export * from './convolution-transpose';
export * from './dropout';
export * from './embedding';
export * from './linear';
export * from './normalization';
export * from './pooling';
export * from './positional-encoding';
export * from './quantized';
export * from './recurrent';
export * from './transformer';
export * from './upsample';
2 changes: 1 addition & 1 deletion lib/nn/layers/linear.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx} from '../../..';
import {core as mx} from '../../core';
import {Module} from './base';
import {QuantizedLinear} from './quantized';

Expand Down
2 changes: 1 addition & 1 deletion lib/nn/layers/normalization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx, utils} from '../../..';
import {core as mx} from '../../core';
import {range} from './pytools';
import {Module} from './base';

Expand Down
2 changes: 1 addition & 1 deletion lib/nn/layers/pooling.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx} from '../../..';
import {core as mx} from '../../core';
import {accumulate, range} from './pytools';
import {Module} from './base';

Expand Down
2 changes: 1 addition & 1 deletion lib/nn/layers/positional-encoding.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx, utils} from '../../..';
import {core as mx} from '../../core';
import {Module} from './base';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/nn/layers/quantized.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx} from '../../..';
import {core as mx} from '../../core';
import {toSnakeCase, treeMapWithPath} from '../../utils';
import {Embedding} from './embedding';
import {Linear} from './linear';
Expand Down
2 changes: 1 addition & 1 deletion lib/nn/layers/recurrent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx} from '../../..';
import {core as mx} from '../../core';
import {tanh} from './activations';
import {Module} from './base';

Expand Down
2 changes: 1 addition & 1 deletion lib/nn/layers/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx} from '../../..';
import {core as mx} from '../../core';
import {checkpoint} from '../utils';
import {relu} from './activations';
import {Module} from './base';
Expand Down
2 changes: 1 addition & 1 deletion lib/nn/layers/upsample.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx, utils} from '../../..';
import {core as mx} from '../../core';
import {product} from './pytools';
import {Module} from './base';

Expand Down
6 changes: 3 additions & 3 deletions lib/nn/losses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx} from '../..';
import {core as mx} from '../core';
import {deepEqual} from '../utils';

type Reduction = 'none' | 'mean' | 'sum';
Expand All @@ -15,7 +15,7 @@ type Reduction = 'none' | 'mean' | 'sum';
* @param weights - Optional weights for each target. Default: `undefined`.
* @param axis - The axis over which to compute softmax. Default: `-1`.
* @param labelSmoothing - Label smoothing factor. Default: `0`.
* @param reduction - Specifies the reduction to apply to the output: `'none'` |
* @param reduction - Specifies the reduction to apply to the output: `'none'` |
* `'mean'` | `'sum'`. Default: `'none'`.
*
* @returns The computed cross entropy loss.
Expand Down Expand Up @@ -370,7 +370,7 @@ export function smoothL1Loss(predictions: mx.array,
* @param axis - The distribution axis. Default: `-1`.
* @param p - The norm degree for pairwise distance. Default: `2`.
* @param margin - Margin for the triplet loss. Defaults to `1.0`.
* @param eps - Small positive constant to prevent numerical instability. Defaults to `1e-6`.
* @param eps - Small positive constant to prevent numerical instability. Defaults to `1e-6`.
* @param reduction - Specifies the reduction to apply to the output: `'none'` | `'mean'` | `'sum'`. Default: `'none'`.
*
* @returns Computed triplet loss. If reduction is "none", returns a tensor of the same shape as input;
Expand Down
2 changes: 1 addition & 1 deletion lib/nn/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx} from '../..';
import {core as mx} from '../core';
import {Module} from './layers/base';
import {NestedDict} from '../utils';

Expand Down
4 changes: 3 additions & 1 deletion lib/optimizers/optimizers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {core as mx, nn, utils} from '../..';
import * as nn from '../nn';
import * as utils from '../utils';
import {core as mx} from '../core';
import {Nested, NestedDict, treeMap} from '../utils';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/optimizers/schedulers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core as mx} from '../..';
import {core as mx} from '../core';

/**
* Make an exponential decay scheduler.
Expand Down
16 changes: 0 additions & 16 deletions lib/stream.ts

This file was deleted.

12 changes: 2 additions & 10 deletions index.d.ts → node_mlx.node.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export namespace core {
declare module '*node_mlx.node' {
// Device.
type DeviceType = number;

Expand All @@ -20,7 +20,7 @@ export namespace core {
}

function defaultStream(device: DeviceOrType): Stream;
function setDefaultStream(): void;
function setDefaultStream(stream: Stream): void;
function newStream(device: DeviceOrType): Stream;
function toStream(s: StreamOrDevice): Stream;
function stream(s: StreamOrDevice): Disposable;
Expand Down Expand Up @@ -475,11 +475,3 @@ export namespace core {
const newaxis: null;
}

// The nn module.
export * as nn from './lib/nn';

// The optim module.
export * as optimizers from './lib/optimizers';

// The utils module.
export * as utils from './lib/utils';
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
"name": "@frost-beta/mlx",
"version": "0.0.1-dev",
"description": "Node-API bindings for MLX",
"main": "index.js",
"types": "index.d.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": "./dist/index.js",
"./*": "./dist/*.js"
},
"scripts": {
"install": "node install.js",
"prepack": "tsc --build",
Expand Down
Loading