Expand description
WebAssembly entry point for RLX.
Compiles to wasm32-unknown-unknown and exposes a small JS-callable
surface via wasm-bindgen. Both forward (inference) and backward
(gradients via rlx_autodiff) passes are available.
§Compute paths
-
CPU backend (default, works today):
mlp_forward,mlp_loss,mlp_grads,mlp_train_stepbuild an IR graph and run it throughrlx_runtime::Sessionon the CPU backend. Fully synchronous — runs on the browser main thread (rlx-cpuis single-threaded on wasm). -
WebGPU (
webgpufeature): async forward/backward viarlx_wgpu::WgpuExecutable::run_async(see [webgpu]); GPU→CPU readback cannot block the browser event loop, so those entry points areasync.
The forward and backward graphs are identical across backends — only the
executor differs. The backward graph comes from
rlx_autodiff::grad_with_loss; its outputs are [loss, ∂loss/∂p…] and
it is seeded with a d_output input (the cotangent, [1.0] for a scalar
loss).
Structs§
- Vision
Bench - Vision benchmark handle — forward, backward, and SGD on CPU / WebGPU / WebGL.
- Vision
Model Info - Metadata for a vision model (shapes, param layout, WebGL train support).
Functions§
- backend
- Label of the compute backend used by the synchronous entry points.
- list_
vision_ models - List vision model slugs available in the browser bundle.
- mlp_
forward - Run a two-layer MLP —
relu(x·W1 + b1)·W2 + b2— on the CPU backend and return the output row. - mlp_
grads - Forward + backward in one call on the CPU backend. Returns a flat vector:
[loss, ∂/∂w1 …, ∂/∂b1 …, ∂/∂w2 …, ∂/∂b2 …](gradients in row-major parameter order, same lengths as the inputs). - mlp_
loss - Mean-of-squares loss
Σ (y − target)²for the MLP, on the CPU backend. (Used for inference + as the scalar the backward pass differentiates.) - mlp_
train_ step - One SGD step: compute gradients of the loss and return the updated
parameters as
[w1 …, b1 …, w2 …, b2 …](same layout as the inputs). - parse_
backend - Parse backend name:
auto,cpu,webgpu,webgl. - preferred_
backend - Highest-priority available browser backend label (
cpu,webgpu,webgl, ornone). - start
- Module entry point — installs a panic hook that routes Rust panics to the browser console. Runs automatically when the wasm module is instantiated.
- transformer_
next_ logits - Run a real decoder-only transformer (RMSNorm + RoPE + causal multi-head
attention + SwiGLU) on the CPU backend with deterministic synthesized
weights, and return the next-token logits (last position), length
vocab.tokensare token ids (as f32);seq=tokens.len().dimmust equaln_heads * head_dim. - vision_
model_ info - Look up model metadata by slug (
mnist-cnn,mnist-mlp,cifar-cnn,resnet).