An error was raised by this line of code y = y.numpy() while training on the GPU. y should be moved to the CPU before converting it to a numpy array.
You can replace y = y.numpy() with y = y.cpu().numpy()