英文:
AssertionError: Torch not compiled with CUDA MacOS
问题
我克隆了一个git仓库,尝试运行代码。但是,我意识到一些操作已加载到GPU上。问题是MacOS不支持NVIDA,所以当我运行代码时会不断出现断言错误(如下所示)。对于任何建议,我将不胜感激。
请注意,代码相当庞大,因此我无法逐个文件查看并卸载这些操作。以下是示例代码。
for batch_idx, data in enumerate(valid_generator):
x, y, x1, y1 = data[0].squeeze(-1).to(device), data[1].squeeze(-1).to(device), data[2].squeeze(-1).to(device), data[3].squeeze(-1).to(device)
for param in transform.parameters():
param.requires_grad = False
param.volatile = True
names = sorted(glob.glob(data))
然后我收到以下错误消息:
raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled
英文:
I cloned a git repo and I'm trying to run the code. However, I realised that some operations were loaded to the GPU. The issue is that MacOS doesnt support NVIDA so I keep getting assertion error when I run the code(as seen below). Any suggestion will be appreciated.
Note that the code is quite bulky so I can't go through every file and offload these operations. Below is a sample code.
for batch_idx, data in enumerate(valid_generator):
x, y, x1, y1 = data[0].squeeze(-1).to(device), data[1].squeeze(-1).to(device), data[2].squeeze(-1).to(device), data[3].squeeze(-1).to(device)
for param in transform.parameters():
param.requires_grad = False
param.volatile = True
names = sorted(glob.glob(data))
And I get the error below
raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled
答案1
得分: 0
这可能足以在您的代码开头添加以下内容(告诉PyTorch使用CPU而不是GPU):
device = torch.device("cpu")
然后,您需要进行全局替换(您可能有机会在所有项目代码中自动执行它,借助您的IDE)将.cuda()
替换为 .to(device)
。
如果错误仍然存在,请尝试手动在shell中设置变量CUDA_VISIBLE_DEVICES
的值:
export CUDA_VISIBLE_DEVICES=""
如果在复杂的代码中无法执行批量方法替换,或者如果您打算在将来使用模型:
考虑使用带有GPU的远程机器。这通常是Mac用户的做法,根据我的经验。如果您的模型不是很大,可以使用Google Colab或其他类似的服务。
祝您好运
英文:
It might be enough to add this at the beginning of your code(the line telling PyTorch to use the CPU instead):
device = torch.device("cpu")
Then, you need to make a global replacement (you will probably have a chance to perform it automatically in all project's code with the help of your IDE) of .cuda()
to .to(device)
In case the error continues, try setting the value of the variable CUDA_VISIBLE_DEVICES
in the shell manually:
export CUDA_VISIBLE_DEVICES=""
In case it is impossible to perform mass method substitution in tangled code, or if you intend to work with models in the future:
Consider using a remote machine with a GPU. This is usually what Mac users do, in my experience. You can use Google Colab or other similar services if your model is not very large.
Wish you luck
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论