tensorflow / tensorflow/tensorflow

tf.keras.ops.numpy.sinc returns NaN gradient at zero where derivative should be zero

Open
#127,226 2 comments 0 reactions 1 assignee View on GitHub

@Venkat6871 is already working on this.

Since Sep 16, 2026.

2.21.0 awaiting PR merge comp:ops type:bug
Dominant language
C++
Stars
200k
Forks
76.9k
Avg merge
2d 3h
Merged PRs (30d)
433

Description

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

source

TensorFlow version

tf 2.21.0, also reproduced on tf 2.22.0-dev20260904

Custom code

Yes

OS platform and distribution

Linux Ubuntu 22.04

Mobile device

No response

Python version

Python 3.13.5

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

tf.keras.ops.numpy.sinc returns nan for the first derivative at a point where the normalized sinc function has a smooth extension and the derivative should be finite.

In the reproducer below, the function evaluates tf.keras.ops.numpy.sinc(2 * t + 1) at t = -0.5, so the argument to sinc is exactly zero. The forward value is correctly returned as 1.0. However, TensorFlow autodiff returns nan for the derivative with respect to t.

The expected derivative is 0.0, including the chain rule through 2 * t + 1.

Expected behavior?

The first derivative of tf.keras.ops.numpy.sinc(2 * t + 1) at t = -0.5 should be 0.0, not nan.

Standalone code to reproduce the issue
import os
os.environ["CUDA_VISIBLE_DEVICES"] = ""
os.environ["OMP_NUM_THREADS"] = "1"
os.environ["TF_NUM_INTRAOP_THREADS"] = "1"
os.environ["TF_NUM_INTEROP_THREADS"] = "1"

import tensorflow as tf

def target(t):
    return tf.keras.ops.numpy.sinc(2 * t + 1)

x = tf.constant(-0.5, dtype=tf.float64)

with tf.GradientTape() as tape:
    tape.watch(x)
    y = target(x)

actual = tape.gradient(y, x)
expected = 0.0

print("forward:", y.numpy())
print("actual:", actual.numpy())
print("expected:", expected)

if tf.math.is_nan(actual):
    print("BUG REPRODUCED: tf.keras.ops.numpy.sinc returns NaN gradient at zero")
else:
    print("not reproduced")
Relevant log output
forward: 1.0
actual: nan
expected: 0.0
BUG REPRODUCED: tf.keras.ops.numpy.sinc returns NaN gradient at zero

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.