torch 和paddle 的GPU版本可以放在同一个conda环境下吗

新建conda 虚拟环境,python 版本3.8.17

虚拟机,系统centos 7,内核版本Linux fastknow 3.10.0-1160.92.1.el7.x86_64 ,显卡T4,nvidia-smi ,460.32.03,对应cuda 11.2,安装cuda 11.2和cudnn,conda 版本23.1

conda 安装paddle GPU 版本2.4.2+cuda112,pip安装torch 2.0.1+cuda11.7,

单执行

import paddle

paddle.utils.run_check()

不报错,并且基于paddle的应用也可以使用

单执行

import torch

torch.cuda.is_available()

print(torch.rand(3,3).cuda())

不报错,并且基于torch的应用也可以使用

但是....,如果同时导入2个包,问题就来了

import torch

torch.rand(3,3).cuda()

import paddle

paddle.utils.run_check()

第3行就会报如下错误

ExternalError: CUBLAS error(15).

Hint: Please search for the error code(15) on website (https://docs.nvidia.com/cuda/cublas/index.html#cublasstatus_t) to get Nvidia's official solution and advice about CUBLAS Error. (at /paddle/paddle/phi/kernels/funcs/blas/blas_impl.cu.h:35)

operator \< matmul_v2 \> error

并且paddle gpu版本还没法使用,会报和上述类似的错误,如下所示

(External) CUBLAS error(15).

Hint: Please search for the error code(15) on website (https://docs.nvidia.com/cuda/cublas/index.html#cublasstatus_t) to get Nvidia's official solution and advice about CUBLAS Error. (at /paddle/paddle/phi/kernels/funcs/blas/blas_impl.cu.h:35)

operator \< fc \> error

换个顺序执行

import paddle

paddle.utils.run_check()

import torch

第3行导入torch 就会报如下错误

File "/虚拟环境名字/lib/python3.8/site-packages/torch/init.py", line 229, in <module>

from torch._C import * # noqa: F403

ImportError: /home/haieradmin/test/miniconda3/envs/langchain/lib/python3.8/site-packages/torch/lib/libtorch_cuda.so: symbol cudaGraphDebugDotPrint, version libcudart.so.11.0 not defined in file libcudart.so.11.0 with link time reference

但是换成办公电脑win10 系统,版本号21H2,内部版本19044.1889,conda 4.13.0,显卡3080,nvidia-smi 驱动512.95,cuda 11.6,安装cuda 11.6和cudnn,paddle 2.4.2+cuda116,torch 1.13.1+cuda116, 两者可以并存且基本很好的工作(没有看到报错)

然后再换成新的服务器,ubuntu 20.04,显卡T4,nvidia-smi 515.65.01,cuda 11.7,安装cuda 11.7和cudnn 8.8.0,然后创建虚拟环境,安装torch 和paddle,两者基本可以并存并很好的工作

再次在上述虚拟机上重新新建conda 环境,先pip安装torch(非源码安装,官网上貌似没有cuda11.2对应的torch,安装的cudatoolkit是11.3),再pip安装paddle+cuda112,发现torch 和paddle 一样存在冲突,和上面的错误一样

然后卸载原来的torch,再重新安装低版本cuda对应的torch ,对应的cudatoolkit 为11.1,pip install torch==1.10.0+cu111 torchvision==0.11.0+cu111 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html

再次运行发现,两者已经不冲突了,因此这个配置是torch 1.10.1+cu111,paddle 2.4.2+cuda112,两者可以并存并可以很好的工作。

原因分析: 貌似高版本torch自带cuda,它使用的cuda 是nvidia-smi 显示的cuda 版本,不需要机子安装的那个cuda,paddle 使用的cuda 也是nvidia-smi 显示的cuda 版本,但是paddle 需要安装cuda 和cudnn,torch 工作只需要驱动的cuda 兼容torch带的cuda 就可以。所以同时使用torch 和paddle ,要尽量做到nvidia-smi ,cuda, cudnn ,torch,paddle 的cuda 版本要一致,如果实在不一致(如torch没有cuda112的版本,paddle没有cuda113、cuda114的版本),建议先安装paddle,因为paddle需要安装cuda 和cudnn ,确保paddle正常工作后,再调测不同版本的torch,仅供参考

参考资料:

1https://github.com/PaddlePaddle/Paddle/issues/49519

2进行模型预测遇到以下错误OSError: (External) CUBLAS error(15)

相关推荐
世辰辰辰5 小时前
批量修改图片/文本名子
开发语言·python·批量修改文件名
myenjoy_17 小时前
MQTT 与 Sparkplug B——从车间到云端的最后一公里
网络·python
颜酱8 小时前
LangChain 输出解析器:把模型回复变成你要的数据
python·langchain
2401_873479408 小时前
企业安全运营中,如何用IP离线库提前发现失陷主机?三步实现风险画像
网络·数据库·python·tcp/ip·ip
weixin_523185328 小时前
Java基础知识总结(四):引用数据类型与参数传递机制
java·开发语言·python
码农飞哥9 小时前
我把RAG召回率从60%提到90%,就改了这两件事
python·知识库·向量检索·rag·效果提示
宸津-代码粉碎机9 小时前
Spring AI企业级实战|从RAG优化到Agent多工具调度
java·大数据·人工智能·后端·python·spring
yuhuofei20219 小时前
【Python入门】Python中的字典dict
python
Jinkxs9 小时前
Python基础 - 文件的写入操作 write与writelines方法
android·服务器·python
初学Python的小明9 小时前
Python格式化输出、运算符、分支&循环
python