torch.Tensor.get_device¶ Tensor.get_device() -> Device ordinal (整數)¶ 對於 CUDA 張量,此函數會傳回張量所在的 GPU 的裝置序數。對於 CPU 張量,此函數會傳回 -1。 範例 >>> x = torch.randn(3, 4, 5, device='cuda:0') >>> x.get_device() 0 >>> x.cpu().get_device() -1