当我在 Google Colab 中运行 PyTorch 深度学习模型时,出现以下错误
/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in linear(input, weight, bias)
1370 ret = torch.addmm(bias, input, weight.t())
1371 else:
-> 1372 output = input.matmul(weight.t())
1373 if bias is not None:
1374 output += bias
RuntimeError: CUDA error: CUBLAS_STATUS_ALLOC_FAILED when calling `cublasCreate(handle)`
我什至将批量大小从 128 减少到 64,即减少到一半,但仍然出现此错误。早些时候,我以批量大小 128 运行相同的代码,但没有收到任何这样的错误。
不,在这种情况下,批量大小并不重要。
最可能的原因是标签数量和输出单元数量不一致。
- 尝试在正向传递中打印最终输出的大小并检查输出的大小
print(model.fc1(x).size())
Here fc1
返回之前将被替换为模型最后一个线性层的名称
- 确保
label.size()
等于prediction.size()
在计算损失之前
即使解决了这个问题之后,你也必须重新启动 GPU 运行时(我在使用 Colab GPU 时需要这样做)
此 GitHub 问题评论 https://github.com/pytorchbearer/torchbearer/issues/658#issuecomment-581407150可能也会有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)