node-executorch: Node.js binding for ExecuTorch
npm install node-executorch
import { Module, Tensor } from 'node-executorch';
const model = await Module.load('path/to/model.pte');
const input = new Tensor('int32', [1, 1], Int32Array.from([ 1 ]));
const outputs = await model.forward([input]);
// Manually release
input.dispose();
model.dispose();
Building node-executorch requires a supported version of Node and Rust.
To run the build, run:
$ EXECUTORCH_INSTALL_PREFIX=path/to/executorch/cmake-out yarn build
This command uses the @neon-rs/cli utility to assemble the binary Node addon from the output of cargo
.
In the project directory, you can run:
Installs the project, including running yarn build
.
Builds the Node addon (bin/<platform>/<arch>/executorch.node
) from source, generating a release build with cargo --release
.
Additional cargo build
arguments may be passed to npm run build
and similar commands. For example, to enable a cargo feature:
yarn build --feature=beetle
Similar to yarn build
but generates a debug build with cargo
.
Similar to yarn build
but uses cross-rs to cross-compile for another platform. Use the CARGO_BUILD_TARGET
environment variable to select the build target.
Runs the unit tests by calling cargo test
. You can learn more about adding tests to your Rust code from the Rust book.
The directory structure of this project is:
node-executorch/
├── Cargo.toml
├── README.md
├── src/
| └── lib.rs
├── lib/
| ├── index.ts
| └── binding.ts
├── bin/
| └── <platform>/<arch>/executorch.node
├── scripts/
| └── postneon-dist.js
├── package.json
└── target/
Entry | Purpose |
---|---|
Cargo.toml |
The Cargo manifest file, which informs the cargo command. |
README.md |
This file. |
src/ |
The directory tree containing the Rust source code for the project. |
lib.rs |
Entry point for the Rust source code. |
lib/ |
The directory tree containing the TypeScript source code for the project. |
executorch.node |
Node addon generated by the build. |
scripts/ |
Utility scripts for the project. |
postneon-dist.js |
Utility script for post-processing the Neon build. |
package.json |
The npm manifest file, which informs the npm command. |
target/ |
Binary artifacts generated by the Rust build. |
Learn more about:
BSD
Built and maintained by BRICKS.