Unexpected 0 when invoking tf.GradientTape() and tf.math.reduce_prod() both on CPU and GPU
Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62556">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62556">No</a>

### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

tf 2.13

### 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?

```python
import tensorflow as tf
import numpy as np

with tf.device("/cpu:0"):
  def test(x):
    with tf.GradientTape() as tape_1:
      tape_1.watch(x)
      w = tf.math.reduce_prod(x)
    grad_1 = tape_1.gradient(w, x)
    return grad_1

  x = tf.constant([[0, 0.1,0.2],[0, 0.1,0.2]],dtype=tf.float32)
  cpu_output_1 = test(x)

with tf.device("/gpu:0"):
  def test(x):
    with tf.GradientTape() as tape_1:
      tape_1.watch(x)
      w = tf.math.reduce_prod(x)
    grad_1 = tape_1.gradient(w, x)
    return grad_1

  x = tf.constant([[0, 0.1,0.2],[0, 0.1,0.2]],dtype=tf.float32)
  gpu_output_1 = test(x)

expect_out_1 = tf.constant([[0,0.2,0.4],[0,2,4.]],dtype=tf.float32)
print(expect_out_1)
print(cpu_output_1)
print(gpu_output_1)

### Standalone code to reproduce the issue

```shell
Unexpected 0 when invoking tf.GradientTape() and tf.math.reduce_prod() both on CPU and GPU
```


### Relevant log output

```shell
tf.Tensor(
[[0.  0.2 0.4]
 [0.  2.  4. ]], shape=(2, 3), dtype=float32)
tf.Tensor(
[[0. 0. 0.]
 [0. 0. 0.]], shape=(2, 3), dtype=float32)
tf.Tensor(
[[0. 0. 0.]
 [0. 0. 0.]], shape=(2, 3), dtype=float32)
```
