Skip to content

Commit

Permalink
Support to load ONNX APIs based on JS runtime (#947)
Browse files Browse the repository at this point in the history
* Add support for global `onnxruntime`

- Allows custom JS runtimes to expose their own ONNX API.

* Update onnx.js

---------

Co-authored-by: Joshua Lochner <[email protected]>
  • Loading branch information
kallebysantos and xenova authored Sep 30, 2024
1 parent fe51609 commit b518866
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/backends/onnx.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ const supportedDevices = [];
/** @type {ONNXExecutionProviders[]} */
let defaultDevices;
let ONNX;
if (apis.IS_NODE_ENV) {
const ORT_SYMBOL = Symbol.for('onnxruntime');

if (ORT_SYMBOL in globalThis) {
// If the JS runtime exposes their own ONNX runtime, use it
ONNX = globalThis[ORT_SYMBOL];

} else if (apis.IS_NODE_ENV) {
ONNX = ONNX_NODE.default ?? ONNX_NODE;

// Updated as of ONNX Runtime 1.18.0
Expand Down

0 comments on commit b518866

Please sign in to comment.