Transformers.js v4 Preview: Now Available on NPM!

Transformers.js v4 (preview) is now available on NPM, featuring a new C++ WebGPU Runtime and significant performance optimizations for running state-of-the-art AI models locally.
We're excited to announce that Transformers.js v4 (preview) is now available on NPM! After nearly a year of development (we started in March 2025 🤯), we're finally ready for you to test it out. Previously, users had to install v4 directly from source via GitHub, but now it's as simple as running a single command!
npm i @huggingface/transformers@next
We'll continue publishing v4 releases under the next tag on NPM until the full release, so expect regular updates!
The biggest change is undoubtedly the adoption of a new WebGPU Runtime, completely rewritten in C++. We've worked closely with the ONNX Runtime team to thoroughly test this runtime across our ~200 supported model architectures, as well as many new v4-exclusive architectures.
In addition to better operator support (for performance, accuracy, and coverage), this new WebGPU runtime allows the same transformers.js code to be used across a wide variety of JavaScript environments, including browsers, server-side runtimes, and desktop applications. That's right, you can now run WebGPU-accelerated models directly in Node, Bun, and Deno!
We've proven that it's possible to run state-of-the-art AI models 100% locally in the browser, and now we're focused on performance: making these models run as fast as possible, even in resource-constrained environments. This required completely rethinking our export strategy, especially for large language models. We achieve this by re-implementing new models operation by operation, leveraging specialized ONNX Runtime Contrib Operators like com.microsoft.GroupQueryAttention, com.microsoft.MatMulNBits, or com.microsoft.QMoE to maximize performance.
For example, adopting the com.microsoft.MultiHeadAttention operator, we were able to achieve a ~4x speedup for BERT-based embedding models.
This update enables full offline support by caching WASM files locally in the browser, allowing users to run Transformers.js applications without an internet connection after the initial download.
Developing a new major version gave us the opportunity to invest in the codebase and tackle long-overdue refactoring efforts. Until now, the GitHub repository served as our npm package. However, looking to the future, we saw the need for various sub-packages that depend heavily on the Transformers.js core while addressing different use cases. That's why we converted the repository to a monorepo using pnpm workspaces.
Another major refactoring effort targeted the ever-growing models.js file. In v3, all available models were defined in a single file spanning over 8,000 lines. For v4, we split this into smaller, focused modules. This new structure improves readability and makes it much easier to add new models.
We've migrated our build system from Webpack to esbuild, and the results have been incredible. Build times dropped from 2 seconds to just 200 milliseconds, a 10x improvement. Bundle sizes also decreased by an average of 10% across all builds. The most notable improvement is in transformers.web.js, which is now 53% smaller.
A frequent request from users was to extract the tokenization logic into a separate library, and with v4, that's exactly what we've done. @huggingface/tokenizers is a complete refactor of the tokenization logic, designed to work seamlessly across browsers and server-side runtimes. At just 8.8kB (gzipped) with zero dependencies, it's incredibly lightweight while remaining fully type-safe.
We've made several quality-of-life improvements across the library. The type system has been enhanced with dynamic pipeline types. Additionally, we've added support for larger models exceeding 8B parameters. In our tests, we've been able to run GPT-OSS 20B (q4f16) at ~60 tokens per second on an M4 Pro Max.
Source: Hugging Face Blog

















