Exploring JSTorch: The JavaScript Version of PyTorch

Опубликовано: 02 Июнь 2024
на канале: Stephen Blum
530
8

JSTorch is a JavaScript library created for machine learning with the intention of mimicking PyTorch's syntax. it's not an exact replica because Python has some extra features that make it easier to build, like being able to overload operators so you can add matrices with a plain plus sign. But with JSTorch, you have to use torch.add, which makes it a bit more cumbersome. Now, we do run into a problem.

The library is called JSTorch, but it's focused on imitating PyTorch syntax, not LibTorch's., LibTorch is a version of the framework written in C and designed to use hardware accelerators like GPUs, FPGAs, and TPUs. But JSTorch, written 100% in JavaScript, doesn't use LibTorch. Instead, it appeals only to single-processor CPUs, meaning you won't get multiple core or hardware acceleration benefits. Despite this limitation, the library is well-made as it's simple to use and does carry over the patterns used in LibTorch or PyTorch.

There's something peculiar though: while its repository name and brand is JSTorch, its reference as a package on NPM is, JSPyTorch. So, if you decide to use this library, make sure you download the correct one: NPM install JS-PyTorch.