Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7b2bdb9
Transformers.js models working in d8; WIP other shells, another model
danleh Feb 10, 2025
6d48daa
fix paths
danleh Aug 14, 2025
8bab51e
both distilbert and Whisper running in d8
danleh Feb 11, 2025
e1fc06b
cleanup dependencies, TODOs
danleh Feb 11, 2025
25bb946
make it compatible with all shells
danleh Feb 11, 2025
9ae0fb4
reuse same TextEncoder/Decoder polyfill as other wasm line item
danleh Feb 12, 2025
18b6918
WIP adapt to runner changes, new preloading code
danleh Aug 18, 2025
0e86613
Merge branch 'main' into transformersjs-rebase
danleh Aug 18, 2025
06610f5
fix both tasks, use preloading from runner/JetStream global
danleh Aug 18, 2025
abec374
fix accidentally committed dir
danleh Aug 18, 2025
1c425af
fix browser fetch with blob preloading, fix print calls
danleh Aug 19, 2025
8f14f8f
print is no longer used
danleh Aug 20, 2025
7aa469a
shorten audio clip to speed up whisper task
danleh Aug 20, 2025
f8147cd
shorten iterations for bert task
danleh Aug 20, 2025
1d122da
add output validation
danleh Aug 20, 2025
c9c67c0
polyfill performance.timeOrigin for transformersjs
danleh Aug 20, 2025
71e1ff0
update transformersjs dependency to latest
danleh Aug 20, 2025
f3bcfb4
cleanup, rebuild
danleh Aug 20, 2025
fb0ab2b
fix module resolution with blob URL/preload
danleh Aug 20, 2025
65b7e97
add tag to transformersjs workloads
danleh Sep 8, 2025
28b203c
Merge branch 'main' into transformersjs-rebase
danleh Sep 9, 2025
5b5e6c5
fix duplicate TextDecoder polyfill
danleh Sep 9, 2025
6b52dad
fix new allowUtf16 test
danleh Sep 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup dependencies, TODOs
  • Loading branch information
danleh committed Aug 14, 2025
commit e1fc06bc24ac4c61bcbfd7fa556f97d041122d82
1 change: 1 addition & 0 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2098,6 +2098,7 @@ let BENCHMARKS = [
worstCaseCount: 2,
tags: ["Default", "Wasm"],
}),
// TODO: Change this to AsyncBenchmark, we don't actually need the Emscripten magic.
new WasmEMCCBenchmark({
name: "transformersjs-bert-wasm",
files: [
Expand Down
13 changes: 11 additions & 2 deletions transformersjs/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
- Two tasks: one text/NLP, one audio processing/speech-to-text.
- Everything in `build/` comes from upstream or is generated.
- Everything in `util/` is tooling for building, preparing the benchmark.
- Everything in `build/` is generated or an upstream library.
- Everything in `util/` is tooling for building and preparing the benchmark.

# Licenses

- Transformers.js: Apache 2.0, https://github.com/huggingface/transformers.js/blob/main/LICENSE
- ONNX runtime: MIT, https://github.com/microsoft/onnxruntime/blob/main/LICENSE
- `text-encoding` Polyfill: Unlicense OR Apache 2.0, https://github.com/inexorabletash/text-encoding/blob/master/LICENSE.md
- Model `DistilBERT base uncased finetuned SST-2`: Apache 2.0, https://huggingface.co/distilbert/distilbert-base-uncased-finetuned-sst-2-english
- Model `openai/whisper-tiny.en`: Apache 2.0, https://huggingface.co/openai/whisper-tiny.en
- Audio file for speech-to-text task: Public domain, https://www.jfklibrary.org/learn/about-jfk/historic-speeches/inaugural-address
6 changes: 3 additions & 3 deletions transformersjs/build.log
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Built on 2025-02-11T14:56:01Z
Built on 2025-02-11T16:17:21Z
Installing Node dependencies...

up to date, audited 153 packages in 489ms
up to date, audited 85 packages in 418ms

27 packages are looking for funding
20 packages are looking for funding
run `npm fund` for details

found 0 vulnerabilities
Expand Down
6 changes: 4 additions & 2 deletions transformersjs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ rm jfk.wav
echo "Download and run model(s)..." | tee -a "$BUILD_LOG"
# This automatically places the model files in `build/models/`.
node util/test-models.mjs
# TODO(dlehmann): Compress models with zopfli, without header.
# Uncompress/inflate with https://github.com/binji/raw-wasm/blob/main/inflate/index.html / https://github.com/binji/raw-wasm/blob/main/inflate/inflate.js

echo "Copy library files into build/..." | tee -a "$BUILD_LOG"
# TextEncoder/TextDecoder polyfill with UTF-16 LE support.
Expand All @@ -42,6 +40,10 @@ cp util/node_modules/@huggingface/transformers/dist/transformers.js build/
# TODO(dlehmann): Measure performance difference between the two.
cp util/node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.{mjs,wasm} build/lib/onnxruntime-web/

# TODO: Compress model data (and maybe Wasm modules) with zstd.
# Either decompress with native APIs available in browsers or JS/Wasm polyfill?
# E.g., https://github.com/101arrowz/fzstd or https://github.com/fabiospampinato/zstandard-wasm or https://github.com/donmccurdy/zstddec-wasm

# Cleanup node packages.
# rm -rf util/node_modules/

Expand Down
2 changes: 1 addition & 1 deletion transformersjs/task-whisper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ globalThis.initPipeline = async function(pipeline) {
return await pipeline(
'automatic-speech-recognition',
'Xenova/whisper-tiny.en',
// FIXME: The non-quantized model is faster!?
// Use quantized model because of smaller weights.
{ dtype: 'q8' }
);
}
Expand Down
Binary file removed transformersjs/ted_60_16k.wav
Binary file not shown.
3 changes: 1 addition & 2 deletions transformersjs/util/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"name": "transformersjs-wasm",
"version": "1.0.0",
"version": "0.0.1",
"author": "Daniel Lehmann <[email protected]>",
"license": "MIT",
"dependencies": {
"@huggingface/transformers": "^3.3.2",
"node-zopfli": "^2.1.4",
"text-encoding": "^0.7.0",
"wavefile": "^11.0.0"
}
Expand Down
1 change: 0 additions & 1 deletion transformersjs/util/test-models.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ globalThis.print = function(str) { console.log(str); }
console.log('Automatic speech recognition with Whisper model.');
await import('../task-whisper.js');

// TODO: We could also transcribe `ted_60_16k.wav`, but that takes quite long...
const inputAudioBuffer = readFileSync('build/inputs/jfk.raw').buffer;

let start = performance.now();
Expand Down
1 change: 1 addition & 0 deletions wasm-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ testList = [
"zlib-wasm",
"Kotlin-compose-wasm",
"transformersjs-bert-wasm",
"transformersjs-whisper-wasm",
];

// Reuse the full CLI runner, just with the subset of Wasm line items above.
Expand Down