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)

相关推荐
多恩Stone5 小时前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
QQ4022054965 小时前
Python+django+vue3预制菜半成品配菜平台
开发语言·python·django
百锦再5 小时前
Django实现接口token检测的实现方案
数据库·python·django·sqlite·flask·fastapi·pip
QQ5110082855 小时前
python+springboot+django/flask的校园资料分享系统
spring boot·python·django·flask·node.js·php
QQ_19632884755 小时前
Python-flask框架西山区家政服务评价系统网站设计与开发-Pycharm django
python·pycharm·flask
遥遥江上月5 小时前
Node.js + Stagehand + Python 部署
开发语言·python·node.js
B站计算机毕业设计超人5 小时前
计算机毕业设计Django+Vue.js音乐推荐系统 音乐可视化 大数据毕业设计 (源码+文档+PPT+讲解)
大数据·vue.js·hadoop·python·spark·django·课程设计
B站_计算机毕业设计之家5 小时前
电影知识图谱推荐问答系统 | Python Django系统 Neo4j MySQL Echarts 协同过滤 大数据 人工智能 毕业设计源码(建议收藏)✅
人工智能·python·机器学习·django·毕业设计·echarts·知识图谱
计算机专业码农一枚5 小时前
Python-flask框架基于推荐算法的在线课程推荐系统设计与实现-Pycharm django
python·flask·推荐算法
ATCB5 小时前
零门槛!PythonAnywhere 免费部署全指南:不止 Django,这些项目都能搭(附主流平台对比)
后端·python·django