-
Notifications
You must be signed in to change notification settings - Fork 179
[onert/python] Support dynamic shapes(on-the-fly) #15205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hseok-oh
merged 3 commits into
Samsung:master
from
ragmani:onert/python/support_dynamic_shape
Apr 30, 2025
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
runtime/onert/sample/minimal-python/src/dynamic_shape_inference.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import numpy as np | ||
| import random | ||
| import sys | ||
| from onert import infer | ||
|
|
||
|
|
||
| def main(nnpackage_path, backends="cpu"): | ||
| # Create session and load nnpackage | ||
| session = infer.session(nnpackage_path, backends) | ||
|
|
||
| # Prepare input. Here we just allocate dummy input arrays. | ||
| input_infos = session.get_inputs_tensorinfo() | ||
|
|
||
| # Call infer() 10 times | ||
| for i in range(10): | ||
| dummy_inputs = [] | ||
| for info in input_infos: | ||
| # Retrieve the dimensions list from tensorinfo property. | ||
| dims = list(info.dims) | ||
| # Replace -1 with a random value between 1 and 10 | ||
| dims = [random.randint(1, 10) if d == -1 else d for d in dims] | ||
| # Build the shape tuple from tensorinfo dimensions. | ||
| shape = tuple(dims[:info.rank]) | ||
| # Create a dummy numpy array filled with uniform random values in [0,1). | ||
| dummy_inputs.append( | ||
| np.random.uniform(low=0.0, high=1.0, size=shape).astype(info.dtype)) | ||
|
|
||
| outputs = session.infer(dummy_inputs) | ||
| print(f"Inference run {i+1}/10 completed.") | ||
|
|
||
| print(f"nnpackage {nnpackage_path.split('/')[-1]} runs successfully.") | ||
| return | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| argv = sys.argv[1:] | ||
| main(*argv) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.