Repository navigation
fix: validate minimum input rank in convolution_internal to prevent crash on invalid shapes - #125859
Merged
copybara-service[bot] merged 1 commit intoAug 26, 2026
Conversation
…rash on invalid shapes
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds input rank validation to the convolution_internal helper function in tensorflow/python/ops/nn_ops.py to ensure that the input tensor has a rank of at least num_spatial_dims + 1. It also adds corresponding unit tests (testInvalidInputRank) to verify this behavior for both atrous_conv2d and convolution operations. I have no feedback to provide.
dianatofficial
left a comment
There was a problem hiding this comment.
Solid PR. Tests cover the important paths.
dmiltr3
approved these changes
Aug 24, 2026
copybara-service
Bot
merged commit Aug 26, 2026
deb1655
into
tensorflow:master
18 of 19 checks passed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When calling
tf.nn.atrous_conv2dortf.nn.convolutionwith an invalid input tensor rank (for example, a rank-1 or rank-2 tensor when performing 2D convolution with rank-4 filters), execution on CPU triggers a fatal check failure abort:Root cause
In
tensorflow/python/ops/nn_ops.py:convolution_internal,num_spatial_dimsis computed fromfilters.shape.rank - 2(e.g.4 - 2 = 2for 2D convolution). The number of batch dimensions was calculated asnum_batch_dims = inputs_rank - num_spatial_dims - 1.When
inputs_rank < num_spatial_dims + 1(e.g.inputs_rank = 1for a 1D input to 2D convolution),num_batch_dimsbecame negative (1 - 2 - 1 = -2), leading to an invalidchannel_index = num_batch_dims + num_spatial_dims = 0. This caused_get_sequenceto construct malformed stride/dilation sequences and passed invalid shapes to the C++ kernel where an internal dimension check failure terminated the process on CPU. Additionally, wheninputs_rank == 0(scalar),if inputs_rank:evaluated toFalseand incorrectly fell back tonum_batch_dims = 1.Fix
In
convolution_internal, wheninputs_rank is not None, validate thatnum_batch_dims = inputs_rank - num_spatial_dims - 1 >= 0. Ifinputs_rank < num_spatial_dims + 1, raise a descriptiveValueErrorindicating that the input must have rank at leastnum_spatial_dims + 1(spatial dimensions + channel dimension), preventing malformed parameters from reaching the underlying kernels.Testing
testInvalidInputRankintensorflow/python/kernel_tests/nn_ops/atrous_conv2d_test.py.testInvalidInputRankintensorflow/python/kernel_tests/nn_ops/atrous_convolution_test.py.python3 -m py_compile.Fixes #125510.