@jax-js/jax 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Eric Zhang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # jax-js: JAX in pure JavaScript
2
+
3
+ [Website](https://www.ekzhang.com/jax-js/)
4
+
5
+ This is a machine learning framework for the browser. It aims to bring JAX-style, high-performance
6
+ CPU and GPU kernels to JavaScript, so you can run numerical applications on the web.
7
+
8
+ ```bash
9
+ npm i @jax-js/jax
10
+ ```
11
+
12
+ Under the hood, it translates array operations into a compiler representation, then synthesizes
13
+ kernels in WebAssembly and WebGPU.
14
+
15
+ ## Quickstart
16
+
17
+ You can use `jax-js` as an array API, just like NumPy.
18
+
19
+ ```js
20
+ import { numpy as np } from "@jax-js/jax";
21
+
22
+ // Array operations, compatible with NumPy.
23
+ const x = np.array([1, 2, 3]);
24
+ const y = x.mul(4); // [4, 8, 12]
25
+ ```
26
+
27
+ It also lets you take derivatives like in JAX.
28
+
29
+ ```js
30
+ import { grad, numpy as np } from "@jax-js/jax";
31
+
32
+ // Calculate derivatives with reverse-mode AD.
33
+ const norm = (a) => a.ref.mul(a).sum();
34
+
35
+ const x = np.array([1, 2, 3]);
36
+ const xnorm = norm(x.ref); // 1^2 + 2^2 + 3^2 = 14
37
+ const xgrad = grad(norm)(x); // [2, 4, 6]
38
+ ```
39
+
40
+ The default backend runs on CPU, but on [supported browsers](https://caniuse.com/webgpu),
41
+ you can switch to GPU for maximum performance.
42
+
43
+ ```js
44
+ import { numpy as np, setDevice } from "@jax-js/jax";
45
+
46
+ // Change the default backend to GPU.
47
+ setDevice("webgpu");
48
+
49
+ const x = np.ones([4096, 4096]);
50
+ const y = np.dot(x.ref, x); // JIT-compiled into a matrix multiplication kernel
51
+ ```
52
+
53
+ ## Development
54
+
55
+ Under construction.
56
+
57
+ ```bash
58
+ npm install
59
+ npm run build:watch
60
+ npm test
61
+ ```
62
+
63
+ ## Next on Eric's mind
64
+
65
+ - softmax, log_softmax, logsumpexp, one_hot
66
+ - Start working on first neural network
67
+ - Investigate why jax-js Matmul is 2x slower on Safari TP than unroll kernel
68
+ - How many threads to create per workgroup, depends on hardware
69
+ - Need to break up kernel dispatches if workgroup count exceeds 65536
70
+ - Think about two-stage `cumsum()`
71
+ - Frontend transformations need to match backend type for pureArray() and zeros() calls
72
+
73
+ ## Milestones
74
+
75
+ - [x] It works!
76
+ - [x] Demos: Browser REPL / editor
77
+ - [x] First custom kernel
78
+ - [x] Custom WebGPU backend, removing tfjs dependency
79
+ - [x] Low-level operations
80
+ - [x] Create `class Array {}` wrappers
81
+ - [x] Reduction operations
82
+ - [ ] Kernel tuning (see `tuner.ts`)
83
+ - [x] "Upcast" optimizations (compute a tile per thread, e.g., matmul)
84
+ - [x] "Unroll" optimizations (multiple loop iters per thread, e.g., matmul)
85
+ - [ ] "Group" optimizations (multiple threads per value, e.g., matvec)
86
+ - [ ] Blocks respect local dimensions
87
+ - [x] Other dtypes like int32 and bool
88
+ - [x] `jit()` support via Jaxprs and kernel fusion
89
+ - [x] We figure out the `dispose()` / refcount / linear types stuff
90
+ - [ ] `dispose()` for saved "const" tracers in Jaxprs
91
+ - [ ] Garbage collection for JIT programs, maybe needs to be moved off-device
92
+ - [ ] Memory scheduling, buffer allocation (can be tricky)
93
+ - [ ] Demos: Navier-Stokes, neural networks, statistics
94
+ - [ ] Features for neural networks
95
+ - [ ] Convolution
96
+ - [ ] Random and initializers
97
+ - [ ] Optimizers (optax package?)
98
+ - [ ] Wasm backend (needs malloc)
99
+ - [ ] SIMD support for Wasm backend
100
+ - [ ] Device switching with `.to()` between webgpu/cpu/wasm
101
+ - [ ] numpy/jax API compatibility table
102
+ - [ ] Import tfjs models