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)

相关推荐
数据智能老司机6 小时前
精通 Python 设计模式——分布式系统模式
python·设计模式·架构
数据智能老司机7 小时前
精通 Python 设计模式——并发与异步模式
python·设计模式·编程语言
数据智能老司机7 小时前
精通 Python 设计模式——测试模式
python·设计模式·架构
数据智能老司机7 小时前
精通 Python 设计模式——性能模式
python·设计模式·架构
c8i7 小时前
drf初步梳理
python·django
每日AI新事件7 小时前
python的异步函数
python
这里有鱼汤8 小时前
miniQMT下载历史行情数据太慢怎么办?一招提速10倍!
前端·python
databook17 小时前
Manim实现脉冲闪烁特效
后端·python·动效
程序设计实验室17 小时前
2025年了,在 Django 之外,Python Web 框架还能怎么选?
python
倔强青铜三19 小时前
苦练Python第46天:文件写入与上下文管理器
人工智能·python·面试