Skip to content

Transformers.js V4: Native WebGPU EP, repo restructuring, and more! #1382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 49 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1f1c645
Move adaptive retrieval demo
xenova Dec 23, 2024
363aefa
Move code completion demo
xenova Dec 23, 2024
6c96600
Move florence-2 demo
xenova Dec 23, 2024
c4b3a76
Move depth anything demo
xenova Dec 23, 2024
29bdc5b
Move tokenizer playground demo
xenova Dec 23, 2024
98958ff
Move node audio processing demo
xenova Dec 23, 2024
ac5b758
Move remove background web demo
xenova Dec 23, 2024
b3ac89e
Move webgpu whisper demo
xenova Dec 23, 2024
48b46d6
Move depth estimation video demo
xenova Dec 23, 2024
a361b38
Move vanilla js demo
xenova Dec 23, 2024
1634399
Move node demo
xenova Dec 23, 2024
4f7b7f4
Move whisper word timestamps demo
xenova Dec 23, 2024
b0ac200
Move musicgen web demo
xenova Dec 23, 2024
4ccb405
Move cross encoder demo
xenova Dec 23, 2024
bc006e5
Move text-to-speech client demo
xenova Dec 23, 2024
7cdea27
Move video object detection demo
xenova Dec 23, 2024
b053db2
Move video background removal demo
xenova Dec 23, 2024
eacdbd1
Move Segment Anything demo
xenova Dec 23, 2024
e890716
Move zero-shot classification demo
xenova Dec 23, 2024
1ee3d46
Move browser extension template
xenova Dec 23, 2024
56297b0
Move semantic image search demo
xenova Dec 23, 2024
97a3c48
Move semantic audio search demo
xenova Dec 24, 2024
0bf2fec
Move webgpu embedding benchmark demo
xenova Jan 15, 2025
c033537
Merge branch 'main' into move-examples
xenova Apr 9, 2025
e20167a
Merge branch 'main' into move-examples
xenova Apr 16, 2025
c6b7edf
Upgrade to new WebGPU EP
xenova Jul 30, 2025
140f106
Merge branch 'main' into v4
xenova Jul 30, 2025
bf12225
Upgrade sharp version
xenova Jul 30, 2025
5e2c942
Bump versions
xenova Jul 30, 2025
9f9f6f2
Delete gh-pages.yml
xenova Jul 30, 2025
ee2f0b4
Move next-server and next-client examples
xenova Jul 30, 2025
c755653
Move react-translator demo
xenova Jul 30, 2025
3913313
Remove old demo site example
xenova Jul 30, 2025
08b3391
Move webgpu-chat demo to phi-3.5-webgpu
xenova Jul 30, 2025
5ecbb85
Remove old server-side semantic image search demo
xenova Jul 30, 2025
0cfda75
Move electron example app
xenova Jul 31, 2025
18d675f
Move webgpu clip demo app
xenova Jul 31, 2025
e8151c5
Replace webgpu-vlm demo
xenova Jul 31, 2025
64a0836
Folder no longer exists
xenova Jul 31, 2025
5979250
Remove examples table, replacing with link to new examples repo
xenova Jul 31, 2025
3204661
Rename files
xenova Jul 31, 2025
32017ae
Merge branch 'main' into move-examples
xenova Jul 31, 2025
a2b00c0
Merge branch 'move-examples' into v4
xenova Jul 31, 2025
0c76a03
Update .prettierrc
xenova Jul 31, 2025
05df971
Apply to js, mjs, and cjs
xenova Jul 31, 2025
2a32dc0
Format source code
xenova Jul 31, 2025
276f3e7
Update .prettierrc
xenova Jul 31, 2025
3c7cf47
Formatting
xenova Jul 31, 2025
3b4f4c4
Fix type issues
xenova Jul 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
60 changes: 0 additions & 60 deletions .github/workflows/gh-pages.yml

This file was deleted.

1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
.github
dist
docs
examples
scripts
types
*.md
25 changes: 17 additions & 8 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
{
"overrides": [
{
"files": ["tests/**/*.js"],
"options": {
"printWidth": 10000000
}
}
]
"overrides": [
{
"files": ["src/**/*.{js,mjs,cjs}"],
"options": {
"singleQuote": true,
"tabWidth": 4,
"printWidth": 120
}
},
{
"files": ["tests/**/*.{js,mjs,cjs}"],
"options": {
"tabWidth": 2,
"printWidth": 10000000
}
}
]
}
27 changes: 3 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ npm i @huggingface/transformers
Alternatively, you can use it in vanilla JS, without any bundler, by using a CDN or static hosting. For example, using [ES Modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules), you can import the library with:
```html
<script type="module">
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.0';
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.0.0-alpha.0';
</script>
```

Expand Down Expand Up @@ -126,36 +126,15 @@ const pipe = await pipeline('sentiment-analysis', 'Xenova/distilbert-base-uncase
});
```

Ready to dive in? Explore our wide variety of demo applications and templates [here](https://github.com/huggingface/transformers.js-examples). You can also launch your own project instantly using the official Transformers.js [template](https://huggingface.co/new-space?template=static-templates%2Ftransformers.js) on Hugging Face!

## Examples

Want to jump straight in? Get started with one of our sample applications/templates, which can be found [here](https://github.com/huggingface/transformers.js-examples).

| Name | Description | Links |
|-------------------|----------------------------------|-------------------------------|
| Whisper Web | Speech recognition w/ Whisper | [code](https://github.com/xenova/whisper-web), [demo](https://huggingface.co/spaces/Xenova/whisper-web) |
| Doodle Dash | Real-time sketch-recognition game | [blog](https://huggingface.co/blog/ml-web-games), [code](https://github.com/xenova/doodle-dash), [demo](https://huggingface.co/spaces/Xenova/doodle-dash) |
| Code Playground | In-browser code completion website | [code](https://github.com/huggingface/transformers.js/tree/main/examples/code-completion/), [demo](https://huggingface.co/spaces/Xenova/ai-code-playground) |
| Semantic Image Search (client-side) | Search for images with text | [code](https://github.com/huggingface/transformers.js/tree/main/examples/semantic-image-search-client/), [demo](https://huggingface.co/spaces/Xenova/semantic-image-search-client) |
| Semantic Image Search (server-side) | Search for images with text (Supabase) | [code](https://github.com/huggingface/transformers.js/tree/main/examples/semantic-image-search/), [demo](https://huggingface.co/spaces/Xenova/semantic-image-search) |
| Vanilla JavaScript | In-browser object detection | [video](https://scrimba.com/scrim/cKm9bDAg), [code](https://github.com/huggingface/transformers.js/tree/main/examples/vanilla-js/), [demo](https://huggingface.co/spaces/Scrimba/vanilla-js-object-detector) |
| React | Multilingual translation website | [code](https://github.com/huggingface/transformers.js/tree/main/examples/react-translator/), [demo](https://huggingface.co/spaces/Xenova/react-translator) |
| Text to speech (client-side) | In-browser speech synthesis | [code](https://github.com/huggingface/transformers.js/tree/main/examples/text-to-speech-client/), [demo](https://huggingface.co/spaces/Xenova/text-to-speech-client) |
| Browser extension | Text classification extension | [code](https://github.com/huggingface/transformers.js/tree/main/examples/extension/) |
| Electron | Text classification application | [code](https://github.com/huggingface/transformers.js/tree/main/examples/electron/) |
| Next.js (client-side) | Sentiment analysis (in-browser inference) | [code](https://github.com/huggingface/transformers.js/tree/main/examples/next-client/), [demo](https://huggingface.co/spaces/Xenova/next-example-app) |
| Next.js (server-side) | Sentiment analysis (Node.js inference) | [code](https://github.com/huggingface/transformers.js/tree/main/examples/next-server/), [demo](https://huggingface.co/spaces/Xenova/next-server-example-app) |
| Node.js | Sentiment analysis API | [code](https://github.com/huggingface/transformers.js/tree/main/examples/node/) |
| Demo site | A collection of demos | [code](https://github.com/huggingface/transformers.js/tree/main/examples/demo-site/), [demo](https://huggingface.github.io/transformers.js/) |

Check out the Transformers.js [template](https://huggingface.co/new-space?template=static-templates%2Ftransformers.js) on Hugging Face to get started in one click!


## Custom usage



By default, Transformers.js uses [hosted pretrained models](https://huggingface.co/models?library=transformers.js) and [precompiled WASM binaries](https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.0/dist/), which should work out-of-the-box. You can customize this as follows:
By default, Transformers.js uses [hosted pretrained models](https://huggingface.co/models?library=transformers.js) and [precompiled WASM binaries](https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.0.0-alpha.0/dist/), which should work out-of-the-box. You can customize this as follows:

### Settings

Expand Down
11 changes: 3 additions & 8 deletions docs/scripts/build_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@

{quick_tour}

## Examples

{examples}

## Custom usage

{custom_usage}
Expand All @@ -57,10 +53,9 @@
intro='./docs/snippets/0_introduction.snippet',
quick_tour='./docs/snippets/1_quick-tour.snippet',
installation='./docs/snippets/2_installation.snippet',
examples='./docs/snippets/3_examples.snippet',
custom_usage='./docs/snippets/4_custom-usage.snippet',
tasks='./docs/snippets/5_supported-tasks.snippet',
models='./docs/snippets/6_supported-models.snippet',
custom_usage='./docs/snippets/3_custom-usage.snippet',
tasks='./docs/snippets/4_supported-tasks.snippet',
models='./docs/snippets/5_supported-models.snippet',
)

DOCS_BASE_URL = 'https://huggingface.co/docs/transformers.js'
Expand Down
3 changes: 3 additions & 0 deletions docs/snippets/1_quick-tour.snippet
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ const pipe = await pipeline('sentiment-analysis', 'Xenova/distilbert-base-uncase
dtype: 'q4',
});
```

Ready to dive in? Explore our wide variety of demo applications and templates [here](https://github.com/huggingface/transformers.js-examples). You can also launch your own project instantly using the official Transformers.js [template](https://huggingface.co/new-space?template=static-templates%2Ftransformers.js) on Hugging Face!

2 changes: 1 addition & 1 deletion docs/snippets/2_installation.snippet
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ npm i @huggingface/transformers
Alternatively, you can use it in vanilla JS, without any bundler, by using a CDN or static hosting. For example, using [ES Modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules), you can import the library with:
```html
<script type="module">
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.0';
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.0.0-alpha.0';
</script>
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


By default, Transformers.js uses [hosted pretrained models](https://huggingface.co/models?library=transformers.js) and [precompiled WASM binaries](https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.0/dist/), which should work out-of-the-box. You can customize this as follows:
By default, Transformers.js uses [hosted pretrained models](https://huggingface.co/models?library=transformers.js) and [precompiled WASM binaries](https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.0.0-alpha.0/dist/), which should work out-of-the-box. You can customize this as follows:

### Settings

Expand Down
20 changes: 0 additions & 20 deletions docs/snippets/3_examples.snippet

This file was deleted.

2 changes: 1 addition & 1 deletion docs/source/custom_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

<include>
{
"path": "../snippets/4_custom-usage.snippet"
"path": "../snippets/3_custom-usage.snippet"
}
</include>
4 changes: 2 additions & 2 deletions docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ You can refine your search by selecting the task you're interested in (e.g., [te

<include>
{
"path": "../snippets/5_supported-tasks.snippet"
"path": "../snippets/4_supported-tasks.snippet"
}
</include>


<include>
{
"path": "../snippets/6_supported-models.snippet"
"path": "../snippets/5_supported-models.snippet"
}
</include>
2 changes: 1 addition & 1 deletion docs/source/pipelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,6 @@ If you would like more control over the inference process, you can use the [`Aut

<include>
{
"path": "../snippets/5_supported-tasks.snippet"
"path": "../snippets/4_supported-tasks.snippet"
}
</include>
20 changes: 0 additions & 20 deletions examples/adaptive-retrieval/.eslintrc.cjs

This file was deleted.

24 changes: 0 additions & 24 deletions examples/adaptive-retrieval/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions examples/adaptive-retrieval/index.html

This file was deleted.

Loading
Loading