### Issue type

Bug

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

Yes

### Source

source

### TensorFlow version

tf2.17

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

Version
TensorFlow Version: 2.17 (based on traceback)
CUDA Environment: GPU-enabled system
Total GPU Memory: 51.04 GB (51041271808 bytes)
Python Version: 3.10
Current Behavior
Error Description
The application crashes during CUDA device context initialization when calling tf.raw_ops.GatherV2with an invalid axis parameter (axis=9 for a 2D tensor). The failure occurs before any gather operation, during GPU context acquisition.
Error Log
RuntimeError: Bad StatusOr access: INTERNAL: failed initializing StreamExecutor for CUDA device ordinal 0: INTERNAL: failed call to cuDevicePrimaryCtxRetain: CUDA_ERROR_OUT_OF_MEMORY: out of memory; total memory reported: 51041271808
Steps to Reproduce

### Standalone code to reproduce the issue

```shell
import tensorflow as tf
resource = tf.Variable([[1, 2, 3], [4, 5, 6]], dtype=tf.int32)
indices = tf.constant([0, 1], dtype=tf.int32)
dtype = tf.int32
batch_dims = 0
output = tf.raw_ops.GatherV2(params=resource, indices=indices, axis=
    9, batch_dims=batch_dims)
```

### Relevant log output

```shell

```