Validate input rank in the tf2xla QR and SVD kernels - #126542
Merged
copybara-service[bot] merged 1 commit intoSep 3, 2026
Merged
Conversation
The tf2xla kernels for Qr, Svd, and XlaSvd passed their input straight to the XLA builder libraries without checking its rank. The graph-level shape functions reject inputs of known rank below 2, but an input of unknown static rank, for example one produced by StackPopV2, reaches the kernels unchecked at compile time. QrExplicit then reads dimension rank - 2 = -1 and dies on a fatal ShapeUtil check, and SvdOp dies on the dim_size range check in TensorShape, aborting the process instead of failing compilation. Validate rank >= 2 in all three kernels before any trailing dimensions are read, mirroring the validation and message style of the neighboring MatrixSolve kernel and the errors already produced by the Cholesky and SelfAdjointEig builder libraries. The regression tests feed a rank-1 value through an unknown-rank placeholder, which reproduces the abort on unfixed builds, and assert that a regular InvalidArgumentError is raised instead. Fixes tensorflow#110798
dmiltr3
approved these changes
Sep 1, 2026
This was referenced Sep 3, 2026
This was referenced Sep 3, 2026
This was referenced Sep 3, 2026
copybara-service
Bot
merged commit Sep 3, 2026
91fd803
into
tensorflow:master
19 of 20 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.
Fixes #110798.
Problem
The tf2xla kernels for
Qr,Svd, andXlaSvdpass their input straight into the XLA builder libraries without validating its rank. The graph-level shape functions reject known-rank inputs below rank 2, but an input whose static rank is unknown, such as the reporter'sStackPopV2output or any unknown-rank placeholder, reaches the kernels unchecked at XLA compile time:QROp::Compilecallsxla::QrExplicit, which reads dimensionrank - 2 = -1and dies on the fatalShapeUtil::GetDimensionNumbercheck (shape_util.cc:952, the check in the report).SvdOp::Compiledies one step earlier, on its owninput_shape.dim_size(dims() - 2)call, hitting thed >= 0check inTensorShape::dim_size. This sibling was found while verifying the report and is fixed here as well;XlaSvdOpshares the same gap.Both reproduce on XLA CPU with
jit_compile=True(verified locally, exit 134 with the reported check-failure text for QR and the TensorShape variant for SVD). The neighboringCholeskyandSelfAdjointEiglowerings already reject rank-1 inputs with cleanInvalidArgumentErrors, which confirms the intended behavior for this input class.Fix
Validate
rank >= 2in all three kernels before any trailing dimensions are read, using the validation and message style of the neighboringMatrixSolvekernel ("Input must have rank >= 2, got shape ..."). Compilation now fails with a regularInvalidArgumentErrorinstead of aborting the process.Tests
testVectorInputRaisesErrorincompiler/tests/qr_op_test.pyandcompiler/tests/svd_op_test.pyfeeds a rank-1 value through an unknown-rank placeholder, which is exactly the path that bypasses graph-level shape inference; on unfixed builds this aborts the test process, and with the fix it asserts theInvalidArgumentError. BUILD dependencies updated for the strict-deps targets (kernel targets gain the absl status and strings deps used by the new checks, test targets gain//tensorflow/python/framework:errors).