tf.signal.ifft2d` / `tf.signal.irfft` produce different CPU vs GPU NaN propagation for small `complex64` inputs containing `Inf

未关闭
#128,957 1 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 2 天内回复

@Kayyuri 已经在做这个了。

开始于 2026年10月13日。

评估

这个 Issue 还没有评估数据。

描述

2.20.0 comp:ops type:bug
Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

source

TensorFlow version

2.20.0

Custom code

Yes

OS platform and distribution

No response

Mobile device

No response

Python version

3.11.14

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

For small complex64 FFT inputs containing Inf, TensorFlow CPU and GPU produce different NaN propagation patterns.

Two examples are stable in three isolated runs:

  • tf.signal.ifft2d([[inf+0j, 1+0j], [2+0j, 3+0j]])
    • CPU imaginary components are finite zeros.
    • GPU imaginary components are all NaN.
    • NumPy matches the TensorFlow CPU pattern.
  • tf.signal.irfft([1+2j, inf+0j, -4+0j])
    • CPU returns [inf, 1.25, -inf, 1.25].
    • GPU returns [inf, nan, -inf, nan].
    • NumPy matches the TensorFlow CPU pattern.

A stronger non-finite control, tf.signal.irfft([1+2j, inf-3j, -4+infj]), returns all NaN on CPU, GPU, and NumPy, so the issue is not that all non-finite FFT outputs are being flagged as wrong.

Expected behavior

If TensorFlow considers CPU and GPU FFT non-finite propagation to have the same semantic contract, these small inputs should produce consistent NaN/Inf patterns across devices.

If backend-specific non-finite propagation is expected for FFT kernels, it would be helpful for the documentation or error notes to make that explicit. I am filing this as a CPU/GPU consistency issue rather than a strict finite-value correctness claim.

Standalone code to reproduce the issue
import numpy as np
import tensorflow as tf

print("TensorFlow:", tf.__version__)
print("GPUs:", tf.config.list_physical_devices("GPU"))

def run(device):
    with tf.device(device):
        a = tf.constant(
            np.array(
                [[np.inf + 0j, 1 + 0j], [2 + 0j, 3 + 0j]],
                dtype=np.complex64,
            )
        )
        b = tf.constant(
            np.array([1 + 2j, np.inf + 0j, -4 + 0j], dtype=np.complex64)
        )
        c = tf.constant(
            np.array([1 + 2j, np.inf - 3j, -4 + np.inf * 1j], dtype=np.complex64)
        )
        return {
            "ifft2d": tf.signal.ifft2d(a).numpy(),
            "irfft": tf.signal.irfft(b).numpy(),
            "irfft_control": tf.signal.irfft(c).numpy(),
        }

cpu = run("/CPU:0")
gpu = run("/GPU:0")

np_ifft2d = np.fft.ifft2(
    np.array([[np.inf + 0j, 1 + 0j], [2 + 0j, 3 + 0j]], dtype=np.complex64)
)
np_irfft = np.fft.irfft(
    np.array([1 + 2j, np.inf + 0j, -4 + 0j], dtype=np.complex64)
)
np_control = np.fft.irfft(
    np.array([1 + 2j, np.inf - 3j, -4 + np.inf * 1j], dtype=np.complex64)
)

for name in ["ifft2d", "irfft", "irfft_control"]:
    print("\n", name)
    print("CPU:", cpu[name])
    print("GPU:", gpu[name])

print("\nNumPy ifft2d:", np_ifft2d)
print("NumPy irfft:", np_irfft)
print("NumPy control:", np_control)
Relevant log output
TensorFlow: 2.20.0

ifft2d
CPU: [[inf+0.j inf+0.j]
      [inf+0.j inf+0.j]]
GPU: [[inf+nanj inf+nanj]
      [inf+nanj inf+nanj]]

irfft
CPU: [ inf  1.25 -inf  1.25]
GPU: [ inf  nan -inf  nan]

irfft_control
CPU: [nan nan nan nan]
GPU: [nan nan nan nan]

NumPy ifft2d: [[inf+0.j inf+0.j]
               [inf+0.j inf+0.j]]
NumPy irfft: [ inf  1.25 -inf  1.25]
NumPy control: [nan nan nan nan]
主要语言
C++
星标
201k
派生
78.4k
平均合并
3 天 2 小时
30 天内合并 PR
452

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

tensorflow/tensorflow 的其他 Issue

查看 tensorflow/tensorflow 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。