Repository navigation
Closed
Labels
2.17Issues related to 2.17 releaseawaiting PR mergeawaiting PR mergecomp:gpuGPU related issuescomp:opsOPs related issuestype:bugBug
Description
Issue type
Bug
Have you reproduced the bug with TensorFlow Nightly?
No
Source
source
TensorFlow version
tf 2.17
Custom code
Yes
OS platform and distribution
No response
Mobile device
No response
Python version
No response
Bazel version
No response
GCC/compiler version
No response
CUDA/cuDNN version
No response
GPU model and memory
No response
Current behavior?
In a Linux + GPU environment, calling tf.linalg.solve on singular matrices yields different results on GPU depending on the matrix shape:
For a 3×3 singular matrix, the CPU backend raises InvalidArgumentError, but the GPU backend returns an identity matrix without error.
For a 2×2 singular matrix, both CPU and GPU backends correctly raise InvalidArgumentError.
Standalone code to reproduce the issue
import tensorflow as tf
for name, matrix in [
("3×3 float64 singular matrix", tf.constant([
[1.0, 2.0, 3.0],
[2.0, 5.0, 6.0],
[3.0, 6.0, 9.0]
], dtype=tf.float64)),
("2×2 float64 singular matrix", tf.constant([
[1.0, 2.0],
[2.0, 4.0]
], dtype=tf.float64))
]:
print(f"\n=== {name} ===")
with tf.device('/CPU:0'):
try:
x_cpu = tf.linalg.solve(matrix, matrix)
print("CPU solve ->\n", x_cpu.numpy())
except Exception as e:
print("CPU solve raised:", type(e).__name__, e)
with tf.device('/GPU:0'):
try:
x_gpu = tf.linalg.solve(matrix, matrix)
print("GPU solve ->\n", x_gpu.numpy())
except Exception as e:
print("GPU solve raised:", type(e).__name__, e)Relevant log output
=== 3×3 float64 singular matrix ===
CPU solve raised: InvalidArgumentError {{function_node __wrapped__MatrixSolve_device_/job:localhost/replica:0/task:0/device:CPU:0}} Input matrix is not invertible. [Op:MatrixSolve] name:
GPU solve ->
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
=== 2×2 float64 singular matrix ===
CPU solve raised: InvalidArgumentError {{function_node __wrapped__MatrixSolve_device_/job:localhost/replica:0/task:0/device:CPU:0}} Input matrix is not invertible. [Op:MatrixSolve] name:
GPU solve raised: InvalidArgumentError {{function_node __wrapped__MatrixSolve_device_/job:localhost/replica:0/task:0/device:GPU:0}} Input matrix is not invertible. [Op:MatrixSolve] name:Metadata
Metadata
Assignees
Labels
2.17Issues related to 2.17 releaseawaiting PR mergeawaiting PR mergecomp:gpuGPU related issuescomp:opsOPs related issuestype:bugBug
Activity
Venkat6871 commentedon Jun 5, 2025
I was able to reproduce the issue using TensorFlow version 2.19.0 and the nightly build. I have attached a Gist for your reference.
Thank you!
tripathi-genius commentedon Jun 20, 2025
Is it open for contribution? I want to contribute.
Venkat6871 commentedon Jun 23, 2025
Hi @tripathi-genius ,
Yes, TensorFlow welcomes contributions! Please feel free to submit a Pull Request (PR). I am sharing the contribution guide for your reference, kindly follow the guidelines provided there.
Thank you!
github-actions commentedon Jul 10, 2025
This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.
girinithr commentedon Jul 21, 2025
i wish to contribute to this, can i take up this task and contribute?
Venkat6871 commentedon Jul 22, 2025
Hi @girinithr ,
Yes, TensorFlow welcomes contributions! Please feel free to submit a Pull Request (PR). I am sharing the contribution guide for your reference, kindly follow the guidelines provided there.
Thank you!
HamiAlyasin54 commentedon Aug 27, 2025
Harshit057 commentedon Feb 3, 2026
Thanks for the updates and the linked PRs (#103324, #109335).
I can help by validating the fix on GPU (different shapes / dtypes / batched vs non-batched cases) and checking consistency with CPU error behavior. If there are specific scenarios you’d like tested, I’m happy to do so.
Fix GPU MatrixSolve not detecting singular matrices for certain shapes
Fix GPU MatrixSolve not detecting singular matrices for certain shapes
Fix GPU MatrixSolve not detecting singular matrices for certain shapes
google-ml-butler commentedon Aug 11, 2026
Are you satisfied with the resolution of your issue?
Yes
No