RuntimeError: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED when calling `cublasSgemm 解决方案

目录


问题描述

跑pytorch相关的代码时,在根据requirements.txt进行环境配置后,运行模型测试代码,出现了以下错误

  File "/opt/conda/envs/uof/lib/python3.7/site-packages/torch/nn/modules/module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "/opt/conda/envs/uof/lib/python3.7/site-packages/torch/nn/modules/linear.py", line 87, in forward
    return F.linear(input, self.weight, self.bias)
  File "/opt/conda/envs/uof/lib/python3.7/site-packages/torch/nn/functional.py", line 1372, in linear
    output = input.matmul(weight.t())
RuntimeError: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED when calling `cublasSgemm( handle, opa, opb, m, n, k, &alpha, a, lda, b, ldb, &beta, c, ldc)`

在网上查询这个问题的解决方案千奇百怪,尝试之后都没有成功解决。

解决方案

后来猜想应当是pytorch、cuda和python版本不匹配的问题(之前遇到过一次python版本为3.8过高装不上低版本pytorch~=1.3.0的情况),去查找了cuda、pytorch和python之间的版本对应关系表:

https://blog.csdn.net/weixin_45564943/article/details/121688734

 RuntimeError: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED when calling `cublasSgemm 解决方案

根据目前的cuda版本(11.2),python版本(3.7),选择了安装pytorch~=1.7.0版本:

pip uninstall torch==1.3.0
pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

 成功解决了该问题

后记

下次再安装pytorch时,一定要考虑python和cuda版本再做选择,不要盲目依赖requirements.txt。

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
社会演员多的头像社会演员多普通用户
上一篇 2023年3月5日 下午4:41
下一篇 2023年3月5日 下午4:42

相关推荐