You shouldn’t transform tensor to numpy like this:
batch_x = x.view(-1, 1input_layer).cpu().numpy()
batch_y = x.view(-1, 1input_layer).cpu().numpy()
but write  as follows
batch_x = x.view(-1, 1input_layer).to(device)
batch_y = x.view(-1, 1input_layer).to(device)