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.
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:
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
Training Pipeline
Fine-tune SmolLM2-360M-Instruct on custom text using LoRA with Unsloth. Runs on your GPU or Google Colab.
Prepare data
Export text as a .txt file. 50K+ characters recommended.
Train
Loads SmolLM2 in 4-bit NF4 via Unsloth, applies LoRA (rank 16), trains with SFTTrainer. Takes 5-15 min.
Merge
LoRA adapters are merged into the base model and saved as PyTorch (~700 MB).
Export ONNX
Runs optimum-cli to export to ONNX with KV-cache support.
Upload
The ONNX files are zipped automatically. Upload to the Chat page.
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
--dataPath to training text file
--outputOutput directory
default: ./output
--stepsTraining steps
default: 60
--lora-rankLoRA rank
default: 16
--batch-sizePer-device batch size
default: 2
--learning-rateLearning rate
default: 2e-4
--export-onnxExport 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 IDsattention_mask[batch, seq_len]— Padding maskpast_key_values.{i}.key/.value[batch, heads, past_len, dim]— KV cache (optional)Outputs:
logits[batch, seq_len, vocab_size]— Prediction scorespresent.{i}.key/.value[batch, heads, total_len, dim]— Updated KV cacheFAQ
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