Transformers.js v4 プレビュー版がNPMで利用可能に!
Transformers.js v4のプレビュー版がNPMで公開されました。最新バージョンではパフォーマンス向上と新機能が追加されています。
キーポイント
Transformers.js v4がNPMでプレビュー公開され、WebGPUランタイム(C++実装)を採用し、ブラウザ・Node・Bun・Denoなど多様なJavaScript環境で高速実行が可能に
ONNX Runtime Contrib Operatorsを活用した最適化により、BERTベースの埋め込みモデルで約4倍の高速化を実現し、オフライン対応(WASMキャッシュ)も強化
リポジトリをpnpmワークスペースを用いたモノレポに移行し、保守性と拡張性を向上させ、将来のサブパッケージ展開に対応
影響分析・編集コメントを表示
影響分析
このリリースは、最先端AIモデルのブラウザ上での100%ローカル実行を性能面で大幅に進化させ、WebGPUの普及とエッジAIの実用化を加速させる可能性がある。JavaScriptエコシステム全体で機械学習モデルの高性能・汎用実行環境が整備されることで、AIアプリケーションの開発・配布形態に影響を与える。
編集コメント
Hugging Faceが提供するTransformers.jsのメジャーアップデートは、ブラウザ上でのAIモデル実行の性能と利便性を大きく引き上げる。開発者にとっては、複雑な環境構築なしに高性能なAI機能をWebアプリに組み込める可能性が広がる画期的な進展だ。
Transformers.js v4 プレビュー版がNPMで公開されました。本稿では、この新バージョンにおける主要な改善点と新機能について詳述します。
最大の変更点は、新しいWebGPUランタイムの採用です。C++で完全に書き直されたこのランタイムは、ONNX Runtimeチームと緊密に連携し、約200の既存モデルアーキテクチャに加え、v4専用の新アーキテクチャでも徹底的にテストされています。これにより、演算子サポートが向上し、性能、精度、対応範囲が拡大しました。さらに、このランタイムはブラウザ、サーバーサイドランタイム、デスクトップアプリケーションなど、多様なJavaScript環境で同一のコードを動作可能にします。つまり、Node.js、Bun、Deno上でもWebGPU加速モデルを直接実行できるようになったのです。
開発チームは、最先端のAIモデルをブラウザ上で100%ローカル実行する可能性を実証済みであり、現在はリソースが限られた環境でも可能な限り高速に動作させる「性能」に焦点を当てています。特に大規模言語モデルでは、エクスポート戦略を根本から再考し、モデルを演算子レベルで再実装することでこれを実現しました。具体的には、com.microsoft.GroupQueryAttentionやcom.microsoft.MatMulNBitsといったONNX Runtimeの貢献演算子を活用し、性能を最大化しています。例えば、com.microsoft.MultiHeadAttention演算子を採用したことで、BERT系の埋め込みモデルで約4倍の高速化を達成しました。
また、この更新により完全なオフラインサポートが可能になります。WASMファイルをブラウザにローカルキャッシュするため、初回ダウンロード後はインターネット接続なしでTransformers.jsアプリケーションを実行できます。
加えて、メジャーバージョン開発を機に、コードベースの大規模なリファクタリングも実施されました。従来はGitHubリポジトリがnpmパッケージそのものでしたが、今後はコアライブラリに依存しつつ異なる用途に対応するサブパッケージ(特定ライブラリ実装や、一部ユーザーに必須のユーティリティなど)の必要性を見据え、pnpmワークスペースを用いたモノレポ構造へ移行しました。これにより、@huggingface/transformersに依存するより小さなパッケージを、別リポジトリの管理負担なく提供できるようになります。さらに、v3で肥大化していたmodels.jsファイルの分割など、コードの保守性向上も図られています。
v4は現在プレビュー版としてnpm i @huggingface/transformers@nextでインストール可能で、正式リリースまでnextタグ下で定期的に更新される予定です。
原文を表示
Transformers.js v4 Preview: Now Available on NPM! Back to Articles Transformers.js v4 Preview: Now Available on NPM!
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!
Performance & Runtime Improvements
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. This worked well as long as the repository only exposed a single library. 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, like library-specific implementations, or smaller utilities that most users don't need but are essential for some.
That's why we converted the repository to a monorepo using pnpm workspaces. This allows us to ship smaller packages that depend on @huggingface/transformers without the overhead of maintaining separate repositories.
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, becoming increasingly difficult to maintain. For v4, we split this into smaller, focused modules with a clear distinction between utility functions, core logic, and model-specific implementations. This new structure improves readability and makes it much easier to add new models. Developers can now focus on model-specific logic without navigating through thousands of lines of unrelated code.
In v3, many Transformers.js example projects lived directly in the main repository. For v4, we've moved them to a dedicated repository, allowing us to maintain a cleaner codebase focused on the core library. This also makes it easier for users to find and contribute to examples without sifting through the main repository.
We updated the Prettier configuration and reformatted all files in the repository. This ensures consistent formatting throughout the codebase, with all future PRs automatically following the same style. No more debates about formatting... Prettier handles it all, keeping the code clean and readable for everyone.
Thanks to our new export strategy and ONNX Runtime's expanding support for custom operators, we've been able to add many new models and architectures to Transformers.js v4. These include popular models like GPT-OSS, Chatterbox, GraniteMoeHybrid, LFM2-MoE, HunYuanDenseV1, Apertus, Olmo3, FalconH1, and Youtu-LLM. Many of these required us to implement support for advanced architectural patterns, including Mamba (state-space models), Multi-head Latent Attention (MLA), and Mixture of Experts (MoE). Perhaps most importantly, these models are all compatible with WebGPU, allowing users to run them directly in the browser or server-side JavaScript environments with hardware acceleration. Stay tuned for some exciting demos showcasing these new models in action!
We've migrated our build system from Webpack to esbuild, and the results have been incredible. Build times dropped from 2 seconds
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み