Harden ConvTranspose pad computation with SafeInt and consistency checks
Merged
YU
4mo ago+417+417+012345678901234567890123456789-5-5-0123456789
This pull request strengthens validation and error handling for the ConvTranspose operator in ONNX Runtime, particularly when using explicit output_shape attributes. It adds comprehensive checks to prevent inconsistent or invalid configurations, improves arithmetic safety to guard against integer overflows, and introduces a suite of targeted unit tests to verify these behaviors.
Validation and Error Handling Improvements:
- Added stricter input validation in
ConvTransposeAttributes::ComputePadAndOutputShapeto ensure that all relevant parameters (output_shape, input size, stride, kernel, dilation, and output padding) are within valid ranges and to provide clear error messages when they are not. This includes checks that all values are positive and that output padding is non-negative. - Added a consistency check to verify that the explicit
output_shapeis compatible with the input dimensions and convolution parameters, preventing buffer overruns and logical inconsistencies.
Arithmetic Safety:
- Updated
ComputeTotalPadto useSafeIntfor all intermediate arithmetic, ensuring that integer overflows are detected and handled safely instead of producing undefined behavior.
Testing Enhancements:
- Added a comprehensive set of unit tests for
ConvTransposewith explicitoutput_shape, including cases for invalid, inconsistent, and overflow-prone configurations, as well as valid edge cases (e.g., 1D, 2D, and 3D, large batch sizes, group > 1, and cases requiring padding). These tests verify that invalid configurations are rejected and that valid ones work as expected.
These changes collectively improve the robustness, correctness, and maintainability of the ConvTranspose operator's implementation and its handling of explicit output shapes.