-
Notifications
You must be signed in to change notification settings - Fork 51
Upgrade onnx runtime #1764
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
Upgrade onnx runtime #1764
Changes from all commits
7c0c293
45d37d5
2b6e082
2fcf246
61ce337
2ddb683
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,7 @@ | ||
| // Copyright (C) 2022-2025 Intel Corporation | ||
| // LIMITED EDGE SOFTWARE DISTRIBUTION LICENSE | ||
|
|
||
| import type { InferenceSession } from 'onnxruntime-common'; | ||
| import * as ort from 'onnxruntime-web'; | ||
| import { env, InferenceSession } from 'onnxruntime-web'; | ||
|
|
||
| import { loadSource } from '../utils/tool-utils'; | ||
| import { SessionParameters, sessionParams } from '../utils/wasm-utils'; | ||
|
|
@@ -14,26 +13,34 @@ const loadModel = async (modelPath: string) => { | |
| export class Session { | ||
| ortSession: InferenceSession | undefined; | ||
| params: SessionParameters; | ||
| private runQueue: Promise<void> = Promise.resolve(); | ||
|
|
||
| constructor() { | ||
| this.params = sessionParams; | ||
| } | ||
|
|
||
| public async init(modelPath: string) { | ||
| ort.env.wasm.numThreads = this.params.numThreads; | ||
| ort.env.wasm.wasmPaths = this.params.wasmRoot; | ||
| ort.env.wasm.simd = true; | ||
| env.wasm.numThreads = this.params.numThreads; | ||
| env.wasm.wasmPaths = this.params.wasmRoot; | ||
| env.wasm.simd = true; | ||
| // Suppress expected "some nodes not assigned to WebGPU EP" warnings β | ||
| // ORT intentionally keeps shape-related ops on CPU for performance. | ||
| env.logLevel = 'error'; | ||
|
jpggvilaca marked this conversation as resolved.
|
||
|
|
||
| const modelData = await loadModel(modelPath); | ||
|
|
||
| if (!modelData) { | ||
| throw new Error(`Unable to load model from "${modelPath}"`); | ||
| } | ||
|
|
||
| const session = await ort.InferenceSession.create(modelData, { | ||
| const session = await InferenceSession.create(modelData, { | ||
| executionProviders: this.params.executionProviders, | ||
| graphOptimizationLevel: 'all', | ||
| executionMode: 'parallel', | ||
| // 0=verbose, 1=info, 2=warning, 3=error, 4=fatal. Silences the | ||
| // native "VerifyEachNodeIsAssignedToAnEp" warnings emitted when | ||
| // ORT intentionally keeps shape-related ops on the CPU EP. | ||
| logSeverityLevel: 3, | ||
| }); | ||
|
|
||
| this.ortSession = session; | ||
|
|
@@ -43,7 +50,14 @@ export class Session { | |
| if (!this.ortSession) { | ||
| throw Error('the session is not initialized. Call `init()` method first.'); | ||
| } | ||
| return await this.ortSession.run(input); | ||
| // onnxruntime-web does not support concurrent run() calls on the same session. | ||
| // Serialize calls through a void queue so the result type stays clean. | ||
| const runNext = this.runQueue.then(() => this.ortSession!.run(input)); | ||
|
Contributor
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. could we make sure we have
Contributor
Author
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. 100%, agree. Let me update on the next PR
Contributor
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. I don't really understand why we need this, could u please explain more?
Contributor
Author
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. Artifacts from Claude, but the gist is that each In any case i agree this is confusing so i will refactor this as well on my next PR. It will be something like:
Contributor
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. Maybe we should cancel ongoing processing if there is a new one?
Contributor
Author
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. We want to wait for it. The user clicked so it's intentional. Worry not. The next version will be much simpler :) |
||
| this.runQueue = runNext.then( | ||
| () => undefined, | ||
| () => undefined | ||
| ); | ||
| return runNext; | ||
| } | ||
|
|
||
| public inputNames(): readonly string[] { | ||
|
|
||
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.
can it be
gpuTensor.dims?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.
It's better to clone things, but we could maybe make them read-only. In any case i will update on my next PR