torch.device("cuda:0" if torch.cuda.is_available() else "cpu") 如果模型中的所有参数都在同一个设备上,可以使用next(model.parameters()).device。