I change the device by torch.device(“cuda:1”) but it got such problem. The program stucks at creating tensor b.?

Just to be clear, in this case, you did not use “os.environ[“CUDA_VISIBLE_DEVICES”] = “1”” ?
(Because I think if you use that like, torch.device(“cuda:1”) will be equivalent  to torch.device(“cuda:0”), and there is no  torch.device(“cuda:1”) then.)