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)

相关推荐
“AI国潮设计-小江”9 小时前
《Python+SDXL实战:用ControlNet精准控制“英歌舞翻糖吐司”构图,附批量生成脚本》
开发语言·人工智能·python·prompt·aigc
wenwen_chao9 小时前
Python学习与开发资源合集:实用技巧与工具推荐
python
for_ever_love__10 小时前
函数——参数、lambda、*args与作用域
python·函数·大模型开发·编程基础
东莞市云毅网络有限公司10 小时前
企业资料时效性判定:Last-Modified、正文日期与版本字段三路交叉
python·sqlite·自动化运维·geo·数据监测
Query*10 小时前
深入浅出LangGraph【一】_基础篇
python·ai·langchain
XiaoMaqqqq11 小时前
市面上正规的IP驱动产业新场景新工具哪家强
运维·python·网络协议·tcp/ip
ShyanZh11 小时前
【Python3基础】19-Socket 与 TCP、UDP 编程
python·网络协议·tcp/ip·udp
惊讶的猫12 小时前
工具选对之后还不够:商城 Agent 的参数与权限治理
开发语言·python
天赐范式12 小时前
天赐范式第186天:让方差开始自洽——Bulmer效应的闭式验证
python·数字生命·天赐范式·动态运行时·遗传方差·bulmer效应
泡茶喝茶写代码12 小时前
A股量化数据工程:从 REST 接口到策略信号(第 8 篇):成长能力因子:营收与利润增速
java·python·股票数据api·股票数据api接口·股票量化数据api·股票量化数据接口·股票数据api数据