Sometimes GPU tensors are automatically detached onto CPU

It looks like this happens randomly.

I mean code sometimes runs without error but the other time code complains error,
saying “expected float cuda tensor”.

I checked the tensor was on the CPU device which was supposed to be on the GPU
and tensor was filled with all 0s.

Why does this happen and how can I solve this?

Do you have a (small) executable code snippet so that we could debug this issue?

Hi, ptrblck. As I trace the code to create snippet, I found some potential issue part.
I’ll try to debug that part. And if the issue keeps unsolved, I’ll write the post.