microsoft / microsoft/onnxruntime
[Web] InferenceSession.RunOptions.terminate not working as expected (reopen)
- Dominant language
- C++
- Stars
- 21.9k
- Forks
- 4.2k
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 184
Description
### Describe the issue
My understanding of this flag is, if there are pending calls ahead of this one, that those calls will be terminated and the new call will start.
Instead, the new call is terminated.
Am I missing anything here?
```shell
Error: failed to call OrtRun(). ERROR_CODE: 1, ERROR_MESSAGE: Exiting due to terminate flag being set to true.
```
https://onnxruntime.ai/docs/api/js/interfaces/InferenceSession.RunOptions.html#terminate
I previously opened this as https://github.com/microsoft/onnxruntime/issues/27793, reopening now with an example.
Example output:
```shell
^1866 +1866 Running 1...
^1867 +1 Running 2...
^1867 +0 Running 3...
^2962 +1095 Run 1 done: 1.0000262260437012
^2963 +1 Running 4 with terminate=true...
^4024 +1061 Run 2 done: 2.000026226043701
^5083 +1059 Run 3 done: 3.000026226043701
^5084 +1 Run 4 fail: failed to call OrtRun(). ERROR_CODE: 1, ERROR_MESSAGE: Exiting due to terminate flag being set to true.
```
### To reproduce
[create_onnx.py](https://github.com/user-attachments/files/28917700/create_onnx.py)
[dummy.zip](https://github.com/user-attachments/files/28917702/dummy.zip)
[test.html](https://github.com/user-attachments/files/28917701/test.html)
```js
function getFeeds(value) {
const data = new Float32Array(512 * 512).fill(value);
const tensor = new ort.Tensor('float32', data, [512, 512]);
return { input: tensor };
}
ort.env.wasm.proxy = true;
async function testTermination() {
const session = await ort.InferenceSession.create('./dummy.onnx', {
executionProviders: ['wasm']
});
const feeds1 = getFeeds(1.0);
const feeds2 = getFeeds(2.0);
const feeds3 = getFeeds(3.0);
const feeds4 = getFeeds(4.0);
log("Running 1...");
session.run(feeds1).then(r => {
log("Run 1 done:", r.output.data[0]);
log("Running 4 with terminate=true...");
session.run(feeds4, { terminate: true }).then(r => {
log("Run 4 done:", r.output.data[0]);
}).catch(e => {
log("Run 4 fail:", e.message);
});
});
log("Running 2...");
session.run(feeds2).then(r => {
log("Run 2 done:", r.output.data[0]);
}).catch(e => {
log("Run 2 fail:", e.message);
});
log("Running 3...");
session.run(feeds3).then(r => {
log("Run 3 done:", r.output.data[0]);
}).catch(e => {
log("Run 3 fail:", e.message);
});
}
```
### Urgency
_No response_
### ONNX Runtime Installation
Released Package
### ONNX Runtime Version or Commit ID
1.26.0
### Execution Provider
'wasm'/'cpu' (WebAssembly CPU)
Contributor guide
Research direction
Start with test.html and the supplied dummy.zip and create_onnx.py to reproduce the ordering shown for session.run calls with and without terminate. Compare the observed behavior with the InferenceSession.RunOptions.terminate documentation and verify that the intended call lifecycle is reflected by the resulting success and failure messages.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, wasm
- Domain
- machine-learning, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100