Skip to content

tf.math.abs returns inconsistent results for complex inf/nan inputs on CPU and GPU #98410

@rookieLiu2018

Description

@rookieLiu2018

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

source

TensorFlow version

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?

tf.math.abs produces inconsistent results on CPU versus GPU when the input is a complex number containing both inf and nan components.

Standalone code to reproduce the issue

import tensorflow as tf
import numpy as np

input_tensor = tf.constant([
    complex(np.inf, np.nan)
], dtype=tf.complex128)


with tf.device('/CPU:0'):
    cpu_out = tf.math.abs(input_tensor)
print(f"CPU Output: {cpu_out.numpy()}")

with tf.device('/GPU:0'):
    gpu_out = tf.math.abs(input_tensor)
print(f"GPU Output: {gpu_out.numpy()}")

Relevant log output

CPU Output: [inf]
GPU Output: [nan]

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions