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)

相关推荐
代码山河8 小时前
Python就业方向全解析:后端、爬虫、数据分析、AI你选哪个?
python·学习·架构·教程·面向对象·项目
在世修行8 小时前
智学文枢:题目流水线
python·多线程·状态机·pyside
梯度下降者8 小时前
零基础入门Python 爬虫
爬虫·python·数据分析·入门指南·webcrawler
“AI国潮设计-小江”10 小时前
【AIGC实战】Python+Stable Diffusion打造“英歌舞财神”IP,解锁“马到成功”等爆款情绪营销文案设计
开发语言·人工智能·python·prompt·aigc
benchmark_cc11 小时前
用 Python 拉 A 股全市场实时快照:Notebook 请求、结果校验与易错点
python·数据分析·pandas·量化交易·股票数据·quantdash
伞伞悦读11 小时前
【第70期】Adam二阶矩不是方差:偏差校正、动量与AdamW完整实验
python
外收内放12 小时前
Python基础语法练习题(73)
java·前端·python
锋行天下12 小时前
Langgraph HITL 中断运行,用户输入后输出打字效果
人工智能·python
时早玖沐12 小时前
给 AstrBot 写一个天气推送插件:12 次提交、6 个坑
python·开源·ai编程
触底反弹12 小时前
🚀 FastAPI 五大重难点深度剖析:从 500 报错到彻底搞懂 Depends、Pydantic 与 SQLAlchemy
python·fastapi