Pybind11 Exception
Hi, Could you please test it with the latest Tensorflow version and with the below configuration.
<h4 id="gpu" data-text="GPU" role="presentation" style="box-sizing: inherit; margin: 32px 0px 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: ; font-variant-east-asian: ; font-variant-alternates: ; font-weight: ; font-stretch: ; font-size: 16px; line-height: ; font-family: Roboto, &quot;Noto Sans&quot;, &quot;Noto Sans JP&quot;, &quot;Noto Sans KR&quot;, &quot;Noto Naskh Arabic&quot;, &quot;Noto Sans Thai&quot;, &quot;Noto Sans Hebrew&quot;, &quot;Noto Sans Bengali&quot;, sans-serif; font-optical-sizing: ; font-kerning: ; font-feature-settings: ; font-variation-settings: ; letter-spacing: normal; overflow: hidden; text-overflow: ellipsis; margin-inline-end: -40px; padding-inline-end: 40px; color: rgb(32, 33, 36); orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><span class="devsite-heading" role="heading" aria-level="4" style="box-sizing: inherit;">GPU</span><button type="button" class="devsite-heading-link button-flat material-icons" aria-label="Copy link to this section: GPU" data-title="Copy link to this section: GPU" data-id="gpu" style="box-sizing: border-box; appearance: none; background: 0px center; border: 0px; border-radius: var(--devsite-button-border-radius,2px); box-shadow: none; color: var(--devsite-icon-color,var(--devsite-secondary-text-color)); cursor: pointer; display: inline-block; font-style: normal; font-variant-ligatures: ; font-variant-caps: ; font-variant-numeric: ; font-variant-east-asian: ; font-variant-alternates: ; font-weight: normal; font-stretch: ; font-size: 24px; font-family: &quot;Material Icons&quot;; font-optical-sizing: ; font-kerning: ; font-feature-settings: &quot;liga&quot;; font-variation-settings: ; height: 24px; letter-spacing: normal; line-height: 1; margin: var(--devsite-button-margin,0); margin-inline-end: var(--devsite-button-margin-x-end); max-width: var(--devsite-button-max-width,none); min-width: 36px; outline: 0px; overflow: hidden; padding: 0px 8px; text-align: center; text-decoration: none; text-overflow: ellipsis; text-transform: none; transition: background-color 0.2s ease 0s, border 0.2s ease 0s, box-shadow 0.2s ease 0s; vertical-align: bottom; white-space: nowrap; width: var(--devsite-button-width,auto); overflow-wrap: normal; direction: ltr; -webkit-font-smoothing: antialiased; opacity: 0;"></button></h4><div class="devsite-table-wrapper" style="box-sizing: inherit; margin: var(--devsite-table-margin,16px 0); padding: 0px; overflow: auto; color: rgb(32, 33, 36); font-family: Roboto, &quot;Noto Sans&quot;, &quot;Noto Sans JP&quot;, &quot;Noto Sans KR&quot;, &quot;Noto Naskh Arabic&quot;, &quot;Noto Sans Thai&quot;, &quot;Noto Sans Hebrew&quot;, &quot;Noto Sans Bengali&quot;, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">

Version | Python version | Compiler | Build tools | cuDNN | CUDA
-- | -- | -- | -- | -- | --
tensorflow-2.12.0 | 3.8-3.11 | GCC 9.3.1 | Bazel 5.3.0 | 8.6 | 11.8

</div>

Latest Tensorflow supports c++ 17 version, make sure your test is inline with the supported versions.
Let us know the outcome after your test with the latest version. Thanks! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. Hi, @sachinprasadhs. thanks for the reply. I have tried TensorFlow 2.12 with Python 3.8. and Python 3.9.

As I mentioned initially, there is no need for GPU processing (although the same can be seen there). I am not using C++ code and so there is no compiler or Build tools in my environment. In case Tensorflow requires packages it may have installed them. The command I used for installing TensorFlow 2.12 is ```pip install tensorflow```. After core dump with ```procdump -e 2 -l -f "" <PID of the process python running tensorflow code>``` I still see that pybind11 is generating many exceptions. @mraunak, Could you please take a look into this, this seems to be happening with CPU build also.  Hi @yahyanik, sorry for the delayed response. I was unable to reproduce the error. Could you please provide us with the steps to replicate the issue and view the exceptions you see?

I didn't get any exception messages when I ran the code snippet and capture the dump. Below is the screenshot of what output I got when I tried to replicate it:

![image](https://github.com/tensorflow/tensorflow/assets/83710963/4da75eaf-2449-4a08-ad7b-58a177fcf220)
 This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. Hi @mraunak and thanks for getting back to me. 

The problem statement is the same as I mentioned before. I can still see the same problem using Windows 10. These are not seen in the training phase of the sample code, they appear in the inferencing step. Here are two screenshots of what I see attached. 

![Capture1 (1)](https://github.com/tensorflow/tensorflow/assets/24399893/c32c496d-7ea4-44a7-a743-887d04344bcf)
![Capture2](https://github.com/tensorflow/tensorflow/assets/24399893/0eccb3a0-4ff3-450e-92c7-ccf0aa6b1d53)

Here is the code I used in python3.7 and tensorflow 2.9 today. I have tested other package variations as well, as we discussed before:

```
import tensorflow as tf
mnist = tf.keras.datasets.mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0


model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10)
])


predictions = model(x_train[:1]).numpy()
predictions


tf.nn.softmax(predictions).numpy()
loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
loss_fn(y_train[:1], predictions).numpy()

model.compile(optimizer='adam',
              loss=loss_fn,
              metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test,  y_test, verbose=2)

probability_model = tf.keras.Sequential([
  model,
  tf.keras.layers.Softmax()
])

probability_model(x_test[:5])
``` Hi @yahyanik, I see 13:05:26 on the above screenshot, is it 13 hrs? The entire code run including training and inferencing completes successfully within a minute on my system(Windows CPU) and I don't see any exceptions in the other command prompt with Procdump. How much does it take on your system?  
<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Support

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

No

### Source

source

### Tensorflow Version

tf 2.9, 2.7, 2.6, 2.5, 2.4, 2.3

### Custom Code

No

### OS Platform and Distribution

Windows 10

### Mobile device

_No response_

### Python version

3.7, 3.8

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

10.1, 11.2 and coresponding CuDNN

### GPU model and memory

3090, 1650

### Current Behaviour?

Running TensorFlow custom code or sample code provided the TensorFlow website creates exceptions when looking at the dump file from C++ side. 

I used procdump.exe to see the exceptions in Windows 10 as follows: 
Open a separate CMD.exe and run: ``` procdump -e 2 -l -f "" <PID of the process python running tensorflow code>```

sample code used:

```
from time import sleep
import tensorflow as tf

def fn_raw(inputs):
      return inputs*2

while True:
  fn = tf.function(fn_raw)
  r = fn(2)
  print(r)
  sleep(1)
```

sample code tested from the TensorFLow website is located at https://colab.research.google.com/github/tensorflow/docs/blob/master/site/en/tutorials/quickstart/beginner.ipynb

exceptions are seen at inference time (after the training period)

hundreds of exceptions, as follows, are dumped:

``` Exception: [E06D7363.?AVerror_already_set@pybind11@@]```

I tested TnesorFlow GPU and CPU with several versions of TensorFlow 2.x
According to Pybind11 documentation page, https://pybind11.readthedocs.io/en/stable/advanced/exceptions.html, this shows an issue with the Python code which is captured on C++ side.

PS: The code runs with no issues and completes the task. However, these exceptions are concerning.

### Standalone code to reproduce the issue

```shell
from time import sleep
import tensorflow as tf

def fn_raw(inputs):
      return inputs*2

while True:
  fn = tf.function(fn_raw)
  r = fn(2)
  print(r)
  sleep(1)
```
```


### Relevant log output

```shell
Exception: [E06D7363.?AVerror_already_set@pybind11@@]```
```
</details>