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
WIP adapt to runner changes, new preloading code
  • Loading branch information
danleh committed Aug 18, 2025
commit 18b6918b61ee16bfe193d7aa9eeef6474807b83d
50 changes: 26 additions & 24 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2098,15 +2098,16 @@ let BENCHMARKS = [
worstCaseCount: 2,
tags: ["Default", "Wasm"],
}),
// TODO: Change this to AsyncBenchmark, we don't actually need the Emscripten magic.
new WasmEMCCBenchmark({
new AsyncBenchmark({
name: "transformersjs-bert-wasm",
files: [
"./polyfills/fast-text-encoding-1.0.3/text.js",
"./transformersjs/benchmark.js",
"./transformersjs/task-bert.js",
],
preload: {
transformersJsModule: "./transformersjs/build/transformers.js",

// TODO: Remove the duplication here and in `task-*.js` `preloadFiles`.
// Probably by adding a new category of files that are just provided by filename.
wasmBinary: "./transformersjs/build/onnxruntime-web/ort-wasm-simd-threaded.wasm",
Expand All @@ -2118,28 +2119,29 @@ let BENCHMARKS = [
iterations: 50,
tags: ["Default", "Wasm"],
}),
new WasmEMCCBenchmark({
name: "transformersjs-whisper-wasm",
files: [
"./polyfills/fast-text-encoding-1.0.3/text.js",
"./transformersjs/benchmark.js",
"./transformersjs/task-whisper.js",
],
preload: {
wasmBinary: "./transformersjs/build/onnxruntime-web/ort-wasm-simd-threaded.wasm",
modelEncoderWeights: "./transformersjs/build/models/Xenova/whisper-tiny.en/onnx/encoder_model_quantized.onnx",
modelDecoderWeights: "./transformersjs/build/models/Xenova/whisper-tiny.en/onnx/decoder_model_merged_quantized.onnx",
modelConfig: "./transformersjs/build/models/Xenova/whisper-tiny.en/config.json",
modelTokenizer: "./transformersjs/build/models/Xenova/whisper-tiny.en/tokenizer.json",
modelTokenizerConfig: "./transformersjs/build/models/Xenova/whisper-tiny.en/tokenizer_config.json",
modelPreprocessorConfig: "./transformersjs/build/models/Xenova/whisper-tiny.en/preprocessor_config.json",
modelGenerationConfig: "./transformersjs/build/models/Xenova/whisper-tiny.en/generation_config.json",
inputFile: "./transformersjs/build/inputs/jfk.raw",
},
iterations: 5,
worstCaseCount: 1,
testGroup: WasmGroup
}),
// TODO: Change this to AsyncBenchmark, we don't actually need the Emscripten magic.
// new WasmEMCCBenchmark({
// name: "transformersjs-whisper-wasm",
// files: [
// "./polyfills/fast-text-encoding-1.0.3/text.js",
// "./transformersjs/benchmark.js",
// "./transformersjs/task-whisper.js",
// ],
// preload: {
// wasmBinary: "./transformersjs/build/onnxruntime-web/ort-wasm-simd-threaded.wasm",
// modelEncoderWeights: "./transformersjs/build/models/Xenova/whisper-tiny.en/onnx/encoder_model_quantized.onnx",
// modelDecoderWeights: "./transformersjs/build/models/Xenova/whisper-tiny.en/onnx/decoder_model_merged_quantized.onnx",
// modelConfig: "./transformersjs/build/models/Xenova/whisper-tiny.en/config.json",
// modelTokenizer: "./transformersjs/build/models/Xenova/whisper-tiny.en/tokenizer.json",
// modelTokenizerConfig: "./transformersjs/build/models/Xenova/whisper-tiny.en/tokenizer_config.json",
// modelPreprocessorConfig: "./transformersjs/build/models/Xenova/whisper-tiny.en/preprocessor_config.json",
// modelGenerationConfig: "./transformersjs/build/models/Xenova/whisper-tiny.en/generation_config.json",
// inputFile: "./transformersjs/build/inputs/jfk.raw",
// },
// iterations: 5,
// worstCaseCount: 1,
// testGroup: WasmGroup
// }),
new WasmLegacyBenchmark({
name: "tfjs-wasm",
files: [
Expand Down
96 changes: 49 additions & 47 deletions transformersjs/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,62 +50,64 @@ class Benchmark {
inputFile;

async init() {
// The generated JavaScript code from dart2wasm is an ES module, which we
// can only load with a dynamic import (since this file is not a module.)
// TODO: Support ES6 modules in the driver instead of this one-off solution.
// This probably requires a new `Benchmark` field called `modules` that
// is a map from module variable name (which will hold the resulting module
// namespace object) to relative module URL, which is resolved in the
// `preRunnerCode`, similar to this code here.
if (isInBrowser) {
// In browsers, relative imports don't work since we are not in a module.
// (`import.meta.url` is not defined.)
this.transformersJsModule = await import(location.origin + "/transformersjs/build/transformers.js");
} else {
// In shells, relative imports require different paths, so try with and
// without the "./" prefix (e.g., JSC requires it).
try {
this.transformersJsModule = await import("transformersjs/build/transformers.js");
} catch {
this.transformersJsModule = await import("./transformersjs/build/transformers.js");
}
}
this.transformersJsModule = await dynamicImport(globalThis.JetStream.transformersJsModule);

preload = preloadFiles(Module);
// // The generated JavaScript code from dart2wasm is an ES module, which we
// // can only load with a dynamic import (since this file is not a module.)
// // TODO: Support ES6 modules in the driver instead of this one-off solution.
// // This probably requires a new `Benchmark` field called `modules` that
// // is a map from module variable name (which will hold the resulting module
// // namespace object) to relative module URL, which is resolved in the
// // `preRunnerCode`, similar to this code here.
// if (isInBrowser) {
// // In browsers, relative imports don't work since we are not in a module.
// // (`import.meta.url` is not defined.)
// this.transformersJsModule = await import(location.origin + "/transformersjs/build/transformers.js");
// } else {
// // In shells, relative imports require different paths, so try with and
// // without the "./" prefix (e.g., JSC requires it).
// try {
// this.transformersJsModule = await import("transformersjs/build/transformers.js");
// } catch {
// this.transformersJsModule = await import("./transformersjs/build/transformers.js");
// }
// }

if (Module.inputFile) {
this.inputFile = Module.inputFile.buffer;
}
// preload = preloadFiles(Module);

// if (Module.inputFile) {
// this.inputFile = Module.inputFile.buffer;
// }
}

async runIteration() {
if (!this.pipeline) {
// TODO: Profile startup only: What is taking so much time here?
let { env, pipeline } = this.transformersJsModule;
// if (!this.pipeline) {
// // TODO: Profile startup only: What is taking so much time here?
// let { env, pipeline } = this.transformersJsModule;

env.localModelPath = 'build/models/';
env.allowRemoteModels = false;
// env.localModelPath = 'build/models/';
// env.allowRemoteModels = false;

// Single-threaded only for now, since we cannot spawn workers in shells.
// TODO: Implement sufficiently powerful workers in shells (or provide
// polyfills).
env.backends.onnx.wasm.numThreads = 1;
// // Single-threaded only for now, since we cannot spawn workers in shells.
// // TODO: Implement sufficiently powerful workers in shells (or provide
// // polyfills).
// env.backends.onnx.wasm.numThreads = 1;

// Either specify path prefix, but this loads the JSEP build by default.
// env.backends.onnx.wasm.wasmPaths = 'build/onnxruntime-web/';
// So instead, give the ONNX runtime files directly:
env.backends.onnx.wasm.wasmPaths = {
mjs: './onnxruntime-web/ort-wasm-simd-threaded.mjs',
wasm: 'ort-wasm-simd-threaded.wasm',
};
// Finally, this would be our preferred option: Giving the Wasm binary
// directly, such that we don't have to intercept `instantiateStreaming`,
// but see above.
// env.backends.onnx.wasm.wasmBinary = ...
// // Either specify path prefix, but this loads the JSEP build by default.
// // env.backends.onnx.wasm.wasmPaths = 'build/onnxruntime-web/';
// // So instead, give the ONNX runtime files directly:
// env.backends.onnx.wasm.wasmPaths = {
// mjs: './onnxruntime-web/ort-wasm-simd-threaded.mjs',
// wasm: 'ort-wasm-simd-threaded.wasm',
// };
// // Finally, this would be our preferred option: Giving the Wasm binary
// // directly, such that we don't have to intercept `instantiateStreaming`,
// // but see above.
// // env.backends.onnx.wasm.wasmBinary = ...

this.pipeline = await initPipeline(pipeline);
}
// this.pipeline = await initPipeline(pipeline);
// }

await doTask(this.pipeline, this.inputFile);
// await doTask(this.pipeline, this.inputFile);
}
}
1 change: 1 addition & 0 deletions wasm/j2cl-box2d/j2cl
Submodule j2cl added at 506db3