CUDA error: an illegal memory access was encountered

I came across the same issue. I double there’s some issue on hardware.
Because it works by use another card.
Could you try device = torch.device(“cuda:1”)