Developer Docs

Architecture, research, and API reference for browser-native AI inference.

Overview

browser ai is an open-source platform for running AI models entirely in your browser. No servers, no API keys, no data leaving your device. Every model runs locally via WebGPU or WebAssembly.

Browser-native AI inference — no servers, no latency

Built for two audiences: users who want private, free AI tools without setup, anddevelopers/ML engineers who want to fine-tune, export, and deploy custom models for browser-based inference.

Core Principles

  • 100% client-side — All inference runs in the browser tab. Your data never touches a server.
  • Zero operating cost — No API fees, no GPU rentals, no subscriptions.
  • Privacy by design — Uploaded data and model files never leave your device.
  • Offline capable — After initial download, most features work without internet.

Architecture

The platform uses two inference engines depending on the model type:

ONNX Runtime Web — two engines, one platform

Transformers.js (standard models)

Used for: Summarization, Image Classification, Object Detection, Segmentation, OCR. Models are downloaded from Hugging Face Hub and executed via ONNX Runtime Web.

Custom ONNX Runtime Web (fine-tuned models)

Used for: Personality Chat. Users upload ONNX model files as ZIP archives. A custom BPE tokenizer handles text encoding/decoding.

Both engines target WebGPU with automatic fallback to WebAssembly (WASM).

Stack

FrameworkNext.js 16 (React 19)
StylingTailwind CSS v4
AnimationFramer Motion
InferenceONNX Runtime Web v1.27+
Transformers@huggingface/transformers v4
Fine-tuningUnsloth + LoRA (Python)
ONNX Exportoptimum-cli (Python)
Zipfflate (browser)

Training Pipeline

Fine-tune SmolLM2-360M-Instruct on custom text using LoRA with Unsloth. Runs on your GPU or Google Colab.

1

Prepare data

Export text as a .txt file. 50K+ characters recommended.

2

Train

Loads SmolLM2 in 4-bit NF4 via Unsloth, applies LoRA (rank 16), trains with SFTTrainer. Takes 5-15 min.

3

Merge

LoRA adapters are merged into the base model and saved as PyTorch (~700 MB).

4

Export ONNX

Runs optimum-cli to export to ONNX with KV-cache support.

5

Upload

The ONNX files are zipped automatically. Upload to the Chat page.

6

Chat

All inference runs locally via WebGPU/WASM. Streaming, KV-cache, temperature sampling.

Training Script

train/smol_lora_train.py is the main training script. Uses Unsloth for 4-bit LoRA fine-tuning with optional ONNX export.

Arguments

--data

Path to training text file

--output

Output directory

default: ./output

--steps

Training steps

default: 60

--lora-rank

LoRA rank

default: 16

--batch-size

Per-device batch size

default: 2

--learning-rate

Learning rate

default: 2e-4

--export-onnx

Export to ONNX for browser

default: False

Example

python train/smol_lora_train.py --data ./my-book.txt --steps 60 --export-onnx

ONNX Export

The ONNX export bridges Python training and browser inference. Here is how the exported model is structured.

Files produced

model.onnxThe core computation graph with weights.
config.jsonModel architecture hyperparameters.
tokenizer.jsonBPE tokenizer vocabulary and merge rules.
tokenizer_config.jsonTokenizer metadata and chat template.

Tensor names

Inputs:

input_ids[batch, seq_len]Token IDs
attention_mask[batch, seq_len]Padding mask
past_key_values.{i}.key/.value[batch, heads, past_len, dim]KV cache (optional)

Outputs:

logits[batch, seq_len, vocab_size]Prediction scores
present.{i}.key/.value[batch, heads, total_len, dim]Updated KV cache

FAQ

Q: Does the personality model learn my writing style?

Yes. LoRA fine-tuning trains the model on your text using causal language modeling. 50K+ characters recommended.

Q: Is my data sent anywhere?

No. Everything runs locally — training on your GPU or Colab, inference in your browser.

Q: Will this work on my phone?

Desktop WebGPU works well (30-60 tok/s). Mobile is more limited — INT8 models help.

Q: How do I share my trained personality?

Share the personality-onnx.zip file. Others upload it to their own Chat page.

Setup

Setting up the project for local development.

Frontend (Next.js)

npm install
npm run dev

Training (Python)

pip install unsloth trl accelerate torch transformers
train/smol_lora_train.py --data ./my-book.txt --steps 60 --export-onnx

Last updated: June 2026 · View source on GitHub