[onert/python] Support static shape modification across inference API#15184
Conversation
This commit supports static shape modification across inference API and samples. - common/basesession.py: add typed get_inputs_tensorinfo/get_outputs_tensorinfo helpers - infer/session.py: - normalize any `-1` dims to `1` then call `update_inputs_tensorinfo` in `__init__` - remove obsolete `compile()` method - provide `update_inputs_tensorinfo` and `run_inference` with full type hints - samples: - minimal sample: build dummy inputs from tensorinfo and use `run_inference` - static_shape_inference example: demonstrate modifying input tensorinfo (e.g. batch size → 10) and running inference with static shapes ONE-DCO-1.0-Signed-off-by: ragmani <ragmani0216@gmail.com>
| info.dims = dims # assume setter accepts a list | ||
| fixed_infos.append(info) | ||
| # update tensorinfo in session | ||
| self.update_inputs_tensorinfo(fixed_infos) |
There was a problem hiding this comment.
(just curious)
If dynamic dimension (-1) is changed to 1 before shape interference,
I think we do not know whether dynamic shape is included in session.
In this case, how should we deal with dynamic shape?
There was a problem hiding this comment.
Thank you for your advice. If an input contains ‑1, it still errors, so I only applied a fragmentary fix by forcing ‑1 to 1. I just ran it with onert_run and saw the same failure, so this looks like a bug in onert. We need to fix this bug and update this code to allow ‑1 in inputs. I'll try it.
There was a problem hiding this comment.
(In my opinion)
It seems that the user did in a wrong scenario rather than a bug. and If the user does not know this changes(-1 -> 1), it will be difficult to debug in case of dynamic shape.
so, (optional) it would be better to print an error message that the shape should be set explicitly before runnig the unknown shape .
There was a problem hiding this comment.
There are really two modes here:
-
Static shape modification
Users callupdate_inputs_tensorinfo()once (e.g. at construction) with a fully‑specified shape (no –1s), and the session is prepared with that fixed shape. -
Dynamic shape modification
If user's inputs change shape on each run, users must callupdate_inputs_tensorinfo(new_infos)before callingprepare(). If users skip that and anytensorinfo.dimsstill contains-1, users will hit the same shape error at runtime. So how should users specifydimsvalues that change each time? If they set any of them to-1, an error will occur.
There was a problem hiding this comment.
As discussed offline, I’ll keep this code unchanged and add a TODO comment.
There was a problem hiding this comment.
how should users specify dims values that change each time? If they set any of them to -1, an error will occur.
I agree that we can't deal with all scenarios.
but it means to maintain the error caused by unknown shape rather than changing to -1 -> 1.
and, if -1 -> 1 , it can be misunderstood that there is an unknown shape and it work without any problems, so i hope it is to solve this.
This commit supports static shape modification across inference API and samples.
-1dims to1then callupdate_inputs_tensorinfoin__init__compile()methodupdate_inputs_tensorinfoandinferwith full type hintsinferONE-DCO-1.0-Signed-off-by: ragmani ragmani0216@gmail.com