Skip to content

multi thread error on onnxruntime-node 1.21.0 #1292

@wszgrcy

Description

@wszgrcy

System Info

windows 10 / transformers 3.5.0

Environment/Platform

  • Website/web-app
  • Browser extension
  • Server-side (e.g., Node.js, Deno, Bun)
  • Desktop app (e.g., Electron)
  • Other (e.g., VSCode extension)

Description

microsoft/onnxruntime#24486

I found that after upgrading onnxruntime, multithreading will encounter exceptions, which may affect transformers
Should dependency be downgraded? Version 1.20.1 works normally

Reproduction

worker

import { createRequire } from "node:module";
import path from "node:path";
import url from "node:url";
globalThis.require = createRequire(import.meta.url);
globalThis.__filename = url.fileURLToPath(import.meta.url);
globalThis.__dirname = path.dirname(__filename);


import  path2  from "path";
import * as ort from "onnxruntime-node";
import { parentPort } from "worker_threads";
async function test() {
  let dir = path2.join(process.cwd(), "bin/model.onnx");
  const session = await ort.InferenceSession.create(dir, {
    executionProviders: ["cpu"],
    executionMode: "parallel"
  });
  const dataA = Float32Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
  const dataB = Float32Array.from([
    10,
    20,
    30,
    40,
    50,
    60,
    70,
    80,
    90,
    100,
    110,
    120
  ]);
  const tensorA = new ort.Tensor("float32", dataA, [3, 4]);
  const tensorB = new ort.Tensor("float32", dataB, [4, 3]);
  const feeds = { a: tensorA, b: tensorB };
  const results = await session.run(feeds);
}
parentPort.on("message", async (value) => {
  console.log("go", value);
  test();
});

index

import path from 'path';
import { Worker } from 'worker_threads';

(() => {
  let url = path.join(__dirname, './worker.mjs');
  let instance = new Worker(url);
  instance.postMessage(1);
  let instance2 = new Worker(url);
  instance2.postMessage(1);
})();

model
https://github.com/microsoft/onnxruntime-inference-examples/blob/main/js/quick-start_onnxruntime-node/model.onnx

work on 1.20.1
failed on 1.21.1 1.21.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions