[CVS-187745] Add multi-shape profiling support to perftest tool (--data_shape) - #1132
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds multi-shape profiling support to the onnxruntime_perf_test tool via a new --data_shape flag, enabling a single session to run multiple input shape groups (round-robin) and report per-shape latency statistics. It also adds a small dynamic-shape ONNX model generator to help exercise the new flag.
Changes:
- Add
--data_shapecommand-line flag and parsing intoRunConfig::data_shape_groups. - Generate/choose per-shape-group inputs (generated inputs with
-I, or select matching testdata folders without-I) and run them round-robin while recording per-shape timings. - Print per-shape latency stats and add a test model generator script for dynamic shapes.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| onnxruntime/test/testdata/dynamic_shape_add.py | Adds a small dynamic-shape ONNX model generator for testing --data_shape. |
| onnxruntime/test/perftest/test_session.h | Extends RunTiming with shape_group_index for per-shape timing attribution. |
| onnxruntime/test/perftest/test_configuration.h | Adds data_shape_groups storage to RunConfig. |
| onnxruntime/test/perftest/strings_helper.h | Declares ParseDataShapeGroups. |
| onnxruntime/test/perftest/strings_helper.cc | Implements --data_shape parsing into grouped shapes per input name. |
| onnxruntime/test/perftest/performance_runner.h | Adds per-shape timing storage in PerformanceResult. |
| onnxruntime/test/perftest/performance_runner.cc | Implements warmup-per-shape, per-shape timing aggregation/printing, and testdata selection by requested shapes. |
| onnxruntime/test/perftest/ort_test_session.h | Adds round-robin controls and helpers for multi-shape mode. |
| onnxruntime/test/perftest/ort_test_session.cc | Implements multi-shape input generation, round-robin selection, and testdata filtering helpers. |
| onnxruntime/test/perftest/command_args_parser.cc | Adds --data_shape flag and hooks parsing into RunConfig. |
| // Extract bracket-delimited shape groups: [d0,d1,...][d0,d1,...] | ||
| size_t pos = 0; | ||
| while (pos < shapes_str.size()) { | ||
| if (shapes_str[pos] != '[') { | ||
| std::cerr << "Error parsing --data_shape: expected '[' at position " << pos | ||
| << " in shapes for input '" << input_name << "'." << std::endl; | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Accounted for the space in between shapes. This semantic is useful but can be removed if unecessary.
| if (match) { | ||
| selected_ids.push_back(test_data_id); | ||
| found = true; | ||
| break; | ||
| } |
1d939f4 to
e42e521
Compare
|
@n1harika hi! Thank you for this PR 🔥 |
DariaMityagina
left a comment
There was a problem hiding this comment.
The PR LGTM 👍
Thanks for implementing this functionality!
Usage:
.\onnxruntime_perf_test.exe -v -e openvino -m times -r 10 -I --data_shape "data:[1,3,60,40][1,3,60,60]" -i "device_type|NPU" "PSO2_ctx.onnx"
or, using testdata-
.\onnxruntime_perf_test.exe -v -e openvino -m times -r 10 --data_shape "data:[1,3,60,40][1,3,60,60]" -i "device_type|NPU" "PSO2_ctx.onnx"
Addresses the feature request: microsoft#28628