Skip to content

Conversation

@gcunhase
Copy link
Contributor

@gcunhase gcunhase commented Dec 5, 2025

What does this PR do?

Type of change: Bug fix

Overview: Autocast crashes if the input batch size in the ONNX model is different to the calibration data input batch size. For example: calibration data has shape [10, 6, 3, 480, 800] and ONNX model has shape [1, 6, 3, 480, 800]. The quantization workflow interprets this as 10 calibration samples, so ideally, Autocast would also interpret them similarly. This PR just allows Autocast to exit gracefully with a custom message.

Usage

$ python -m modelopt.onnx.autocast --onnx_path=$MODEL_NAME.onnx --calibration_data=calib_data_10.npz

Testing

See bug 5676209.

Before your PR is "Ready for review"

  • Make sure you read and follow Contributor guidelines 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?: Yes
  • Did you update Changelog?: No

Additional Information

Original error:

polygraphy.exception.exception.PolygraphyException: Input tensor: image | Received incompatible shape: (10, 6, 3, 480, 800).
Note: Expected a shape compatible with: BoundedShape([1, 6, 3, 480, 800], min=None, max=None)

Autocast error:

ValueError: Input shape from 'image' does not match provided input shape: [1, 6, 3, 480, 800] vs [10, 6, 3, 480, 800]. Please make sure that your calibration data matches the ONNX input shapes.

@gcunhase gcunhase requested a review from a team as a code owner December 5, 2025 19:28
@gcunhase gcunhase requested a review from galagam December 5, 2025 19:28
Copy link
Contributor

@galagam galagam left a comment

Choose a reason for hiding this comment

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

Thanks for this fix!

@kevalmorabia97
Copy link
Collaborator

Tests failing on this PR. @gcunhase PTAL

Signed-off-by: gcunhase <[email protected]>
@codecov
Copy link

codecov bot commented Dec 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.46%. Comparing base (3ef9e39) to head (0e8f3d3).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #652      +/-   ##
==========================================
- Coverage   74.57%   74.46%   -0.11%     
==========================================
  Files         183      183              
  Lines       18451    18413      -38     
==========================================
- Hits        13759    13712      -47     
- Misses       4692     4701       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gcunhase gcunhase merged commit 47c04d6 into NVIDIA:main Dec 11, 2025
46 of 48 checks passed
kevalmorabia97 pushed a commit that referenced this pull request Dec 11, 2025
…bs (#652)

## What does this PR do?

**Type of change:** Bug fix

**Overview:** Autocast crashes if the input batch size in the ONNX model
is different to the calibration data input batch size. For example:
calibration data has shape `[10, 6, 3, 480, 800]` and ONNX model has
shape `[1, 6, 3, 480, 800]`. The quantization workflow interprets this
as 10 calibration samples, so ideally, Autocast would also interpret
them similarly. This PR just allows Autocast to exit gracefully with a
custom message.

## Usage

```python
$ python -m modelopt.onnx.autocast --onnx_path=$MODEL_NAME.onnx --calibration_data=calib_data_10.npz
```

## Testing
See bug 5676209.

## 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/TensorRT-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?**: Yes
- **Did you update
[Changelog](https://github.com/NVIDIA/TensorRT-Model-Optimizer/blob/main/CHANGELOG.rst)?**:
No

## Additional Information
Original error:
```sh
polygraphy.exception.exception.PolygraphyException: Input tensor: image | Received incompatible shape: (10, 6, 3, 480, 800).
Note: Expected a shape compatible with: BoundedShape([1, 6, 3, 480, 800], min=None, max=None)
```

Autocast error:
```sh
ValueError: Input shape from 'image' does not match provided input shape: [1, 6, 3, 480, 800] vs [10, 6, 3, 480, 800]. Please make sure that your calibration data matches the ONNX input shapes.
```

---------

Signed-off-by: gcunhase <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants