← all repositories
eduardoleao052/js-pytorch

A PyTorch clone that runs in your browser tab

It exists so you can build and backprop through Transformers without leaving JavaScript.

1.2k stars JavaScript ML Frameworks
js-pytorch
Not currently ranked — collecting fresh signals.
star history

What it does

JS-PyTorch is a from-scratch deep learning library that apes PyTorch’s API in JavaScript. It gives you tensors, automatic differentiation, and common layers like nn.Linear, nn.Embedding, and nn.MultiHeadSelfAttention—enough pieces to assemble a Transformer in a browser script or Node process. GPU acceleration is provided by GPU.js, and models can be serialized to JSON.

The interesting bit

The author didn’t just wrap TensorFlow.js or ONNX; they rebuilt the core machinery—autograd, optimizers, and layer primitives—so the codebase stays small and readable. That interpretability is explicitly the goal; the README admits speed is secondary.

Key highlights

  • Implements a surprisingly complete stack: tensor ops, Transformer blocks, positional embeddings, LayerNorm, Dropout, and Adam optimization.
  • GPU offload via GPU.js, with a device argument that mirrors PyTorch’s 'cuda'/'cpu' pattern.
  • Runs in the browser via CDN or in Node, making it a rare fully-JS training environment.
  • Model weights can be saved and loaded as plain JSON, no pickle required.

Caveats

  • The author notes it is “not as optimized as PyTorch yet,” so this is an educational or prototyping tool rather than a production trainer.
  • Windows users may need a C++ build toolchain to install, suggesting native dependencies lurk beneath the JavaScript surface.

Verdict

Worth a look if you want to understand how PyTorch-like frameworks work under the hood without switching languages. Skip it if you need state-of-the-art training throughput or mature model zoos.

Frequently asked

What is eduardoleao052/js-pytorch?
It exists so you can build and backprop through Transformers without leaving JavaScript.
Is js-pytorch open source?
Yes — eduardoleao052/js-pytorch is open source, released under the MIT license.
What language is js-pytorch written in?
eduardoleao052/js-pytorch is primarily written in JavaScript.
How popular is js-pytorch?
eduardoleao052/js-pytorch has 1.2k stars on GitHub.
Where can I find js-pytorch?
eduardoleao052/js-pytorch is on GitHub at https://github.com/eduardoleao052/js-pytorch.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.