The code also crashed on my machine (using CPU).
It seems, the segmentation fault is thrown when calling loss.backward().
I moved the loss.backward() call to get_loss and the segmentation fault disappeared.
Unfortunately, I have no idea, why you cannot return the loss and call backwards afterwards on it.
Besides that, I would remove the get_loss parameter from opt.step(), since you don’t need a closure 3 using RMSprop.