The gradient of tf.math.digamma is NaN on GPU and 0.0 on CPU when the input is inf
@mazeltovlee 
I was able to replicate the issue on Google Colab with TF v2.11 on both CPU(output is 0.0) and GPU(output is nan).  Please find the gist for the same [here-CPU](https://colab.sandbox.google.com/gist/synandi/ae802b0f544e5369425e75c1f5f9b451/59647_cpu.ipynb) and [here-GPU](https://colab.sandbox.google.com/gist/synandi/29c159a1b541e83f5717cb1f0d4db61f/59647_gpu.ipynb). It seems like we have to dig more into this issue, we will update soon here. Thank you! Hi @mazeltovlee, Apologies for the delay. On a GPU, floating point operations are performed using a special hardware that is optimized for parallel computation. This hardware may use different algorithms or have different rounding behavior compared to a CPU, which can lead to different results for the same calculation.

In your case of `tf.math.digamma(x)` where x is equal to inf, the output is undefined mathematically. 
When x is set to inf, the result of the function is undefined, and the gradient of the function is also undefined. However, due to rounding errors and implementation differences, it may be evaluated as NaN on a GPU and as 0 on a CPU. 
Thank you! This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.
 Closing as stale. Please reopen if you'd like to work on this further. 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/59647">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/59647">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

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

Yes

### Source

source

### Tensorflow Version

2.11.0

### Custom Code

Yes

### OS Platform and Distribution

_No response_

### Mobile device

_No response_

### Python version

3.8

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

```shell
The gradient of tf.math.digamma is NaN when receiving inf as input. This issue only happens on GPU mode, when I run the program on CPU, the gradient is 0.
```


### Standalone code to reproduce the issue

```shell
import tensorflow as tf
import numpy as np


x = tf.Variable(np.inf, dtype="float32")

with tf.GradientTape() as g0:
    g0.watch(x)
    res = tf.math.digamma(x)
tf_grad = g0.gradient(res, x)
print("The gradient of digamma is: ", tf_grad)  # The gradient of digamma is:  tf.Tensor(nan, shape=(), dtype=float32)
```


### Relevant log output

```shell
The gradient of digamma is:  tf.Tensor(nan, shape=(), dtype=float32)
```
</details>