Electron + Webpack + Transformers.js: Tensor.data must be a typed array for numeric tensor

Hello :wave:

I’m trying to integrate transformers.js into my Electron Forge app to run the pipeline on the main process (not the renderer).

I’ve copy-pasted the example code from the electron example in the Transformers.js Repo.

Here’s a minimalist version of my project that demonstrates the problem. Just run npm i && npm run start and look at the node output.

When running the pipeline I’m getting the following error:

removing requested execution provider "wasm" from session options because it is not available: backend not found.
An error occurred during model execution: "TypeError: Tensor.data must be a typed array for numeric tensor.".
Inputs given to model: [Object: null prototype] {
  input_ids: Tensor {
    dims: [ 1, 3 ],
    type: 'int64',
    data: undefined,
    size: 3,
    cpuData: BigInt64Array(3) [ 101n, 7592n, 102n ],
    dataLocation: 'cpu'
  },
  attention_mask: Tensor {
    dims: [ 1, 3 ],
    type: 'int64',
    data: undefined,
    size: 3,
    cpuData: BigInt64Array(3) [ 1n, 1n, 1n ],
    dataLocation: 'cpu'
  }
}
Error occurred in handler for 'run-ai': TypeError: Tensor.data must be a typed array for numeric tensor.
    at Immediate.<anonymous> (C:\path\to\project\transformers-test-project\node_modules\onnxruntime-node\dist\backend.js:45:108)
    at process.processImmediate (node:internal/timers:476:21)

The biggest difference between my project and the example project is, that I use webpack to bundle the code - I could imagine it’s a config issue.
It looks like it downloads the model fine, it just crashes when running the pipeline.

I’m on Windows 11
Nodejs v18.19.1

I appreciate any help!
HF beginner here - please forgive any obvious mistakes.

1 Like

Hi! Did you end up fixing it? I’m currently stuck with the same problem!

I did, got some help in the HF Discord.
For me the problem was that I installed the wrong version of onnxruntime.
After installing the same version that’s specified in package-lock.json as a dep of transformers.js, it worked flawlessly.

So, to fix it:

  • install transformers.js, but not onnxruntime
  • look at the onnxruntime version in package-lock.json (ctrl+f onnxruntime)
  • install that version of onnxruntime

It worked like a charm! TYSM!

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.