Repository navigation
Rewriter: validate axis bounds and transposed rank in ScatterAllDynamic - #3146
Conversation
|
Hi Ti-Tai Wang (@titaiwangms), Could you please review this PR when you have a moment? It fixes an |
|
The bounds and rank-zero guards address real IndexError paths. I found no blocking issue in the changed behavior during static review. Two small simplification/documentation suggestions:
There is also an existing repository helper, The new negative-axis test verifies that rewriting still happens; numerical equivalence coverage would strengthen it, but I do not consider that a blocker for these guards. Validation: static review only, including the minimum supported IR implementation; tests were not run locally because onnx_ir is unavailable in this environment. |
…ScatterAllDynamic Leverage _ir_utils.get_dim(data, axis_value) to simplify axis bounds validation and negative axis normalization in ScatterAllDynamic.check, avoiding redundant rank is None guards and manual axis += rank calculations while preserving failure diagnostics. Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…catterAllDynamic Use _ir_utils.get_dim(transposed_data, 0) for looking up the leading dimension of transposed_data and guarding against rank-0 scalar tensors in ScatterAllDynamic.check. Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…s in ScatterAllDynamic Update test_dynamic_indices_valid_negative_axis_supported to use opset 17 and verify numerical parity using testing.assert_numerically_equal. Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…in ScatterAllDynamic Add a regression test verifying that an unranked input data tensor with missing shape metadata is safely rejected by ScatterAllDynamic without crashing. Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
… rejection in ScatterAllDynamic Add a regression test verifying that an unranked transposed_data tensor with missing shape metadata is safely rejected by ScatterAllDynamic without crashing. Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
|
Hi Ti-Tai Wang (@titaiwangms), Thank you for the review and suggestions! I have updated the PR accordingly across five focused commits:
All 16 tests in |
Ti-Tai Wang (titaiwangms)
left a comment
There was a problem hiding this comment.
The revised implementation appropriately reuses _ir_utils.get_dim() for safe dimension lookup, and the added numerical-equivalence and missing-shape tests strengthen coverage. No blocking findings remain in my static review.
Please update the PR description to match the final implementation: bounds checking and negative-index handling are delegated to get_dim(), rather than implemented with an explicit rank-is-None check and axis-normalization branch. Valid negative indices were already supported by IR Shape indexing; the substantive fixes are the out-of-bounds and rank-zero crash guards.
Approval is based on static review; local tests were not run. Please ensure the required CI checks pass before merging.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3146 +/- ##
==========================================
+ Coverage 73.29% 73.32% +0.03%
==========================================
Files 267 269 +2
Lines 33214 33481 +267
Branches 3183 3194 +11
==========================================
+ Hits 24344 24551 +207
- Misses 7801 7868 +67
+ Partials 1069 1062 -7 ☔ View full report in Codecov by Harness. |
5b210da
into
microsoft:main
Summary
This PR hardens
ScatterAllDynamic.checkagainst invalid dimension lookups that could previously cause unhandledIndexErrorcrashes during the rewrite pass.It reuses the existing
_ir_utils.get_dim()helper to safely retrieve dimensions while handling out-of-bounds axes, missing shape information, and rank-zero inputs.Problem
In
_redundant_scatter_nd.ScatterAllDynamic.check, unsafe dimension access could cause the rewrite pass to crash:axis_valuecould raise an unhandledIndexError.transposed_data: Accessing dimension0whentransposed_datais a scalar could also raise anIndexError.Solution
Updated
ScatterAllDynamic.checkto use the existing_ir_utils.get_dim()helper for safe dimension lookups:_ir_utils.get_dim(data, axis_value).transposed_datausing_ir_utils.get_dim(transposed_data, 0).result.fail(...)when either lookup cannot provide a valid dimension.This prevents invalid dimension accesses from propagating as unhandled exceptions while preserving the existing rewrite behavior for valid inputs.
Tests
Added and updated regression tests in
_redundant_scatter_nd_test.py:test_dynamic_indices_out_of_bounds_axis_rejected: Verifies that an out-of-bounds positive axis is safely rejected.test_dynamic_indices_negative_out_of_bounds_axis_rejected: Verifies that an out-of-bounds negative axis is safely rejected.test_dynamic_indices_valid_negative_axis_supported: Verifies valid negative-axis handling and numerical equivalence of the rewritten result.test_dynamic_indices_scalar_transposed_data_rejected: Verifies that scalartransposed_datais safely rejected.test_dynamic_indices_missing_data_shape_rejected: Verifies that unranked input data without shape metadata is safely rejected.test_dynamic_indices_missing_transposed_data_shape_rejected: Verifies that unrankedtransposed_datawithout shape metadata is safely rejected.