[5676209][ONNX][Autocast] Add support for single npz file with multiple samples#815
Conversation
Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com>
Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com>
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughThese changes modify calibration data handling in ONNX quantization. CalibrationDataProvider now accepts pre-loaded ONNX ModelProto objects in addition to file paths, and the reference runner wraps NPZ calibration data within CalibrationDataProvider to enable batch handling from single files. Changes
Sequence DiagramsequenceDiagram
participant RR as Reference Runner
participant CDP as CalibrationDataProvider
participant ONNX as ONNX Model
rect rgba(100, 149, 237, 0.5)
Note over RR,ONNX: New Flow: NPZ Data with CalibrationDataProvider
RR->>RR: Load NPZ file
RR->>CDP: Wrap NPZ data + model path
CDP->>ONNX: Load model from path (if string)
ONNX-->>CDP: ModelProto returned
CDP-->>RR: CalibrationDataProvider with batches
end
rect rgba(144, 238, 144, 0.5)
Note over RR,ONNX: Alternative: Pre-loaded Model
RR->>RR: Load NPZ file + ModelProto
RR->>CDP: Wrap NPZ data + ModelProto
CDP->>CDP: Use ModelProto directly (skip loading)
CDP-->>RR: CalibrationDataProvider with batches
end
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. 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 |
Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #815 +/- ##
==========================================
+ Coverage 74.17% 74.29% +0.12%
==========================================
Files 192 192
Lines 19246 19251 +5
==========================================
+ Hits 14276 14303 +27
+ Misses 4970 4948 -22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…iple samples (#815) ## What does this PR do? **Type of change:** New feature **Overview:** Currently, Autocast only supports calibration data with shape matching the model's input. This PR adds support for calibration data with shape that is a multiple of the model's input. It does so by re-arranging the data as such that it contains multiple samples with shape matching the model's input. Simplified example: - ONNX input: `[1, 3, 224, 224]` - Calibration data: `[10, 3, 224, 224]` - Calibration data with multiple samples: `[1, 3, 224, 224] * 10` ## Usage Single `npz` file with multiple samples: ```sh $ 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/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)?**: Yes ## Additional Information Equivalent support is already included in the quantization workflow: https://github.com/NVIDIA/Model-Optimizer/blob/1cc8e6bf3917f61500e81d4ded0af5d5a00e2e25/modelopt/onnx/quantization/calib_utils.py#L50 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * CalibrationDataProvider now accepts both file paths and pre-loaded ONNX models as input. * NPZ calibration files can now provide multiple batches for calibration workflows. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com>
…iple samples (#815) ## What does this PR do? **Type of change:** New feature **Overview:** Currently, Autocast only supports calibration data with shape matching the model's input. This PR adds support for calibration data with shape that is a multiple of the model's input. It does so by re-arranging the data as such that it contains multiple samples with shape matching the model's input. Simplified example: - ONNX input: `[1, 3, 224, 224]` - Calibration data: `[10, 3, 224, 224]` - Calibration data with multiple samples: `[1, 3, 224, 224] * 10` ## Usage Single `npz` file with multiple samples: ```sh $ 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/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)?**: Yes ## Additional Information Equivalent support is already included in the quantization workflow: https://github.com/NVIDIA/Model-Optimizer/blob/1cc8e6bf3917f61500e81d4ded0af5d5a00e2e25/modelopt/onnx/quantization/calib_utils.py#L50 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * CalibrationDataProvider now accepts both file paths and pre-loaded ONNX models as input. * NPZ calibration files can now provide multiple batches for calibration workflows. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com> Signed-off-by: Daniel Korzekwa <dkorzekwa@nvidia.com>
What does this PR do?
Type of change: New feature
Overview: Currently, Autocast only supports calibration data with shape matching the model's input. This PR adds support for calibration data with shape that is a multiple of the model's input. It does so by re-arranging the data as such that it contains multiple samples with shape matching the model's input.
Simplified example:
[1, 3, 224, 224][10, 3, 224, 224][1, 3, 224, 224] * 10Usage
Single
npzfile with multiple samples:$ python -m modelopt.onnx.autocast --onnx_path=$MODEL_NAME.onnx --calibration_data=calib_data_10.npzTesting
See bug 5676209.
Before your PR is "Ready for review"
Additional Information
Equivalent support is already included in the quantization workflow:
Model-Optimizer/modelopt/onnx/quantization/calib_utils.py
Line 50 in 1cc8e6b
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.