[5868890][ONNX][Autocast] Fix: failure when checking input shape with unknown dimension#859
Conversation
Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com>
📝 WalkthroughWalkthroughThe change refines input shape validation in the reference runner to properly handle dynamic dimensions (represented as -1) by only comparing known dimensions between model and data shapes, allowing flexible dimension matching where either side is undefined. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@modelopt/onnx/autocast/referencerunner.py`:
- Around line 92-97: The rank comparison currently builds a mask between
inp_shape_model and inp_shape_data which will raise a NumPy broadcasting error
if their lengths differ; before creating mask, explicitly check
len(inp_shape_model) == len(inp_shape_data) and if not raise the same ValueError
you would for a mismatch so callers see the intended user-facing error; update
the logic around the variables inp_shape_model, inp_shape_data, and mask in
referencerunner.py to perform this length check and early raise before any
elementwise comparison.
- Around line 92-96: The input_shapes extraction currently ignores ONNX
dim_param and leaves dim_value==0 for dynamic dims, so update the handling so
dynamic dimensions are treated as unknown: either (preferred) normalize any
dimension with a non-empty dim_param to -1 when building self.input_shapes (so
self.input_shapes[...] contains -1 for dynamic dims), or modify the mask in
Referencerunner where inp_shape_model = np.array(self.input_shapes[inp_name]) is
used to also treat entries with dim_value==0 as unknown when the original ONNX
dim_param was set; adjust the mask logic that computes mask = (inp_shape_model
!= -1) & (inp_shape_data != -1) to consider dim_value==0 (and/or stored
dim_param markers) as unknown so validation skips those dimensions correctly.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #859 +/- ##
=======================================
Coverage 73.72% 73.73%
=======================================
Files 196 196
Lines 20457 20463 +6
=======================================
+ Hits 15082 15088 +6
Misses 5375 5375 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com>
Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com>
Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com>
What does this PR do?
Type of change: Bug fix
Overview: Skip unknown dimensions when comparing input shape in model vs calibration data.
Usage
Testing
See bug 5868890.
Before your PR is "Ready for review"
Summary by CodeRabbit
Bug Fixes
Aditional info
Regression introduced in #652.