Hugging FaceJoshua, Nico MartinAnnouncement
Transformers.js v4: Now Available on NPM!
Summary
Transformers.js v4 is now available on NPM, marking a major release after a year of development. It introduces a C++-rewritten WebGPU runtime tested across about 200 supported model architectures, enabling the same JavaScript code to run WebGPU-accelerated models in browsers, Node, Bun, Deno, and desktop applications. Specialized ONNX Runtime Contrib Operators support new export strategies for large language models, and the post reports a roughly fourfold speedup for BERT-based embedding models using MultiHeadAttention. The release also restructures the repository as a pnpm-workspaces monorepo, modularizes model definitions, moves examples to a separate repository, and switches from Webpack to esbuild, reducing build times from two seconds to 200 milliseconds and shrinking transformers.web.js by 53%. New APIs cover model asset inspection, caching, environment fetch controls, logging, and standalone tokenization, while added architectures include Mamba, MLA, and MoE models compatible with WebGPU.
Context
The release addresses performance, runtime coverage, maintainability, package structure, model-loading visibility, and production-use needs. The previous repository exposed a single library, models.js had grown beyond 8,000 lines, examples were stored in the main repository, and the project needed better support for large language models and additional architectures.
Approach / What changed
The release adopts a C++-rewritten WebGPU runtime and specialized ONNX Runtime Contrib Operators, reworks model export strategies, converts the repository to pnpm workspaces, splits model definitions into focused modules, moves examples to a dedicated repository, and migrates the build system from Webpack to esbuild. It also adds ModelRegistry, environment and logging controls, a standalone tokenizers package, dynamic pipeline types, and support for larger models.
Takeaways
The new WebGPU runtime allows Transformers.js code to run hardware-accelerated models across browsers, Node, Bun, Deno, and desktop applications.
Using the com.microsoft.MultiHeadAttention operator produced a reported roughly 4x speedup for BERT-based embedding models.
The esbuild migration reduced build times from 2 seconds to 200 milliseconds, while transformers.web.js became 53% smaller.
Source and freshness
- Source
- huggingface.co
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.