Open jlucaso1 opened 1 week ago
Thank you for reporting this issue. since navigator.gpu
is supported in deno, it should work. could you share me reproduce steps (or a repo) so that I can debug it?
@fs-eire Try the following:
import { InferenceSession } from "npm:onnxruntime-web";
await InferenceSession.create(
"https://huggingface.co/briaai/RMBG-1.4/resolve/main/onnx/model_quantized.onnx",
{
executionProviders: ["webgpu"],
}
);
I'm using deno 2.0.0-rc.10, but deno stable version get the same error.
I am not sure about this “npm:onnxruntime-web” syntax. In a nodejs based web app project I used “onnxruntime-web/webgpu” (“webgpu” is the export name that defined in package.json). If I just import “onnxruntime-web” it doesn’t load webgpu support.
@fs-eire I understand.
I got a different error when i use import { InferenceSession } from "npm:onnxruntime-web/webgpu";
on stable versions of Deno:
failed to asynchronously prepare wasm: both async and sync fetching of the wasm failed
Aborted(both async and sync fetching of the wasm failed)
error: Uncaught (in promise) Error: no available backend found. ERR: [webgpu] RuntimeError: Aborted(both async and sync fetching of the wasm failed). Build with -sASSERTIONS for more info.
The release candidate version of Deno throw the same error:
error: Uncaught (in promise) Error: no available backend found. ERR: [webgpu] backend not found.
at resolveBackendAndExecutionProviders (file:///run/media/jlucaso/secondary/projects/webgpu/node_modules/.deno/onnxruntime-common@1.19.2/node_modules/onnxruntime-common/dist/esm/backend-impl.js:120:15)
at async Function.create (file:///run/media/jlucaso/secondary/projects/webgpu/node_modules/.deno/onnxruntime-common@1.19.2/node_modules/onnxruntime-common/dist/esm/inference-session-impl.js:180:52)
It seems that Emscripten does not have well support for Deno. The generated javascript glue file didn't work well in Deno:
var ENVIRONMENT_IS_WEB = typeof window == "object";
var ENVIRONMENT_IS_WORKER = typeof importScripts == "function";
var ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";
var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
There is no special treatment for Deno so further operation may be unexpected.
Loading from file URL is explicitly disallowed:
if (isFileURI(wasmBinaryFile)) {
err(`warning: Loading from a file URI (${wasmBinaryFile}) is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing`);
}
Update: OK I hacked the Emscripten glue JS and finally get into Deno's webgpu. And now I am blocked with a bug in Deno's webgpu implementation:
adapter.limits.maxBufferSize
's value is 18446744073709551615n
. This is not expected (adapter.limits.maxBufferSize should be number
but not BigInt
) and will cause an error later:
Cannot convert a BigInt value to a number
link to the issue: https://github.com/denoland/deno/issues/22029
I don't know why maxBufferSize
on my devbox is bigint. will later change to a different machine and try.
changed another PC and the value of maxBufferSize
is still 18446744073709551615n
.
According to the WebGPU spec, maxBufferSize
is an unsigned long long
, so I believe returning a BigInt
is correct.
In google chrome adapter.limits.maxBufferSize
returns a number:
adapter.limits.maxBufferSize
2147483648
typeof adapter.limits.maxBufferSize
'number'
Chrome: 129.0.6668.100 OS: Linux
I am not sure about the details but at least the implementation of Deno WebGPU is incorrect.
It maxBufferSize
is considered to be number
, then adapter.limits.maxBufferSize
being bigint
is incorrect.
It maxBufferSize
is considered to be bigint
, then using it in adapter.requestDevice( { requiredLimits : { maxBufferSize: adapter.limits.maxBufferSize }})
should not run into error Cannot convert a BigInt value to a number
.
@fs-eire what deno version you tested early?
I'm using deno 2.0.0 stable and getting a normal number in adapter.limits.maxBufferSize
const adapter = await navigator.gpu.requestAdapter();
console.log(adapter?.limits.maxBufferSize); // 2147483647
const device = await adapter?.requestDevice( { requiredLimits : { maxBufferSize: adapter.limits.maxBufferSize! }})
console.log(device) // GPUDevice with no error
I tried both 1.46.3 and 2.0.0
deno repl --unstable-webgpu
Deno 1.46.3
exit using ctrl+d, ctrl+c, or close()
> const adapter = await navigator.gpu.requestAdapter();
undefined
> console.log(adapter?.limits.maxBufferSize);
18446744073709551615n
undefined
deno repl --unstable-webgpu
Deno 2.0.0
exit using ctrl+d, ctrl+c, or close()
> const adapter = await navigator.gpu.requestAdapter();
undefined
> console.log(adapter?.limits.maxBufferSize);
18446744073709551615n
undefined
>
Describe the feature request
Support to running onnx models in webgpu using deno
Describe scenario use case
Actually not working because this error:
error: Uncaught (in promise) Error: no available backend found. ERR: [webgpu] backend not found.
Debug
console.log(await navigator.gpu.requestAdapter())