————解决PyTorch的相关问题
2)如果PyTorch是CPU方式,可以改_ _init.py_ _:
def set_device(device: _device_t) -> None:
r"""Sets the current device.
Usage of this function is discouraged in favor of :any:`device`. In most
cases it‘s better to use ``CUDA_VISIBLE_DEVICES`` environmental variable.
Args:
device (torch.device or int): selected device. This function is a no-op
if this argument is negative.
"""
device = _get_device_index(device)
if device >= 0:
#torch._C._cuda_setDevice(device)
torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
最后通过搜索“Win10+Anaconda安装CPU版本Pytorch与GPU版Pytorch”,找到相关的测试程序。
原文:https://www.cnblogs.com/shiningleo007/p/14962583.html