`tf.math.reduce_prod` produces wrong second-order gradient
@SuryanarayanaY I was able to replicate the issue in TF v[2.12](https://colab.research.google.com/gist/sushreebarsa/aa434c17414f0a57f5a8495245b7e26d/61117.ipynb), v[2.13](https://colab.research.google.com/gist/sushreebarsa/2520aca5bc8afa21acbdc8e43deb3e88/61117.ipynb#scrollTo=x_SdosaHmLAm) and [tf-nightly](https://colab.research.google.com/gist/sushreebarsa/375153ae4d26a1b8a9a40e794fa34fca/untitled803.ipynb#scrollTo=545PV9JXmFNe) . Please find the attached gists  here. 
Thank you!
<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

Yes

### Source

source

### Tensorflow Version

2.14.0-dev20230628

### Custom Code

Yes

### OS Platform and Distribution

Linux Ubuntu 20.04

### Mobile device

_No response_

### Python version

3.9

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

`tf.math.reduce_prod` produces wrong second-order gradient when the input tensor has a `0` element. 

In the following example, `d2z_dydx` should be `1`, but the output value is `0`. Note that, if we replace `z = tf.math.reduce_prod(tf.stack([x, y]))` with `z = x * y`, the assertion passes.

### Standalone code to reproduce the issue

```shell
import tensorflow as tf
x = tf.Variable(0.0)
y = tf.Variable(1.0)
with tf.GradientTape(persistent=True) as t1:
    t1.watch(x)
    t1.watch(y)
    with tf.GradientTape(persistent=True) as t2:
        t2.watch(x)
        t2.watch(y)
        z = tf.math.reduce_prod(tf.stack([x, y]))
    print('z = x * y: ', z)  
    dz_dx = t2.gradient(z, x) # dz_dx = y
    print('dz_dx: ', dz_dx)
    dz_dy = t2.gradient(z, y) # dz_dy = x
    print('dz_dy: ', dz_dy)

d2z_dx2 = t1.gradient(dz_dx, x) # d2z_dx2 = 0
print('d2z_dx2', d2z_dx2)
d2z_dxdy = t1.gradient(dz_dx, y) # d2z_dxdy = 1
print('d2z_dxdy', d2z_dxdy)
assert d2z_dxdy == 1
d2z_dydx = t1.gradient(dz_dy, x) # d2z_dydx = 1
print('d2z_dydx', d2z_dydx)
assert d2z_dydx == 1, 'd2z_dydx = {}'.format(d2z_dydx)
# AssertionError: d2z_dydx = 0.0
```


### Relevant log output

```shell
AssertionError: d2z_dydx = 0.0
```
</details>