Machine Learning
BNLM
A small decoder-only Transformer initialized, trained, and executed for inference entirely client-side inside the browser. Written in native JavaScript ES modules and WebGPU WGSL compute shaders with CPU fallback, featuring a custom reverse-mode autograd tensor engine, BPE tokenizer, Adam/AdamW optimizers, and non-blocking Web Worker execution with zero server dependencies, Python runtimes, or build steps.
Research question
What architecture, systems design, and compute-dispatch patterns allow a Transformer language model to be trained from random initialization entirely inside a single browser tab under client-side memory and compute constraints?
Method & architecture
BNLM implements a complete deep learning training and inference pipeline running directly in the browser runtime. The tensor library provides reverse-mode automatic differentiation, matrix operations are accelerated via a custom WGSL compute shader on WebGPU with CPU fallback, and asynchronous Web Workers prevent UI thread blocking during training passes.
- Zero Server Dependency: Entire training loop, gradient backprop, and forward inference execute in the client tab without Python, servers, or WASM toolchains.
- Hardware-Adaptive Compute: Uses WebGPU WGSL compute shaders when available, falling back gracefully to pure CPU execution.
- Non-Blocking Execution: Long-running gradient steps run in dedicated Web Workers to protect browser responsiveness.
- Tensor & Autograd Engine: Custom tensor library supporting dynamic computational graph construction and reverse-mode automatic differentiation (src/tensor.js).
Results & findings
Client-Side Autograd Feasibility
OBSERVEDDemonstrated that reverse-mode backpropagation and parameter updates execute deterministically in browser JavaScript engines without native compilation.
WebGPU Matmul Acceleration
OBSERVEDWGSL compute shaders provide substantial speedups over pure JavaScript CPU execution for inner matrix operations on compatible hardware.