这是indexloc提供的服务,不要输入任何密码
Skip to content

tf.linalg.matrix_rank produces inconsistent output on CPU vs GPU with tol=6 #97102

@jiren-the-gray

Description

@jiren-the-gray

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

source

TensorFlow version

2.20.0-dev20250715

Custom code

Yes

OS platform and distribution

Linux Ubuntu 20.04

Mobile device

No response

Python version

3.12

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

Running tf.linalg.matrix_rank with a float64 tensor with tol=6 produces different values on CPU vs GPU. On the release versions 2.18.0 and 2.19.0, neither CPU or GPU produced the same output as numpy (see colab). On nightly (2.20.0-dev20250715), the output from GPU matched the output from numpy but the CPU output did not match.

Standalone code to reproduce the issue

import tensorflow as tf
import numpy as np

print(tf.__version__)   # 2.20.0-dev20250715

a = tf.ones((48, 74), dtype=tf.float64) * -88917319269045.
tol = 6.

with tf.device('/cpu:0'):
    output_cpu = tf.linalg.matrix_rank(a, tol=tol)

with tf.device('/gpu:0'):
    output_gpu = tf.linalg.matrix_rank(a, tol=tol)

output_np = np.linalg.matrix_rank(a.numpy(), tol=tol)

print("CPU output:", output_cpu)        # 4
print("GPU output:", output_gpu)        # 1
print("NumPy output:", output_np)       # 1

Relevant log output

2.20.0-dev20250715
CPU output: tf.Tensor(4, shape=(), dtype=int32)
GPU output: tf.Tensor(1, shape=(), dtype=int32)
NumPy output: 1

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions