0.14.0 • Published 2 years ago

@arition/torch-js v0.14.0

Weekly downloads
6
License
MIT
Repository
github
Last release
2 years ago

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.

0.14.0

2 years ago

0.13.0

3 years ago

0.13.1

3 years ago

0.12.1

3 years ago

0.12.2

3 years ago

0.12.3

3 years ago

0.12.0

3 years ago

0.11.0

4 years ago

0.10.0

4 years ago

0.9.0

4 years ago

0.8.0

4 years ago

0.7.0

4 years ago

0.7.0-beta.3

4 years ago

0.7.0-beta.2

4 years ago

0.7.0-beta.1

4 years ago

0.7.0-beta.0

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.2.0

4 years ago