After more than a year of development, we're excited to announce the release of 🤗 Transformers.js v3!
You can get started by installing Transformers.js v3 from NPM using:. (Related: Fine-Tune XLSR-Wav2Vec2 for low-resource ASR with 🤗 Tra...)
Then, importing the library with.
For more information, check out the documentation.
Recent findings suggest that webGPU is a new web standard for accelerated graphics and compute. The API enables web developers to use the underlying system's GPU to carry out high-performance computations directly in the browser. WebGPU is the successor to WebGL and provides significantly better performance, because it allows for more direct interaction with modern GPUs. Lastly, it supports general-purpose GPU computations, which makes it just perfect for machine learning! (Related: Director of Machine Learning Insights...)
As of October 2024, global WebGPU support is around 70% (according to caniuse.com), meaning some users may not be able to use the API.
If the following demos do not work in your browser, you may need to enable it using a feature flag:.
Thanks to our collaboration with ONNX Runtime Web, enabling WebGPU acceleration is as simple as setting device: 'webgpu' when loading a model. Let's see some examples!
Example: Compute text embeddings on WebGPU (demo).
Example: Perform automatic speech recognition with OpenAI whisper on WebGPU (demo).
Example: Perform image classification with MobileNetV4 on WebGPU (demo).
Sources indicate that before Transformers.js v3, we used the quantized option to specify whether to use a quantized (q8) or full-precision (fp32) variant of the model by setting quantized to true or false, respectively. Now, we've added the ability to select from a much larger list with the dtype parameter.
The list of available quantizations depends on the model, but some common ones are: full-precision ("fp32"), half-precision ("fp16"), 8-bit ("q8", "int8", "uint8"), and 4-bit ("q4", "bnb4", "q4f16").
(e.g., mixedbread-ai/mxbai-embed-xsmall-v1).
Example: Run Qwen2.5-0.5B-Instruct in 4-bit quantization (demo).
According to recent reports, some encoder-decoder models, like Whisper or Florence-2, are extremely sensitive to quantization settings: especially of the encoder. For this reason, we added the ability to select per-module dtypes, which can be done by providing a mapping from module name to dtype.
Example: Run Florence-2 on WebGPU (demo).
Recent findings suggest that this release increases the total number of supported architectures to 120 (see full list), spanning a wide range of input modalities and tasks. Notable newly introduced names include: Phi-3, Gemma & Gemma 2, LLaVa, Moondream, Florence-2, MusicGen, Sapiens, Depth Pro, PyAnnote, and RT-DETR.
It has been revealed that as part of the release, we've published 25 upcoming example projects and templates, primarily focused on showcasing WebGPU support! This includes demos like Phi-3.5 WebGPU and Whisper WebGPU, as shown below.
We're in the process of moving all our example projects and demos to https://github.com/huggingface/transformers.js-examples, so stay tuned for updates on this!
As of today's release, the community has converted over 1200 models to be compatible with Transformers.js! You can find the full list of available models here.
If you'd like to convert your own models or fine-tunes, you can use our conversion script as follows:.
After uploading the generated files to the Hugging Face Hub, remember to add the transformers.js tag so others can easily find and use your model!
Transformers.js v3 is now compatible with the three most popular server-side JavaScript runtimes:.
Finally, we're delighted to announce that Transformers.js will now be published under the official Hugging Face organization on NPM as @huggingface/transformers (instead of @xenova/transformers, which was used for v1 and v2).
We've also moved the repository to the official Hugging Face organization on GitHub (https://github.com/huggingface/transformers.js), which will be our newly introduced home — come say hi! We look forward to hearing your feedback, responding to your complications, and reviewing your PRs!
It has been revealed that this is a significant milestone and we're extremely grateful to the community for helping us achieve this long-term goal! None of this would be possible without all of you… thank you! 🤗.