Ahmed_Abdelaziz:

I assumed that anomaly detection find the first occurrence of NaN and reports it


It does, but it can only look at the backward pass. So if nans happen in the forward, they won’t be reported.
You will need to add prints directly in your code to check where the nan appears.
In particular, you can check your_tensor.isnan().any() ? To check that in the forward.