Skip to content

[onert/python] Support inference benchmark#15192

Merged
glistening merged 2 commits intoSamsung:masterfrom
ragmani:onert/python/infer_benchmark
Apr 23, 2025
Merged

[onert/python] Support inference benchmark#15192
glistening merged 2 commits intoSamsung:masterfrom
ragmani:onert/python/infer_benchmark

Conversation

@ragmani
Copy link
Copy Markdown
Contributor

@ragmani ragmani commented Apr 21, 2025

This commit adds inference benchmark sample and latency measurement support.

  • Added inference_benchmark.py sample for measuring inference latency and memory usage
    • Supports static shape override via --input-shape
    • Measures MODEL_LOAD / PREPARE / EXECUTE / PEAK memory (RSS) and I/O / run latency
  • Updated session.infer() API to optionally return latency metrics using measure=True
  • Fixed potential memory accumulation in set_inputs() and set_outputs() by clearing internal buffers each call
  • Added _time_block() context manager for clean latency measurement implementation

ONE-DCO-1.0-Signed-off-by: ragmani ragmani0216@gmail.com

This commit adds inference benchmark sample and latency measurement support.
- Added `inference_benchmark.py` sample for measuring inference latency and memory usage
  - Supports static shape override via `--input-shape`
  - Measures MODEL_LOAD / PREPARE / EXECUTE / PEAK memory (RSS) and I/O / run latency
- Updated `session.infer()` API to optionally return latency metrics using `measure=True`
- Fixed potential memory accumulation in `set_inputs()` and `set_outputs()` by clearing internal buffers each call
- Added `_time_block()` context manager for clean latency measurement implementation

ONE-DCO-1.0-Signed-off-by: ragmani <ragmani0216@gmail.com>
@ragmani ragmani added the PR/ready for review It is ready to review. Please review it. label Apr 21, 2025
@ragmani ragmani requested a review from a team April 21, 2025 05:39
@ragmani
Copy link
Copy Markdown
Contributor Author

ragmani commented Apr 21, 2025

For #15172
Draft #15176

@ragmani
Copy link
Copy Markdown
Contributor Author

ragmani commented Apr 21, 2025

python3 runtime/onert/sample/minimal-python/src/inference_benchmark.py mobilenetv2 --backends cpu --input-shape 1,224,224,3 --repeat 100
======= Inference Benchmark =======
- Warmup runs   : 3
- Measured runs : 100
- Prepare       : 10.193 ms
- Avg I/O       : 0.081 ms
- Avg Run       : 10.520 ms
===================================
RSS
- MODEL_LOAD    : 15112 KB
- PREPARE       : 42280 KB
- EXECUTE       : 72160 KB
- PEAK          : 72160 KB
===================================

Comment thread runtime/onert/sample/minimal-python/src/inference_benchmark.py Outdated
@ragmani
Copy link
Copy Markdown
Contributor Author

ragmani commented Apr 21, 2025

python3 runtime/onert/sample/minimal-python/src/inference_benchmark.py mobilenetv2 --backends cpu --input-shape 1,224,224,3 --repeat 10
======= Inference Benchmark =======
- Warmup runs   : 3
- Measured runs : 10
- Prepare       : 10.814 ms
- Avg I/O       : 0.082 ms
- Avg Run       : 10.831 ms
===================================
RSS
- MODEL_LOAD    : 15068 KB
- PREPARE       : 41728 KB
- EXECUTE       : 41856 KB
- PEAK          : 41856 KB
===================================

Note that the above RSS figures exclude the memory footprint of both ONERT library and the Python libraries, ONERT library itself consumes roughly 3 MB.

@ragmani
Copy link
Copy Markdown
Contributor Author

ragmani commented Apr 22, 2025

@Samsung/one_onert PTAL

Copy link
Copy Markdown
Contributor

@glistening glistening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@glistening
Copy link
Copy Markdown
Contributor

@ragmani Could you please update typo in title?

@glistening glistening merged commit c51e1c6 into Samsung:master Apr 23, 2025
10 checks passed
@ragmani ragmani changed the title [onert/python] Support infernece benchmark [onert/python] Support inference benchmark Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR/ready for review It is ready to review. Please review it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants