Model chaining with dynamic output shapes #26874
cNoNim
started this conversation in
Ideas / Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone!
I've been working on chaining multiple ONNX models in a pipeline (like Model A → Model B → Model C), and ran into a limitation with IOBinding when dealing with dynamic output shapes. I wanted to discuss the problem and a potential solution I've prototyped.
Problem
When you want to pass outputs from one model as inputs to another, ONNX Runtime already supports this well... if you know the output shapes in advance:
Just works!
But what if the output shape is dynamic? Then you have to use
BindOutputToDevice, which only specifies the device, not the actual tensor. And now you're doing this:This works, but the problem is:
Solution
What if we could set up the pipeline once even with dynamic shapes, and have the "copy output to input" happen automatically?
Implementation
I've made a small prototype that adds this functionality. Here's the basic idea:
When you get an output handle:
std::shared_ptr<OrtValue>shared_outputs_) in IOBindingAfter Run() completes we call
SyncSharedOutputs()internally which automatically copies outputs into the shared handlesWhen you bind a shared handle as input:
std::shared_ptr<OrtValue>in another array (shared_inputs_)Before Run() executes we call
SyncSharedInputs()internally which automatically copies from shared handles into the input bindingsQuestions
std::shared_ptr<OrtValue>- is this acceptable? In C API I provide OrtOutputHandle wrapper type.GetOutputHandle()as a new method and overloadedBindInput()that acceptsshared_ptr?Notes
GetOutputHandle()is called, subsequentBindOutput()calls on that output maintain the created handle in correct state (sync it automatically)BindInput()calls on the same input name also update the handle. This might need a different strategy or an unbinding method?Run()time a bound shared handle is not allocated yet, it's an errorBeta Was this translation helpful? Give feedback.
All reactions