Could you try to append prediction as:
prediction_list.append(prediction.detach().cpu().numpy())

Currently you are also storing the computation graph in the list, which will grow your memory usage unnecessarily. I’m not sure, how numpy handles a list of tensors, but I assume this might be the reason for the error.