FrameworksModelsML

Transformers.js Documentation — Running Models in the Browser and Node

by Hugging Face

IntermediateDocumentationFree~2-3 hours for the quick tour plus the WebGPU and quantization guides

Ship transformer inference with zero servers — the same pipeline API as Python, running on the user's own GPU.

Start LearningAdded Sep 20, 2026 · Updated Sep 20, 2026

Overview

The documentation is split into five tracks: Get Started (installation and a quick tour), Tutorials (beginner guides and complete sample applications), Developer Guides (task-oriented how-tos, including the WebGPU guide), Integrations, and a full API Reference for classes, functions and types. The API deliberately mirrors Python transformers — `pipeline('sentiment-analysis')` is the entry point, and you select hardware and precision with two options: `device: 'webgpu'` and `dtype` set to fp32, fp16, q8 or q4. Supported tasks span NLP (text generation, classification, NER, summarisation, translation, feature extraction), vision (object detection, segmentation, depth estimation, background removal), audio (ASR, text-to-speech, audio classification) and multimodal work (document question answering, zero-shot image and audio classification). Models come from the Hub as ONNX exports, and you can convert your own PyTorch, TensorFlow or JAX checkpoints with Optimum. Version 4.0.0, announced February 2026, rewrote the WebGPU runtime in C++ alongside the ONNX Runtime team and tested it across roughly 200 model architectures; the same code now runs GPU-accelerated in Node, Bun and Deno rather than browsers alone. That release also added Mamba state-space models, Multi-head Latent Attention and Mixture-of-Experts support — GPT-OSS 20B at q4f16 runs at about 60 tokens/second on an M4 Pro Max — cut the default web bundle by 53%, gave BERT embeddings a ~4x speedup, and shipped a ModelRegistry API for cache inspection and download progress plus a standalone 8.8kB tokenizers package.

At a Glance

Topic
Frameworks
Level
Intermediate
Format
Documentation
Cost
Free
Duration
~2-3 hours for the quick tour plus the WebGPU and quantization guides
Provider
Hugging Face
Hands-on
Yes — code/exercises
Certificate
None

What You’ll Learn

  • Call the same pipeline API you know from Python transformers directly from JavaScript or TypeScript
  • Switch a model between the WASM CPU backend and the WebGPU GPU backend with one option
  • Pick a dtype (fp32, fp16, q8, q4) to trade download size and memory against output quality
  • Run multi-billion-parameter chat models client-side with quantization and measure real tokens/second
  • Convert your own PyTorch, TensorFlow or JAX checkpoints to ONNX for the browser using Optimum
  • Build embedding, speech-recognition and object-detection features that never send user data to a server
  • Use the ModelRegistry API to inspect cache state, compute download size and report progress to users
  • Share one inference codebase across browser, Node, Bun and Deno runtimes after the v4 runtime rewrite

Highlights

  • Genuine API parity with Python transformers means existing model knowledge transfers directly, not approximately
  • The v4 WebGPU runtime was rewritten in C++ with the ONNX Runtime team and tested across ~200 architectures
  • Documented, measured performance numbers — ~4x on BERT embeddings, 53% smaller default bundle, 60 tok/s for GPT-OSS 20B on an M4 Pro Max
  • Covers the unglamorous production concerns most client-side ML posts skip: caching, bundle size, download progress, quantization tradeoffs
  • Runs entirely on the user's device, which removes per-token cost and is often the shortest path to a privacy requirement

Who It’s For

Best For

  • Frontend and full-stack engineers adding AI features without standing up an inference service
  • Teams with data-residency or privacy constraints that rule out sending user text or audio to an API
  • Developers prototyping local-first or offline AI applications in Electron, Node or Deno

Prerequisites

  • Solid JavaScript or TypeScript and familiarity with npm and modern bundlers
  • Basic understanding of what a transformer model and a tokenizer do
  • A WebGPU-capable browser or runtime to follow the GPU acceleration guides

FAQ

What is Transformers.js Documentation — Running Models in the Browser and Node?

Transformers.js is Hugging Face's JavaScript port of the transformers library, and these docs are how a web or Node developer gets real model inference running without an inference server. It mirrors the Python `pipeline()` API, executes models through ONNX Runtime, and since v4 uses a C++ WebGPU runtime that works identically in the browser, Node, Bun and Deno. After working through it you can ship embeddings, speech recognition, or a local chat model that runs entirely on the user's hardware with no API key and no data leaving the device.

Is Transformers.js Documentation — Running Models in the Browser and Node free?

Transformers.js Documentation — Running Models in the Browser and Node is free to access.

What level is Transformers.js Documentation — Running Models in the Browser and Node for?

Transformers.js Documentation — Running Models in the Browser and Node is aimed at a intermediate audience. Recommended background: Solid JavaScript or TypeScript and familiarity with npm and modern bundlers, Basic understanding of what a transformer model and a tokenizer do, A WebGPU-capable browser or runtime to follow the GPU acceleration guides.

How long does Transformers.js Documentation — Running Models in the Browser and Node take?

Expect roughly ~2-3 hours for the quick tour plus the WebGPU and quantization guides. Most learners work through it at their own pace.

What will I learn from Transformers.js Documentation — Running Models in the Browser and Node?

You'll learn: Call the same pipeline API you know from Python transformers directly from JavaScript or TypeScript; Switch a model between the WASM CPU backend and the WebGPU GPU backend with one option; Pick a dtype (fp32, fp16, q8, q4) to trade download size and memory against output quality; Run multi-billion-parameter chat models client-side with quantization and measure real tokens/second; Convert your own PyTorch, TensorFlow or JAX checkpoints to ONNX for the browser using Optimum; Build embedding, speech-recognition and object-detection features that never send user data to a server; Use the ModelRegistry API to inspect cache state, compute download size and report progress to users; Share one inference codebase across browser, Node, Bun and Deno runtimes after the v4 runtime rewrite.

Topics

transformers-jswebgpubrowser-inferenceonnx-runtimeedge-aijavascript

Sources

This page was written from 3 sources, 1 on domains other than huggingface.co.

  1. 1.huggingface.coindexvendor
  2. 2.github.com4.0.0
  3. 3.huggingface.cotransformersjs v4vendor