-
Notifications
You must be signed in to change notification settings - Fork 956
[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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 |
||
localModelPath: localModelPath, | ||
useFS: IS_FS_AVAILABLE, | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,21 @@ class PostBuildPlugin { | |
{ | ||
const src = path.join(__dirname, 'node_modules/onnxruntime-web/dist', ORT_JSEP_FILE); | ||
const dest = path.join(dist, ORT_JSEP_FILE); | ||
fs.copyFileSync(src, dest); | ||
|
||
// Transformers.js uses both onnxruntime-web and onnxruntime-node in the same package, | ||
// and the runtime we use depends on the environment (onnxruntime-web for web, onnxruntime-node for Node.js). | ||
// This means that we don't currently support using the WASM backend in Node.js, so we disable this behaviour in the JSEP file. | ||
const content = fs.readFileSync(src, 'utf8'); | ||
const updatedContent = content | ||
.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", | ||
) | ||
Comment on lines
+63
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 cc @fs-eire if you have a better idea. |
||
fs.writeFileSync(dest, updatedContent); | ||
} | ||
}); | ||
} | ||
|
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)