How to handle RuntimeError: CUDA error: an illegal memory access was encountered in PyTorch?

Viewed 968

I am running some code with pytorch 1.7 and cuda 11.0 on my gpu enabled machine. I have a few classes that contain the code for a few different neural networks. My first class runs smoothly and the following print statements work:

Class A:

print("Device resnet", torch.cuda.current_device()) # Prints 0
print("Boxes resnet", boxes) # Prints the array of bounding boxes

Class A creates an instance of class b, passing in the boxes to the constructor. But when I do similar print statements in class b it crashes:

print("Device fastrcnn", torch.cuda.current_device()) # Prints 0
print("BOXES in fastrcnn", boxes) # crashes and prints the following error

This crashes and prints:

RuntimeError: CUDA error: an illegal memory access was encountered

How do I go about debugging this, I have already tried adding .cpu() and .cuda() to boxes to transfer them to the respective device but I get the exact same crash.

0 Answers
Related