You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Requantizes and clamps results to the output integer type range.
Registered "QLinearConv": QLinearConv in _get_convert_map().
In tests/python/relax/test_frontend_onnx.py:
Added test_qlinearconv covering 2D convolutions with and without bias, and multi-channel convolutions with custom padding, validated against ONNX Runtime.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
SAME_UPPER and SAME_LOWER imports fail because autopad receives an unnormalized expression, and float32 convolution and bias handling can lose integer precision that the current tests may miss.
I have updated the PR to address all the recommended review changes:
Normalize Before Autopadding: Ensured input expressions are normalized with bb.normalize(x_centered) before calling autopad() so SAME_UPPER and SAME_LOWER can inspect shape and rank.
Exact int32 Centered Convolution & Bias: Maintained centered convolution and bias addition strictly in int32 before scaling and requantizing, avoiding float32 precision loss during large-channel cancellation.
In-Range Arithmetic Checks: Calibrated test inputs close to zero-points and used appropriate output scales to ensure outputs remain away from clipping limits.
Extended Test Suite: Added tests for 1D, 2D, 3D convolutions, SAME_UPPER/SAME_LOWER/VALID, non-unit strides/dilations, grouped convolutions, signed int8, per-channel parameters, and the precision cancellation regression case.
Could you please take another look when you have a moment? Thank you!
…oat64 scale product
Two fixes:
1. kernel_shape inference: weight_norm.ty.shape[2:] raises TypeError because
ShapeExpr.__getitem__ does not accept slice arguments. Use
weight_norm.ty.shape.values[2:] (which returns a list/tuple that can be
sliced) so symbolic kernel dimensions remain supported. Adds a regression
test that omits kernel_shape from the ONNX node and verifies correct output.
2. Scale overflow: x_scale * w_scale can overflow float32 even when all three
scales and the final requantized result are finite (e.g. x_scale=w_scale=2^65,
y_scale=2^124 gives a correct output of 64 but float32 product is inf, clipping
to 255). Compute x_scale * w_scale / y_scale in float64, then cast to float32
before multiplying with the conv output. Adds a regression asserting that the
canonical overflow case produces 64 rather than 255.
Addresses GitHub Copilot review comments:
apache#20953 (comment)apache#20953 (comment)
I have updated the PR to address the latest review feedback:
Kernel Shape Slicing: Sliced weight_norm.ty.shape.values[2:] instead of the ShapeExpr object directly to avoid TypeError when the kernel_shape attribute is omitted, keeping support for symbolic kernel dimensions intact.
Combined Scale Overflow Safety: Computed the combined scale multiplier (x_scale * w_scale) / y_scale using float64 intermediates before casting to float32, preventing overflow when large individual scale factors (such as ^{65}$) are multiplied together.
Regression Tests: Added test_qlinearconv_no_kernel_shape_attr and test_qlinearconv_scale_overflow covering both omitted kernel shape inference and the float64 scale product overflow case.
Could you please take another look when you get a chance? Thank you!
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Finite-scale multiplier overflow can turn zero accumulators into NaN, while regression tests fail to distinguish per-channel scales, SAME padding modes, and incorrect output dtypes.
No open issues 🎉
4 previously missed issues
In code that hasn't changed since last review
Preserve zero accumulators when the multiplier overflows
Narrowing the multiplier to float32 still overflows for finite scales such as x_scale = w_scale = 2**65 and y_scale = 1. With a zero accumulator, this produces 0 * inf = NaN rather than the required y_zero_point (for example, 128). Preserve zero accumulators when applying the multiplier and add this case to the overflow regression.
Use distinct scales to test per-channel requantization
tests/python/relax/test_frontend_onnx.py:14622
The per-output-channel test receives identical weight scales [0.25, 0.25, 0.25, 0.25], despite being labeled as testing distinct scales. Consequently, a converter that reuses the first scale for every output channel would still pass. Generate different scales per output channel so the existing bias-enabled case actually validates per-channel requantization.
Check output dtypes in quantization comparisons
tests/python/relax/test_frontend_onnx.py:14678
These comparisons check values but not the output dtype, so returning float32 instead of the required uint8 or int8 would still pass. Set check_dtypes=True, matching the nearby quantization tests at lines 14182 and 14201; the calls at lines 14764 and 14815 need the same check.
Use an even kernel to distinguish SAME_LOWER padding
tests/python/relax/test_frontend_onnx.py:14695
Both SAME-padding cases use a 3×3 kernel with unit strides, yielding one padding cell on each side. SAME_UPPER and SAME_LOWER are therefore indistinguishable, so always using SAME_UPPER would still pass this test. Please use an even-sized kernel here, such as 2×2, to create an odd total padding and verify that SAME_LOWER puts the extra cell at the beginning.
Hi @mshr-h, thank you for the approval and the note! 🙏
I have fixed the GitHub Actions lint errors. The failures were caused by Ruff rule UP038 — the linter requires using union type syntax X | Y instead of tuples (X, Y) in isinstance() calls (Python 3.10+ style). All affected lines in both onnx_frontend.py and test_frontend_onnx.py have been updated and verified clean with pre-commit locally.
The fix has been pushed — CI should now pass. Ready to merge once CI is green! ✅
Preserve Zero Accumulators on Scale Overflow: Kept the scale multiplication in float64 (scaled_f64 = conv_f64 * scale_mult_f64) before casting to float32, ensuring zero accumulators (0.0 * inf) evaluate cleanly to 0.0 instead of NaN when scales are exceptionally large.
Distinct Per-Channel Weight Scales & Output Dtype Checks: Generated linearly spaced distinct scales per channel for multi-channel tests, used asymmetric padding (5x5 input with 2x2 kernel) to clearly distinguish SAME_LOWER from SAME_UPPER, and enabled check_dtypes=True on test comparisons.
Lint & Pre-commit: All pre-commit hooks passed cleanly.
The PR is now conflict-free and ready for merge. Thank you! 🙏
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for the ONNX
QLinearConvoperator in the Relax ONNX frontend, resolving #20959.Key Changes
python/tvm/relax/frontend/onnx/onnx_frontend.py:QLinearConvop converter supporting opset 10.[1, C, 1, 1]and[O, 1, 1, 1]).auto_padmodes (SAME_UPPER,SAME_LOWER,VALID,NOTSET), strides, dilations, and groups.B * x_scale * w_scale)."QLinearConv": QLinearConvin_get_convert_map().tests/python/relax/test_frontend_onnx.py:test_qlinearconvcovering 2D convolutions with and without bias, and multi-channel convolutions with custom padding, validated against ONNX Runtime.Closes #20959.