signal.

Transformers.js v4: Now Available on NPM!

Transformers.js v4 has been released on NPM, featuring a new WebGPU runtime written in C++ that supports over 200 model architectures and allows WebGPU-accelerated models to run in browsers, Node, Bun, and Deno. The release includes a monorepo structure with pnpm workspaces, a split models.js for easier maintenance, and a new ModelRegistry API for production workflows. Performance gains include a 4x speedup for BERT-based embeddings and a 10x build time reduction with esbuild.

Transformers.js v4 has been released on NPM, bringing a new WebGPU runtime written in C++ that has been tested across roughly 200 supported model architectures and several new v4‑exclusive architectures. The update allows the same transformers.js code to run in browsers, Node, Bun, and Deno with WebGPU acceleration, and claims a ~4x speedup for BERT‑based embedding models using the com.microsoft.MultiHeadAttention operator. The release also introduces a monorepo structure using pnpm workspaces, enabling smaller sub‑packages that depend on @huggingface/transformers while reducing repository overhead. The large models.js file from v3 has been split into focused modules, improving readability and maintainability. Example projects have been moved to a dedicated repository, and the codebase has been reformatted with Prettier. Build times dropped from 2 seconds to 200 milliseconds after migrating from Webpack to esbuild, and bundle sizes decreased by an average of 10%, with the default export transformers.web.js shrinking 53%. New library features include a ModelRegistry API that exposes pipeline assets, metadata, cache status, and available data types, and progress callbacks now include a progress_total event. Environment controls such as env.useWasmCache and env.fetch allow offline caching of WASM runtime files and custom fetch implementations. Logging improvements hide ONNX Runtime WebGPU warnings by default and allow explicit verbosity levels. A separate @huggingface/tokenizers library has been released, lightweight at 8.8kB gzipped and dependency‑free, to handle tokenization logic. The release supports models exceeding 8B parameters, with tests showing GPT‑OSS 20B (q4f16) running at about 60 tokens per second on an M4 Pro Max. The update was made possible through collaboration with the ONNX Runtime team and community contributors.

Why it matters

The release expands the reach of high‑performance AI models to a wider range of JavaScript environments, enabling developers to deploy sophisticated models locally without server dependencies.

Topic dossiers OpenAI Hugging Face