tj
@arition/torch-js
npm i @arition/torch-js
tj

@arition/torch-js

Node.js binding for PyTorch.

by Kittipat Virochsiri, arition, raghavmecheri

0.14.0 (see all)License:MITTypeScript:Built-In
npm i @arition/torch-js
Readme

TorchJS

npm version

TorchJS is a JS binding for PyTorch. Its primary objective is to allow running Torch Script inside Node.js program. Complete binding of libtorch is possible but is out-of-scope at the moment.

Changes after fork

  • Add support for List (Javascript Array), Dict (Javascript Object), String, float (Javascript number) as inputs and outputs.

  • Add CUDA support.

  • Add ops from torchvision.

  • Add async support for forward function.

Install

To install the forked version, you can install it from npm:

yarn add torch-js@npm:@arition/torch-js

Example

In tests/resources/torch_module.py, you will find the defination of our test module and the code to generate the trace file.

class TestModule(torch.nn.Module):
    def __init__(self):
        super(TestModule, self).__init__()

    def forward(self, input1, input2):
        return input1 + input2

Once you have the trace file, it may be loaded into NodeJS like this

const torch = require("torch-js");
const modelPath = `test_model.pt`;
const model = new torch.ScriptModule(testModelPath);
const inputA = torch.rand([1, 5]);
const inputB = torch.rand([1, 5]);
const res = await model.forward(inputA, inputB);

More examples regarding tensor creation, ScriptModule operations, and loading models can be found in our examples folder.

Downloads/wk

49

GitHub Stars

11

LAST COMMIT

1yr ago

MAINTAINERS

1

CONTRIBUTORS

4

OPEN ISSUES

2

OPEN PRs

0
VersionTagPublished
0.14.0
latest
2mos ago
0.7.0-beta.1
beta
2yrs ago
No alternatives found
No tutorials found
Add a tutorial

Rate & Review

100
No reviews found
Be the first to rate