[onert/python] Support dynamic shapes(on-the-fly)#15205
[onert/python] Support dynamic shapes(on-the-fly)#15205hseok-oh merged 3 commits intoSamsung:masterfrom
Conversation
415ff1b to
d85affe
Compare
|
For #15172 |
|
This PR follows #15171 (comment) |
|
I have two question
|
Framework Comparison: Input-Tensor Shape HandlingHow Keras (TensorFlow), PyTorch and ONERT manage input shapes—static, dynamic (on-the-fly) and unmodified—in their Python APIs.
Policy ConsiderationDeciding whether to allow inputs that differ from the original model tensorinfo is a policy issue:
Trade-off: internal-only hides complexity but limits flexibility; user-exposed offers control at the cost of extra error-handling and potential unintended dynamic-mode overhead. |
I agree that |
This commit support dynamic shapes and add dynamic_shape_inference sample. - Remove the old “replace -1 with 1” placeholder in the constructor - In `infer()`, on first call: - Inspect each `tensorinfo.dims` and for any `-1` replace it with the matching `inputs_array[i].shape[j]` - Validate that any non-`-1` dims match the actual input shape, raising on mismatch - Call `update_inputs_tensorinfo()`, then `prepare()` and `set_outputs()` once - Bundle the above into the “auto‑dynamic” path instead of hard‑coding 1’s - Add `dynamic_shape_inference.py` sample to show 10 runs with random shapes ONE-DCO-1.0-Signed-off-by: ragmani <ragmani0216@gmail.com>
ONE-DCO-1.0-Signed-off-by: ragmani <ragmani0216@gmail.com>
f46a565 to
a696f38
Compare
I don't think user can enable unintended dynamic mode. To enable dynamic mode, user must change input shape after 1st inference. If user set input shape before 1st inference and doesn't change after, then runtime will reuse static shape inference mode's result only.
Agree. It is trade-off. IMO, it looks |
It's independent issue with this PR :) |
You're right. The dynamic mode can be enabled only when input shapes change for each
How about providing a warning message instead of throwing an exception? import warnings
def infer(input_shape=None, data=None):
...
warnings.warn(
f"infer() called with input_shape={input_shape}, which differs from model’s expected shape={expected}. "
"Ensure this is intended.",
UserWarning
... |
OK, I will move them in another PR :) |
Ah, I thought you're going to add a warning message like this - #15205 (comment). |
Ah, you are right, I was waiting for it. Sorry for bother you. |
👍 <- Looks good |
No problem at all! Thanks for your work :) |
This commit support dynamic shapes and add dynamic_shape_inference sample.
infer(), on first call:tensorinfo.dimsand for any-1replace it with the matchinginputs_array[i].shape[j]-1dims match the actual input shape, raising on mismatchupdate_inputs_tensorinfo(), thenprepare()andset_outputs()oncedynamic_shape_inference.pysample to show 10 runs with random shapesminimal.pyto retain its original static‑shape example logicONE-DCO-1.0-Signed-off-by: ragmani ragmani0216@gmail.com