-
Notifications
You must be signed in to change notification settings - Fork 940
[WIP] Deno browser WASM/WebGPU support #1344
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
base: main
Are you sure you want to change the base?
Conversation
@@ -142,7 +142,7 @@ export const env = { | |||
remoteHost: 'https://huggingface.co/', | |||
remotePathTemplate: '{model}/resolve/{revision}/', | |||
|
|||
allowLocalModels: !(IS_BROWSER_ENV || IS_WEBWORKER_ENV), | |||
allowLocalModels: !(IS_BROWSER_ENV || IS_WEBWORKER_ENV || IS_DENO_RUNTIME), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deno doesn't support relative URLs, so this is necessary... even if we have filesystem access
.replace( | ||
`"object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node&&"renderer"!=process.type`, | ||
"false", | ||
) | ||
.replace( | ||
`typeof globalThis.process?.versions?.node == 'string'`, | ||
"false", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very hacky, but is a current workaround, otherwise we get errors related to worker_threads
not being prefixed with node:
cc @fs-eire if you have a better idea.
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
||
} else if (apis.IS_NODE_ENV) { | ||
ONNX = ONNX_NODE.default ?? ONNX_NODE; | ||
} else if (apis.IS_NODE_ENV && (ONNX = ONNX_NODE.default ?? ONNX_NODE)?.InferenceSession) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handles an edge case where it is a node-like environment (e.g., Deno), but we are running in an environment where onnxruntime-node is not bundled (but onnxruntime-wasm is)
An experimental branch/PR to test running Transformers.js in Deno's WASM and WebGPU runtimes. This is a bit hacky, but it works... at least for now!
You can test this out by building this PR, and hosting the js files locally.
NOTE: This is different to running with the native EP (#1306), which will enable WebGPU support in Deno, via ONNXRuntime's Native WebGPU EP implementation.
There are some bugs/limitations with the current runtime (based on wgpu), e.g.,
but WASM works well 👍
cc @crowlKats for viz