The Definitive Guide to Running Machine Learning Models Locally with WebAssembly, WebGPU, and WebNN
Introduction
- What This Book Covers
- What This Book Is Not
- How to Use This Book
- Prerequisites
- A Note on Versions
Chapter 1: The Web AI Revolution – Why LiteRT.js Matters
- The Browser as an AI Platform
- From TensorFlow.js to LiteRT.js: A Generational Shift
- What Is LiteRT? The Unified On-Device Runtime
- The Value Proposition: Privacy, Performance, and Cost
- When to Use (and Not Use) LiteRT.js
- The Landscape of Browser AI
Chapter 2: Architecture Deep Dive
- The JS-to-WebAssembly Bridge Pattern
- Model Loading and Compilation Pipeline
- Tensor Buffer Management and Memory Layout
- Accelerator Delegation System
- SignatureRunner and Named Entry Points
Chapter 3: Getting Started – Installation, Initialization, and First Inference
- Installing @litertjs/core
- Serving WebAssembly Binaries
- Runtime Initialization with loadLiteRt
- Loading and Compiling Your First Model
- Running Inference and Reading Results
Chapter 4: Hardware Acceleration – WebGPU, WebNN, and XNNPACK
- WebGPU: GPU-Accelerated Inference
- WebNN: Neural Processing Unit Access
- XNNPack on WebAssembly: Optimized CPU Execution
- Accelerator Selection Strategy and Fallback Patterns
- JSPI (JavaScript Promise Integration) for Asynchronous Execution
Chapter 5: Model Conversion – From PyTorch, TensorFlow, and JAX to .tflite
- The .tflite FlatBuffer Format
- Converting PyTorch Models with litert_torch
- Converting TensorFlow and JAX Models
- Ultralytics YOLO Export Integration
- Conversion Troubleshooting and Common Pitfalls
Chapter 6: Model Optimization – Quantization, Size Reduction, and Performance Tuning
- Understanding Quantization: INT8, INT4, FP16
- Dynamic, Static, and Weight-Only Quantization
- Using the AI Edge Quantizer
- Selective Quantization and Mixed-Precision Strategies
- Model Size vs. Accuracy Trade-offs
Chapter 7: The Complete API Reference
- Core Runtime Functions (loadLiteRt, loadAndCompile)
- Tensor Class: Creation, Manipulation, and Transfer
- CompiledModel and SignatureRunner APIs
- Configuration Options and CompileOptions
- Error Handling and Debugging Utilities
Chapter 8: Memory Management and Performance Engineering
- Manual Memory Management: Why delete() Matters
- GPU-to-CPU Data Transfer Patterns
- Benchmarking Inference Performance
- Profiling and Diagnosing Bottlenecks
- Production Optimization Checklist
Chapter 9: Integration with Modern Web Frameworks
- React Integration (react-litert and Custom Hooks)
- Vue.js Composition API Integration
- Angular Services and Components
- Svelte Stores and Reactive Inference
- Next.js and Vite Build Configuration for WASM
Chapter 10: Computer Vision Applications
- Image Classification with MobileNet and ResNet
- Real-Time Object Detection with YOLO
- Semantic Segmentation Pipelines
- Depth Estimation and 3D Point Clouds
- Image Upscaling with Real-ESRGAN
Chapter 11: Audio, Speech, Text, and Multimodal AI
- Audio Processing and Noise Suppression
- Speech Recognition Patterns in the Browser
- Text Embeddings and On-Device RAG
- OCR and Document Intelligence
- LLM Inference with LiteRT-LM.js
Chapter 12: Production Deployment – Security, Compatibility, and Best Practices
- Security Model and Threat Considerations
- Browser Compatibility and Feature Detection
- Progressive Enhancement and Graceful Degradation
- Migrating from TensorFlow.js
- Production Deployment Checklist