huggingface/transformers.js

transformers.js 3.0.2 not compatible with onnxruntime-web 1.20.0

Opened this issue · 1 comments

System Info

transformers.js: 3.0.2
chrome: 130
OS: macos

Environment/Platform

  • Website/web-app
  • Browser extension
  • Server-side (e.g., Node.js, Deno, Bun)
  • Desktop app (e.g., Electron)
  • Other (e.g., VSCode extension)

Description

I am trying to run rather simple automatic-speech-recognition model with onnxruntime-web v1.20.0 in a browser, witch fails in runtime with:

bug.mjs:5462 Uncaught (in promise) TypeError: yn[s] is not a function
    at ip (bug.mjs:5462:61)
    at ort-wasm-simd-threaded.jsep.wasm:0x7f697f
    at I.<computed> (bug.mjs:5679:28)
    at ar (bug.mjs:4926:45)
    at Qi (bug.mjs:5715:135)
    at s (bug.mjs:5718:19)
    at Do (bug.mjs:4576:26)
    at bug.mjs:5659:23

Reproduction

bug.src.mjs

import { env, pipeline } from "@huggingface/transformers";

env.allowLocalModels = false;
env.backends.onnx.wasm.numThreads = 1;
env.backends.onnx.wasm.wasmPaths = "https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.20.0/";

const buffer = await (await fetch("source.pcm")).arrayBuffer();
const audio = new Float32Array(buffer);
const pipe = await pipeline("automatic-speech-recognition", "onnx-community/whisper-base",
	{dtype:{encoder_model:"fp32", decoder_model_merged:"q4"}, device:"webgpu"});
const result = await pipe(audio, {chunk_length_s:30, stride_length_s:5, return_timestamps:true, language:"en"});
console.log(result);

index.html

<script src="bug.mjs" type="module"></script>

build:

ffmpeg -to 60 -i source.mp3 -filter_complex [0:1]aformat=channel_layouts=mono,aresample=16000[aout] -map [aout] -c:a pcm_f32le -f data source.pcm
npm install --save-exact --save-dev esbuild
npm install @huggingface/transformers@3.0.2
./node_modules/.bin/esbuild bug.src.mjs --bundle --format=esm --target=esnext --outfile=bug.mjs

When wasmPaths is not defined (using default value from transformers.js v3.0.2), there is no runtime error and program completes as expected

I have the exact same error. I had to download the WASM from https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.0.2/dist/ort-wasm-simd-threaded.jsep.wasm
and replace it with the one provided inside @huggingface/transformers to get it to work