Skip to content

Commit d0b4b34

Browse files
gcunhasekevalmorabia97
authored andcommitted
[5868890][ONNX][Autocast] Fix: failure when checking input shape with unknown dimension (#859)
## What does this PR do? **Type of change:** Bug fix **Overview:** Skip unknown dimensions when comparing input shape in model vs calibration data. ## Usage ```python $ python -m modelopt.onnx.autocast --onnx_path=$MODEL_NAME.onnx --calibration_data=calib_data_10.npz ``` ## Testing See bug 5868890. ## Before your PR is "*Ready for review*" <!-- If you haven't finished some of the above items you can still open `Draft` PR. --> - **Make sure you read and follow [Contributor guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md)** and your commits are signed. - **Is this change backward compatible?**: Yes - **Did you write any new necessary tests?**: No - **Did you add or update any necessary documentation?**: No - **Did you update [Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?**: No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Bug Fixes * Enhanced input shape validation to properly handle dynamic tensor dimensions, allowing more flexible dimension checking while maintaining validation accuracy. <!-- end of auto-generated comment: release notes by coderabbit.ai --> ## Aditional info Regression introduced in #652. --------- Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com>
1 parent cfb1399 commit d0b4b34

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

modelopt/onnx/autocast/referencerunner.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,16 @@ def _validate_inputs(self, data_loader):
8989
if sorted(self.input_names) != sorted(data_loader[0].keys()):
9090
raise ValueError("Input names from ONNX model do not match provided input names.")
9191
for inp_name, inp_shape in data_loader[0].items():
92-
if self.input_shapes[inp_name] != list(inp_shape.shape):
92+
# Get model and data shapes as numpy arrays
93+
inp_shape_model = np.array(self.input_shapes[inp_name])
94+
inp_shape_data = np.array(inp_shape.shape)
95+
# Compare input rank
96+
raise_value_error = len(inp_shape_model) != len(inp_shape_data)
97+
if not raise_value_error:
98+
# Compare input shape, skipping check for unknown dimensions
99+
mask = inp_shape_model > 0
100+
raise_value_error = np.any(inp_shape_model[mask] != inp_shape_data[mask])
101+
if raise_value_error:
93102
raise ValueError(
94103
f"Input shape from '{inp_name}' does not match provided input shape: "
95104
f"{self.input_shapes[inp_name]} vs {list(inp_shape.shape)}. "

0 commit comments

Comments
 (0)