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] Which node.js version is supposed to be supported? #18078

Open
marcelklehr opened this issue Oct 24, 2023 · 10 comments
Open

[Web] Which node.js version is supposed to be supported? #18078

marcelklehr opened this issue Oct 24, 2023 · 10 comments
Labels
platform:web issues related to ONNX Runtime web; typically submitted using template

Comments

@marcelklehr
Copy link

Describe the issue

Which Node.js versions is the current version of onnxruntime-web supposed to be compatible with?

Using node v16

worker sent an error! undefined:undefined: ortWasmThreaded is not defined

node:internal/event_target:969
  process.nextTick(() => { throw err; });
                           ^
ReferenceError [Error]: ortWasmThreaded is not defined

Using node v18 and v20

node:internal/errors:496
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_WORKER_PATH]: The worker script or module filename must be an absolute path or a relative path starting with './' or '../'. Received "blob:nodedata:0d99e392-a103-4b96-a185-cdd6b6506805"
    at new NodeError (node:internal/errors:405:5)
    at new Worker (node:internal/worker:168:15)
}

To reproduce

  1. require('onnxruntime-web')
  2. Run stable-duffusion-xl-1.0-base

Urgency

No response

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.16.1

Execution Provider

Other / Unknown

@marcelklehr marcelklehr added the platform:web issues related to ONNX Runtime web; typically submitted using template label Oct 24, 2023
@marcelklehr marcelklehr changed the title [Web] [Web] Which node.js version is supposed to be supported? Oct 24, 2023
@carzh
Copy link
Contributor

carzh commented Oct 31, 2023

node v18 should work, but my understanding is that not all browsers + platforms can support ort-web multithreading. If you are running in Node, the onnxruntime-node package should be used. Could you provide more details on reproducing the issue such as what browser + what commands you are using to launch?

@marcelklehr
Copy link
Author

If you are running in Node, the onnxruntime-node package should be used

I want to use onnxruntime-web / WASM as a fallback for machines that are not running on x86, since onnxruntime-node only works on x86

Could you provide more details on reproducing the issue such as what browser + what commands you are using to launch?

I'm running in node, see above. Specifically, I'm running this file ( https://github.com/nextcloud/text2image_stablediffusion/blob/main/src/stablediffusion.mjs ) with onnxruntime-web instead of onnxruntime-node. My understanding is that it should be possible to simply switch out the import statement and it should work.

@carzh
Copy link
Contributor

carzh commented Nov 1, 2023

Hello, where did you see that onnxruntime-node only works on x86 & that it would be possible to swap out the import statements? The npm registry package page indicates that onnxruntime-node supports x64.

Since there is a "node" export in onnxruntime-web's package.json, it does look like onnxruntime-web can work in Node, but it looks like from the build script that the node export is built with multithreading disabled.

You can try a custom build (modify the DISABLE_WASM_THREAD boolean to true for the ort.node.min.js build and then follow these build instructions), but I'm not sure if multithreading in onnxruntime-web in Node is supported yet.

@fs-eire
Copy link
Contributor

fs-eire commented Nov 7, 2023

onnxruntime-node should have supported win/linux/mac on x64/arm64. @marcelklehr what exact OS/platform are you using?

@marcelklehr
Copy link
Author

I can only use pre-built binaries

Following platforms are supported with pre-built binaries:

Windows x64 CPU NAPI_v3
Linux x64 CPU NAPI_v3
MacOS x64 CPU NAPI_v3

I'd like to use it on ARM and on machines that don't have glibc.

On npm it is stated that onnxruntime-web supports node: https://www.npmjs.com/package/onnxruntime-web#compatibility

@fs-eire
Copy link
Contributor

fs-eire commented Nov 8, 2023

Seems like the document is out of date.

Currently we support 6: Win x64, Win Arm64, Linux x64, Linux Arm64, Mac x64 and Mac arm64

You can check from a CDN (eg. https://www.jsdelivr.com/package/npm/onnxruntime-node?tab=files&path=bin%2Fnapi-v3%2Fwin32) for the subfolder of "bin"

@fs-eire
Copy link
Contributor

fs-eire commented Nov 8, 2023

I'd like to use it on ARM and on machines that don't have glibc.

I see... I think ONNX Runtime itself may not support this but I am not sure. Are you able to use a docker in your environment?

@marcelklehr
Copy link
Author

Are you able to use a docker in your environment?

No, that's the reason I'm looking for WASM support on node.js

@gowy222
Copy link

gowy222 commented Jan 2, 2024

@marcelklehr

onnxruntime-node

not MATTER with node version,
FROM node:lts-slim AS base will works. (x86_64 and arm64 both work!)
docker buildx build --platform linux/arm64
(must be slim!!! GUN C lib -> GLIBC ISSUE! )

@fs-eire
Copy link
Contributor

fs-eire commented Jan 2, 2024

WASM works on Node.js only when disabling the multi-thread features. They depends on creating web workers on Blob URL which is not supported in node.js

mnvr added a commit to ente-io/ente that referenced this issue Apr 10, 2024
Fixes #1374

A customer reported that the app fails to run on Windows ARM. The error is
coming when trying to load ONNX.

ONNX runtime supports Windows ARM, e.g. see
- https://www.jsdelivr.com/package/npm/onnxruntime-node?tab=files&path=bin%2Fnapi-v3%2Fwin32
- microsoft/onnxruntime#18078

The issue then seems to be that we're not actually building for Windows ARM. I'm
not sure about this (don't have a Windows ARM machine at hand), but my theory is
that since we don't ask Electron Builder to build for win arm64, it doesn't copy
the corresponding ONNX binary into the generated bundle.

Other refs:
- https://www.electron.build/cli.html
mnvr added a commit to ente-io/ente that referenced this issue Apr 10, 2024
Fixes #1374

A customer reported that the app fails to run on Windows ARM. The error
is coming when trying to load ONNX.

ONNX runtime supports Windows ARM, e.g. see
-
https://www.jsdelivr.com/package/npm/onnxruntime-node?tab=files&path=bin%2Fnapi-v3%2Fwin32
- microsoft/onnxruntime#18078

The issue then seems to be that we're not actually building for Windows
ARM. I'm not sure about this (don't have a Windows ARM machine at hand),
but my theory is that since we don't ask Electron Builder to build for
win arm64, it doesn't copy the corresponding ONNX binary into the
generated bundle.

Other refs:
- https://www.electron.build/cli.html
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

4 participants