Try Y_pred.append(output.detach().numpy()).
I overlooked this part. I think it’s coming because Y_pred is on cpu while output is on cuda. You have to transfer it to cpu before appending  it which is what detach does.