Bug in tf.test.compute_gradient for tf.keras.layers.GlobalMaxPooling2D
Same problem can be found in tf.keras.layers.GlobalMaxPooling3D. Here is the repo code:
```
import tensorflow as tf

data_format = "channels_first"
keepdims = False
__input___0_tensor = tf.random.uniform([2, 4, 3, 1, 1], minval=0, maxval=0, dtype=tf.float64)
__input___0 = tf.identity(__input___0_tensor)
GlobalMaxPooling3D_class = tf.keras.layers.GlobalMaxPooling3D(data_format=data_format, keepdims=keepdims)

layer = GlobalMaxPooling3D_class
inputs = __input___0

r = GlobalMaxPooling3D_class(inputs)
theoretical, numerical = tf.test.compute_gradient(GlobalMaxPooling3D_class, [inputs])
print(theoretical)
print(numerical)
``` Same problem can be found in tf.keras.layers.MaxPooling1D. Here is the repo code:
```
pool_size_0 = 2
pool_size = [pool_size_0, ]
strides_0 = 3
strides = [
    strides_0, ]
padding = "valid"
data_format = "channels_last"
__input___0_tensor = tf.random.uniform([3, 5, 4], minval=0.0, maxval=0.0, dtype=tf.float64)
__input___0 = tf.identity(__input___0_tensor)
MaxPooling1D_class = tf.keras.layers.MaxPooling1D(pool_size=pool_size, strides=strides, padding=padding, data_format=data_format)

layer = MaxPooling1D_class
inputs = __input___0

r = MaxPooling1D_class(inputs)
theoretical, numerical = tf.test.compute_gradient(MaxPooling1D_class, [inputs])
print(theoretical)
print(numerical)
``` @SuryanarayanaY I was able to replicate the issue on colab, please find the [gist](https://colab.research.google.com/gist/sushreebarsa/28c3f8073fe8fcd7c9d62212fdec1e0f/62435.ipynb) here.
Thank you!
### Issue type

Bug

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

No

### Source

source

### TensorFlow version

tf 2.14.0

### Custom code

Yes

### OS platform and distribution

windows colab

### Mobile device

_No response_

### Python version

3.10

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

The numerical gradient and theoretical gradient for `tf.keras.layers.GlobalMaxPooling2D` is different, one is `0.2`, the other is `0.5`. 

### Standalone code to reproduce the issue

```shell
import tensorflow as tf

data_format = "channels_last"
keepdims = False
__input___0_tensor = tf.random.uniform([3, 5, 1, 1], minval=0, maxval=0, dtype=tf.float64)
__input___0 = tf.identity(__input___0_tensor)
GlobalMaxPooling2D_class = tf.keras.layers.GlobalMaxPooling2D(data_format=data_format, keepdims=keepdims)

layer = GlobalMaxPooling2D_class
inputs = __input___0

r = GlobalMaxPooling2D_class(inputs)
theoretical, numerical = tf.test.compute_gradient(GlobalMaxPooling2D_class, [inputs])
print(theoretical)
print(numerical)
```


### Relevant log output

```shell
(array([[0.2, 0.2, 0.2, 0.2, 0.2, 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,
        0. , 0. ],
       [0. , 0. , 0. , 0. , 0. , 0.2, 0.2, 0.2, 0.2, 0.2, 0. , 0. , 0. ,
        0. , 0. ],
       [0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.2, 0.2, 0.2,
        0.2, 0.2]]),)
(array([[0.5, 0.5, 0.5, 0.5, 0.5, 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,
        0. , 0. ],
       [0. , 0. , 0. , 0. , 0. , 0.5, 0.5, 0.5, 0.5, 0.5, 0. , 0. , 0. ,
        0. , 0. ],
       [0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.5, 0.5, 0.5,
        0.5, 0.5]]),)
```
