Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge pull request #53695 from yongtang:53660-tf.sparse.split-crash #54075

Merged
merged 1 commit into from Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions tensorflow/core/kernels/sparse_split_op.cc
Expand Up @@ -30,11 +30,16 @@ class SparseSplitOp : public OpKernel {
}

void Compute(OpKernelContext* context) override {
const int64 axis_input = context->input(0).scalar<int64>()();
const Tensor& input_axis = context->input(0);
const Tensor& input_indices = context->input(1);
const Tensor& input_values = context->input(2);
const Tensor& input_shape = context->input(3);

OP_REQUIRES(context, TensorShapeUtils::IsScalar(input_axis.shape()),
errors::InvalidArgument(
"Input axis should be a scalar but received shape ",
input_axis.shape().DebugString()),
done);
OP_REQUIRES(context, TensorShapeUtils::IsMatrix(input_indices.shape()),
errors::InvalidArgument(
"Input indices should be a matrix but received shape ",
Expand All @@ -48,7 +53,8 @@ class SparseSplitOp : public OpKernel {
"Input shape should be a vector but received shape ",
input_shape.shape().DebugString()));

const int64 input_rank = input_shape.vec<int64>().size();
const int64 axis_input = input_axis.scalar<int64_t>()();
const int64 input_rank = input_shape.vec<int64_t>().size();
const int64 axis = (axis_input < 0) ? input_rank + axis_input : axis_input;

OP_REQUIRES(
Expand Down
9 changes: 9 additions & 0 deletions tensorflow/python/kernel_tests/sparse_split_op_test.py
Expand Up @@ -257,6 +257,15 @@ def testArgumentErrors(self):
with self.assertRaisesRegex(ValueError, 'axis is required'):
sparse_ops.sparse_split(num_split=2, sp_input=1)

def testInvalidArgumentError(self):
# Test case for GitHub issue 53660.
axis = [1, 2]
with self.assertRaisesRegexp(errors.InvalidArgumentError,
r'axis should be a scalar'):
self.evaluate(
sparse_ops.sparse_split(
sp_input=self._SparseTensor_4x6(), num_split=3, axis=axis))


if __name__ == '__main__':
test.main()