onnxruntime icon indicating copy to clipboard operation
onnxruntime copied to clipboard

[Feature Request] Add a real async run method to onnxruntime-node

Open segevfiner opened this issue 1 year ago • 3 comments

Describe the feature request

There should really be a true async version of run in onnxruntime-node, running computationally intensive things on the event loop will stop everything else from happening while it is running, e.g. a web server from answering requests.

This can be done by wrapping RunAsync behind a Napi::Promise and Napi::TypedThreadSafeFunction to run on the onnxruntime thread pool, or Napi::AsyncWorker for the Node.js/libuv thread pool.

See https://github.com/microsoft/onnxruntime/pull/19610

Describe scenario use case

Don't block the event loop while running inference, which is naturally computationally intensive.

segevfiner avatar Feb 22 '24 19:02 segevfiner

Thank you for creating this feature request!

Possible discussions:

  • not sure if we need a ENV flag or session option for this. Maybe some user still prefer the sync call?
  • also need for session initAsync?

fs-eire avatar Feb 23 '24 00:02 fs-eire

Note that the current run method returns a Promise so it's not really sync to begin with just pseudo async where it defers the work to a different phase of the event loop but still blocks it.

segevfiner avatar Feb 23 '24 09:02 segevfiner

So maybe you will want to have a new RunSync method while making the existing Run truly async.

segevfiner avatar Feb 23 '24 10:02 segevfiner