ekzhang/jax-js
JAX in JavaScript – ML library for the web, running on WebGPU & Wasm
What it solves
jax-js is a machine learning framework designed to bring high-performance numerical computing and JAX-style operations to the web browser. It allows developers to run complex mathematical applications, neural networks, and simulations directly on the client side using CPU and GPU acceleration without needing a backend server.
How it works
The framework translates array operations into a compiler representation and then synthesizes optimized kernels for WebAssembly (Wasm) and WebGPU. It supports multiple device backends:
- WebGPU: The primary recommendation for high performance and neural networks.
- Wasm: A multi-threaded CPU backend.
- WebGL: A fallback for older browsers.
- CPU: An interpreted JS backend for debugging.
To optimize performance, it features a jit() function for kernel fusion, which combines multiple operations into a single GPU dispatch to reduce memory bandwidth bottlenecks. It also implements a manual reference-counting memory model (.ref and .dispose()) to manage large arrays in JavaScript's garbage-collected environment.
Who it’s for
It is intended for developers who want to build portable, high-performance ML applications in the browser, such as interactive visualizations, voice assistants, or in-browser LLM inference, while maintaining an API compatible with NumPy and JAX.
Highlights
- JAX-style Transformations: Supports
grad()for automatic differentiation,vmap()for auto-vectorization, andjit()for kernel fusion. - High Performance: Achieves matrix multiplication speeds comparable to OpenBLAS on CPU and over 7000 GFLOP/s on high-end Apple Silicon via WebGPU.
- Broad Compatibility: Runs across Chrome, Firefox, Safari, and Node.js/Deno, with support for Float16, Float32, and Float64.
- Zero Dependencies: Written from scratch with no external dependencies.
- Ecosystem: Includes helper libraries for loading Safetensors, importing ONNX models, and implementing optimizers like Adam and SGD.
Related
- Project
- Project
- Project
- Project
- Project