surfgrad is a high-performance, WebGPU-powered AutoGrad library that enables browser-based tensor operations with GPU acceleration.
Key Features:
- 🚀 Blazing-fast tensor operations leveraging WebGPU
- 🧠 Automatic differentiation for deep learning in the browser
- 🌐 Zero backend dependencies - runs entirely client-side
- 📦 Lightweight and easy to integrate into existing web projects
Perfect for running tensor operations and (in the future) machine learning models in the browser!
It's heavily inspired by micrograd, tinygrad, and PyTorch and aims to leverage the power of WebGPU/WGSL for in-browser machine learning.
surfgrad
supports basic tensor operations such as matmul
, mul
, add
, exp
, and log
.
To use surfgrad
,
import { Tensor } from "surfgrad";
const tensorA = new Tensor(new Float32Array([1, 2, 3, 4]), [2, 2], true);
const tensorB = new Tensor(new Float32Array([5, 6, 7, 8]), [2, 2], true);
const [result, executionTime] = await tensorA.matmul(tensorB);
console.log(result);
await result.backward();
surfgrad
has unit tests and integration tests. To run the unit tests, run the following command:
npm run unit
and to run the integration tests, run the following command:
npm run integration
We also have benchmarks that can be helpful to demonstrate the performance of the matmul
kernels.
To run the benchmarks, run the following command:
npm run benchmark
and open a browser to localhost:9000
.
This will run the benchmarks for the library and display the results.
Contributions to surfgrad
are welcome! If you'd like to contribute, please fork the repository and submit a pull request.
SurfGrad is licensed under the Apache 2.0 License.