Skip to content
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

[Web] [Node] onnxruntime-node failing to load in workers #23790

Closed
tsekiguchi opened this issue Feb 22, 2025 · 0 comments
Closed

[Web] [Node] onnxruntime-node failing to load in workers #23790

tsekiguchi opened this issue Feb 22, 2025 · 0 comments
Labels
platform:web issues related to ONNX Runtime web; typically submitted using template

Comments

@tsekiguchi
Copy link

tsekiguchi commented Feb 22, 2025

Describe the issue

NOTE: I'm labelling with Web because there is currently no label for 'Node', but it shares the same base of 'common'.
This is specifically for an electron project.

Inferencing large amounts of data is a CPU heavy process, and should be run in a worker thread. The current onnxruntime-node package runs well in the node main process. However, when trying to use onnxruntime-node in a node worker, it cannot find the necessary backend.

Uncaught Exception:
Error: no available backend found. ERR: [cpu] backend not found.
at resolveBackendAndExecutionProviders (file:///Users/onnx-worker-error/out/main/onnx.worker-Dqm3O3Aq.js:54:11)
at async InferenceSession.create (file:///Users/onnx-worker-error/out/main/onnx.worker-Dqm3O3Aq.js:999:48)

Here's exactly how I'm implementing it:

textModel = await ort.InferenceSession.create(modelPath, {
	executionProviders: [{ name: 'cpu' }],
	graphOptimizationLevel: 'all'
});

To further add to the confusion, when using other libraries like Transformers.js, we have no problem running ONNX in a WebWorker. So it seems to be something with how node is interacting with onnxruntime.

I'm not sure why onnx isn't able to be run in a worker, and after many attempts and fails, I've been able to reproduce this bug in an example repo, and would love some help figuring out the root cause.

Thank you very very much in advance.

To reproduce

Example Repo:
https://github.com/tsekiguchi/onnx-worker-error

To install, follow the read me.

Then run npm run dev.

Use buttons to test inferencing for node and for a worker.

Urgency

Medium Urgency. I'm going to use in the main process for now, but I think it's important that ONNX runtime is capable of running in a worker.

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.20.1

Execution Provider

Other / Unknown

@tsekiguchi tsekiguchi added the platform:web issues related to ONNX Runtime web; typically submitted using template label Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:web issues related to ONNX Runtime web; typically submitted using template
Projects
None yet
Development

No branches or pull requests

1 participant