Client-side machine learning libraries
Jul 7 – Oct 25, 2026Updated Oct 25, 2026
Reviewed by Dimitry Apollonsky
Which brands AI mentions
Mentioned in
ChatGPTChatGPTGoogle AI ModeGoogle AI Mode
Widest split: ONNX Runtime, 100% on ChatGPT and 80% on Google AI Mode.
- #1Transformers.jsChatGPT 100%Google AI Mode 100%
- #2tiedTensorFlow.jsChatGPT 86%Google AI Mode 100%
- #2tiedONNX RuntimeChatGPT 100%Google AI Mode 80%
- #4WebLLMChatGPT 68%Google AI Mode 70%
- #5tiedMediaPipeChatGPT 18%Google AI Mode 30%
Questions and answers
ChatGPTOct 25, 2026
If you want to run ML inference directly in the browser, my default recommendation is ONNX Runtime Web for general-purpose model inference, and Transformers.js if you're primarily working with pretrained transformer models from Hugging Face.
The best choice depends on your model format, target hardware, and whether you're running computer vision, NLP, embeddings, or generative AI. Browser-side inference can avoid sending inputs to a server, reduce backend costs, and enable offline-capable experiences once models are cached.
Best browser ML libraries compared
1. Transformers.js
(Best default for pretrained models)
Great for text classification, embeddings, reranking, speech recognition, summarization, and supported vision tasks. Its high-level pipeline API makes getting started easy, and it uses ONNX Runtime under the hood.
Website:
2. ONNX Runtime Web
(Best for custom models)
Choose this when you want direct control over inference, input/output tensors, execution providers, and deployment of models exported to ONNX. Supports WebAssembly and WebGPU, with hardware and operator limitations to consider.
Website:
3. TensorFlow.js
Best if your team already uses TensorFlow or Keras, needs browser-based training or transfer learning, or wants a mature ecosystem of vision and audio models.
Website:
4. WebLLM
Best for running supported generative language models entirely in the browser, including chat and text generation. It is more specialized than a general-purpose inference runtime and is designed around WebGPU acceleration.
Website:
What I'd choose by use case
Your workload Recommendation Text embeddings or semantic search Transformers.js Classification, reranking, custom ONNX models ONNX Runtime Web Chat with a local LLM WebLLM Existing TensorFlow/Keras models or browser training TensorFlow.js Face, hand, pose, or gesture tracking MediaPipe These distinctions align with Google's overview of the client-side AI ecosystem.
Example: run inference with Transformers.js
Install the package:
bashnpm install @huggingface/transformersThen run sentiment analysis in the browser:
javascriptimport { pipeline } from '@huggingface/transformers'; const classifier = await pipeline( 'sentiment-analysis', 'Xenova/distilbert-base-uncased-finetuned-sst-2-english' ); const result = await classifier('This runs directly in my browser!'); console.log(result);For supported models, you can request WebGPU acceleration and use quantized weights to reduce memory and download costs. WebGPU availability and model compatibility vary, so test on your target browsers and devices.
Three architectural decisions worth making early
- Model size: Download time, RAM/VRAM usage, and model initialization can dominate the user experience. Start with a small model and evaluate quantization.
- Execution backend: WebAssembly is a useful compatibility fallback; WebGPU can accelerate supported workloads on compatible devices.
- Deployment: Model files can be cached for subsequent or offline use, but the first download still matters. Consider a Web Worker to keep expensive inference from blocking the UI thread.
My bottom line: Start with Transformers.js for the fastest route to a working browser inference feature. Choose ONNX Runtime Web if you need a lower-level runtime for your own exported models, and WebLLM if the main goal is local LLM chat.
One question that would help me narrow this down: what kind of model are you running—an LLM, an embedding model, a computer-vision model, or a custom model you already have in PyTorch/ONNX?
Google AI ModeOct 25, 2026
The "best" JavaScript library for client-side machine learning inference depends entirely on what kind of model you are trying to run and your target hardware acceleration.
Modern browser ML relies heavily on WebGPU and WebAssembly (Wasm) to achieve near-native speeds. The top client-side libraries categorized by use case include:
1. Transformers.js (Hugging Face) — Best for General NLP, Vision, and Audio
- What it is: A JavaScript port of Hugging Face's iconic Python
transformerslibrary, powered under the hood by ONNX Runtime Web. - Best for: Embeddings, sentiment analysis, text classification, feature extraction, object detection, and speech-to-text.
- Why it’s great: It gives you direct, task-level pipeline APIs and drop-in access to thousands of pre-converted ONNX models directly from the Hugging Face Hub. It falls back gracefully to Wasm if WebGPU isn't available.
- Check out: Hugging Face Transformers.js Docs
2. WebLLM — Best for High-Performance In-Browser LLMs & Chatbots
- What it is: An implementation bringing high-throughput, heavy LLM inference (like Llama, Phi, and Mistral) directly inside the browser via WebGPU.
- Best for: Running full conversational chat assistants and generative agents client-side.
- Why it’s great: It leverages TVM WebAssembly and WebGPU optimizations to achieve surprisingly fast token generation speeds locally, preserving absolute user privacy and zero server costs.
- Check out: WebLLM on GitHub
3. MediaPipe (Google) — Best for Real-Time Computer Vision & Audio
- What it is: Google's refined suite of production-ready, highly optimized solutions for perception tasks.
- Best for: Face mesh/landmark detection, hand tracking, pose estimation, selfie segmentation, and object detection.
- Why it’s great: If you need real-time (60 FPS) video manipulation or tracking in the browser, MediaPipe blows general-purpose frameworks out of the water because the models are custom-built and rigidly optimized for the web.
- Check out: Google MediaPipe Solutions
4. ONNX Runtime Web (Microsoft) — Best for Custom/Framework-Agnostic Models
- What it is: Microsoft’s cross-platform inference engine tailored for the web.
- Best for: Developers who have trained a custom PyTorch/TensorFlow model, exported it to
.onnxformat, and need fine-grained control over execution graphs. - Why it’s great: It supports multiple execution paths including WebGPU, WebNN (for hardware NPUs), WebGL, and WebAssembly. It is more verbose than Transformers.js, but offers maximum custom flexibility.
- Check out: ONNX Runtime Web Documentation
5. TensorFlow.js (Google) — Best for Legacy Support & Training in-browser
- What it is: The veteran Google ML ecosystem for JavaScript.
- Best for: Legacy codebases, simpler custom web apps, or scenarios where you specifically need to train a lightweight model directly in the browser via user interaction.
- Why it’s great / Status: While it remains capable, its momentum for modern generative AI and transformer architectures has largely been superseded by ONNX-based workflows and WebGPU-first libraries like Transformers.js and WebLLM.
To help narrow down the ideal choice, tell me:
- What specific task or model architecture are you trying to run (e.g., LLM text generation, embeddings, real-time webcam tracking)?
- Are you targeting desktop-only WebGPU environments, or do you need broad mobile/fallback compatibility via Wasm?
Sources cited in this answer8
- intel.comA Guide to In-Browser LLMs
- pkgpulse.comTransformers.js vs ONNX Runtime Web: Browser ML 2026 — PkgPulse Guides
- lofttools.comRunning LLMs in the Browser - WebLLM vs transformers.js
- web.devThe client-side AI stack | web.dev
- localmode.devWebLLM vs Transformers.js | AI Comparison - LocalMode
- sitepoint.comWebGPU Browser AI: Client-Side Inference in JavaScript
Google AI ModeOct 15, 2026
Selecting the best JavaScript library for client-side model inference
depends heavily on your model format, target hardware acceleration (WebGPU, WebAssembly, or WebNN), and whether you want to write custom architectures or use pre-trained state-of-the-art models.The top tools available for client-side inference are structured below by their primary strengths:
- Transformers.js (
@huggingface/transformers)- Best for: Running pre-trained transformer and deep learning models (NLP, computer vision, audio, and multimodal tasks like Whisper, BERT, or BERT-variants) directly in the browser with zero server dependency.
- Why choose it: It mirrors Hugging Face’s popular Python API, making it remarkably easy to load thousands of pre-converted ONNX models straight from the Hugging Face Hub. It handles tokenization and pipeline abstractions out of the box.
- Where to find it: Check out the package details on the Hugging Face Transformers.js Blog or install it via the @huggingface/transformers npm package.
- ONNX Runtime Web (
onnxruntime-web)- Best for: Maximum flexibility and high-performance inference for custom models exported from PyTorch, TensorFlow, or Scikit-Learn into the Open Neural Network Exchange (ONNX) format.
- Why choose it: Developed by Microsoft, it provides high-speed execution using WebAssembly (WASM) for CPU fallbacks, WebGL, and modern WebGPU pipelines for hardware acceleration. It also supports experimental WebNN API integrations to interface directly with device NPUs and native hardware accelerators.
- Where to find it: Review implementation details and execution providers in the ONNX Runtime Web Documentation.
- TensorFlow.js (
tfjs)- Best for: Projects heavily integrated into the TensorFlow ecosystem, or when you need to train/fine-tune models directly in the browser in addition to running inference.
- Why choose it: It supports WebGL and WebGPU backends, features a rich ecosystem of pre-trained models (via
tfjs-models), and allows you to convert and run standard SavedModel/Keras models client-side. - Where to find it: Explore guides and tutorials on the TensorFlow.js official site.
Quick Selection Matrix
- Using Hugging Face / NLP / Whisper / Vision models? Go with Transformers.js.
- Exporting custom models from PyTorch into a high-performance web runtime? Use ONNX Runtime Web.
- Need browser-based training, data manipulation pipelines, or legacy TF integration? Choose TensorFlow.js.
To help narrow down the ideal choice, could you tell me:
- What model architecture or file format (e.g., ONNX, TensorFlow, PyTorch) you plan to use?
- What type of media or data (text, audio, video/images) your app will process?
ChatGPTOct 15, 2026
Best JavaScript libraries for client-side model inference
If you're building a web application that runs ML models directly on the user's device, my recommendation is to start with Hugging Face Transformers.js for general-purpose inference, or WebLLM if your primary use case is running a local LLM for chat and text generation. If you need lower-level control over model execution, consider ONNX Runtime Web.
The key distinction is whether you're running an LLM, a smaller specialized model (such as an embedding, vision, or speech model), or a custom model you've already trained.
Top options at a glance
1. Transformers.js
(Best general-purpose default)
Run pretrained NLP, vision, audio, and multimodal models in the browser, with an API inspired by Python's Transformers library. Uses ONNX Runtime under the hood.
Best for: embeddings, classification, summarization, speech recognition, and supported text-generation models.
Docs: Transformers.js documentation ·
2. WebLLM
(Best for local LLM chat)
An inference engine purpose-built for running supported LLMs in the browser, with WebGPU acceleration and an OpenAI-compatible API.
Best for: private, local chat, streaming text generation, and LLM-powered features without a model-inference server.
Docs: WebLLM documentation ·
3. ONNX Runtime Web
A lower-level runtime for executing ONNX models with supported browser execution providers, including WebAssembly and WebGPU. You control preprocessing, tensor inputs, and output handling yourself.
Best for: custom models, predictable inference pipelines, and teams that want more control over runtime configuration.
Docs: ONNX Runtime Web documentation ·
4. TensorFlow.js
A broader JavaScript ML framework for running existing TensorFlow models, building models, and doing some training or transfer learning in the browser.
Best for: existing TensorFlow.js projects, custom neural networks, and workflows that combine inference with training.
Docs: TensorFlow.js documentation ·
How they compare
Capability Transformers.js WebLLM ONNX Runtime Web TensorFlow.js General ML inference Excellent LLM-focused Excellent with ONNX Excellent for TF.js models Local LLM generation Yes, supported models Primary use case Possible, more integration work Possible, model-dependent Embeddings and classifiers Excellent Not its focus Yes Yes Vision and audio Broad task support Not its focus Model-dependent Model-dependent Custom model support ONNX conversion required for many models Requires compatible compiled models ONNX models TF.js-compatible models Ease of integration High High for LLMs Moderate Moderate Runtime control Moderate Specialized High High within its framework This is a qualitative comparison, not a benchmark. Actual latency and memory use depend on the model, quantization, browser, and device.
What I'd choose by use case
A chatbot that runs entirely in the browser
Start with WebLLM. Its OpenAI-compatible API is useful if you want a familiar chat-completions interface.
Embeddings, semantic search, classification, or reranking
Start with Transformers.js. It provides a relatively simple path from pretrained models to working browser-side inference.
A custom-trained model or optimized production pipeline
Use ONNX Runtime Web if you can export the model to ONNX and want direct control over inference.
Training or transfer learning in the browser
Choose TensorFlow.js if its model and operator ecosystem matches your needs.
Example: running inference with Transformers.js
For example, a text-classification feature can run locally without sending the text to your own inference API.
Install the package:
bashnpm install @huggingface/transformersThen run a pretrained sentiment classifier:
javascriptimport { pipeline } from '@huggingface/transformers'; const classifier = await pipeline( 'sentiment-analysis', 'Xenova/distilbert-base-uncased-finetuned-sst-2-english' ); const result = await classifier( 'This model runs directly in the browser!' ); console.log(result);This is a starting point; the model must be downloaded and initialized, and you should verify the chosen model's compatibility and runtime behavior in your target browser. Transformers.js supports local model paths and can be configured to disable remote model loading.
Important engineering considerations
Before committing to a library, validate these five areas:
- Model download size: large models can make first-use experience poor. Quantization can reduce download and memory requirements.
- Hardware acceleration: WebGPU can help, but device and browser support must be tested. Have a fallback strategy where needed.
- UI responsiveness: run inference in a Web Worker where practical so long computations don't block rendering.
- Offline and privacy requirements: cache model assets, control remote model loading, and confirm that prompts and inputs are not sent elsewhere by your application.
- Real-device performance: benchmark cold-start time, warm inference latency, peak memory, and throughput on representative laptops and mobile devices. Don't assume WebGPU is always faster than WASM.
A quick question to narrow this down
What kind of models are you planning to run?
LLMs — chat, generation, summarization
Embeddings, classifiers, rerankers
Computer vision or audio models
A mix of model types
Where must inference run?
Browser only
Browser and Node.js
Browser plus mobile or edge devices
What matters most?
Inference speed and low latency
Broad model and hardware compatibility
Simple integration and developer experience
Privacy, offline operation, and local data
Do you already have a model?
We'll use pretrained models
We have our own trained model
We haven't decided yet
[Recommend a stack]
My default shortlist would be Transformers.js + WebLLM, with ONNX Runtime Web as the lower-level alternative when you need more control. The deciding factor is usually the model workload and the hardware you need to support, rather than which library is universally fastest.
Sources cited in this answer15
- huggingface.coTransformers.js · Hugging Face
- intel.comA Guide to In-Browser LLMs
- lofttools.comRunning LLMs in the Browser - WebLLM vs transformers.js
- huggingface.cobackends/onnx
- briancohn.comBrowser-Based ML Inference Guide | Brian Cohn Ph.D.
- github.comGitHub - delcenjo/browser-runtimes-bench: Measured latency, throughput, cold-load and memory for transformers.js, onnxruntime-web and tfjs on the same sentence-embedding and probe-MLP tasks, in a real browser
- Transformers.js (
Also asked as
- We are looking for a way to run ML models in the browser. Can you suggest the best JavaScript libraries for client-side inference?