Repository navigation
Load onnxruntime-node only when no runtime is injected - #1814
Open
iliev-blnk wants to merge 2 commits into
Open
iliev-blnk wants to merge 2 commits into
iliev-blnk wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1813.
onnx-node.jscalledrequire('onnxruntime-node')at import time, so the bundled native binding loaded even when a runtime was injected throughglobalThis[Symbol.for('onnxruntime')]. Next to an app's own onnxruntime-node at another version, that crashes withversion `VERS_1.30.0' not found.onnx-node.jsnow exports a loader, andonnx.jscalls it only when nothing is injected. The web build's esbuild stub for./onnx-node.jsis unaffected, since that branch never runs in the browser.The old "Import order matters" comment dates from the shared ONNX registry in 2023 and no longer applies, so I removed it.
Tests
tests/onnx_node_loading.test.jsimports the package in a child process and checks whetheronnxruntime_binding.nodeends up inrequire.cache: loaded without injection, not loaded with it. The second case fails onmain. It runs in a child process becausejest.isolateModulesAsynchits "Module cache already has entry" for onnxruntime-common under ESM.pnpm test: every suite passes locally excepttests/models.test.js, which runs out of memory on my 15 GB machine onmainas well.tests/pipelines.test.jspasses 148/148 on bothmainand this branch.With #1743
On its own this gets past the crash, but then the empty device list from #1743 shows up (
Unsupported device: "cpu". Should be one of: .). With both, the repro in #1813 prints[ 1, 3, 384 ]on the app's onnxruntime-node 1.24.3. The two conflict on one line ofonnx.js; the resolution isONNX = injectedONNX ?? loadOnnxNode();.