当前位置:网站首页>conda 配置深度学习环境 pytorch transformers
conda 配置深度学习环境 pytorch transformers
2022-07-25 09:27:00 【Haulyn5】
前言
最近想学习一下 Huggingface 的 Transformers 库的使用,需要重新搭建一个虚拟环境,做简单记录方便之后工作。
正文
这次搭建主要是平时测试和玩的环境,不考虑为某某应用兼容用低版本,看一眼 python 的版本。

差不多是一年一个小版本号呀,3.7 再有一年停止维护了,打算用 3.8 了。
conda create -n dev38 python=3.8create 命令创建环境。这里 miniconda 的安装,还有 channel 的设置就不赘述了。
提示 conda 需要更新,顺手更新一下 conda。
conda update -n base -c defaults conda* python --version
Python 3.8.13
看了一下,安装了 3.8.13 版本的 python。
然后先安装 pytorch 再说 Transformers。PyTorch 的安装需要 cudatoolkit 来利用显卡。
本机因为之前安装过 cudatoolkit,先检查一下。
nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Oct_12_20:09:46_PDT_2020
Cuda compilation tools, release 11.1, V11.1.105
Build cuda_11.1.TC455_06.29190527_0
可以看到本机安装的是 cuda 11.1 。
但是 pytorch 官网似乎没有给这个选择。

不过看了一下,应该改一下 cudatoolkit 那一部分就好。 先试试安装 CUDA 11.1 。
conda install pytorch torchvision torchaudio cudatoolkit=11.1这里把 -c 的部分去掉了,这部分大概是选择下载源,我印象里用 pytorch 官方源特别慢,这里关了试试。
* conda install pytorch torchvision torchaudio cudatoolkit=11.1
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- cudatoolkit=11.1
Current channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/linux-64
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/noarch
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/linux-64
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/noarch
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2/linux-64
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2/noarch
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/noarch
- https://mirrors.ustc.edu.cn/anaconda/pkgs/free/linux-64
- https://mirrors.ustc.edu.cn/anaconda/pkgs/free/noarch
- https://mirrors.ustc.edu.cn/anaconda/pkgs/main/linux-64
- https://mirrors.ustc.edu.cn/anaconda/pkgs/main/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
然后光荣报错了。然后试试把 11.1 改成 11.3 。

就可以安装了……就是要下载不少东西。

好,无法使用 cuda,大概率是因为 docker 外宿主机的 driver 版本也有限制。那就只能调整 cuda 到 11.1 了。
我又将版本回退(这里不加 -c 会报错。
conda install cudatoolkit=11.1 -c nvidia可是还是检查不到 gpu。看了一下,现在的 torch 版本是1.10.2,而之前安装的能用的环境中 torch 版本是 1.8.2,莫非是 torch 版本问题?
conda install pytorch=1.8.2 -c pytorch-lts再次回退 pytorch 的版本,注意这里 -c 如果 pytorch 会出错,需要加上 lts (长期维护)。

然后就可以使用 cuda 了…… 大概是新版本一点的 torch 和我使用的 GPU 服务器的 GPU 驱动五行不合吧…… 但是由于 GPU 服务器不能随意更新驱动版本,可能会导致所有用户的 docker 崩掉,所以也只能就这样用 LTS 了。
接下来安装 Transformers 库。
conda install -c huggingface transformers这里安装也很顺利。
总结
安装深度学习的环境很容易出各种各样的问题,如果有权限更新服务器的显卡驱动则应该能安装较新版本的库,但是像我一样在 docker 里,与很多用户共用一台服务器的场景,可能就只能用 pytorch 1.8.2 的 LTS 版本了,用靠前一点的版本就会水土不服。
边栏推荐
猜你喜欢

See how a junior student of double non-2 (0 Internship) can get an offer from Alibaba and Tencent

Debug篇快捷键入门

TensorFlow raw_ RNN - implement the seq2seq mode to take the output of the previous time as the input of the next time

Detailed explanation of MySQL database

nodejs链接mysql报错:ER_NOT_SUPPORTED_AUTH_MODEError: ER_NOT_SUPPORTED_AUTH_MODE

文件的上传功能
![[machine translation] scones -- machine translation with multi tag tasks](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[machine translation] scones -- machine translation with multi tag tasks

Use and principle of rest
![[deployment of deep learning model] deploy the deep learning model using tensorflow serving + tornado](/img/62/78abf16bb6c66726c6e394c9fb4f81.png)
[deployment of deep learning model] deploy the deep learning model using tensorflow serving + tornado

IDEA整体字体大小修改
随机推荐
小程序企业发放红包功能
NPM details
Detailed explanation of JDBC operation database
Ubuntu20.04系统下安装MySQL数据库5.7.29版本
Excel导入导出源码分析
UE4 LoadingScreen动态加载启动动画
一.初始MySQL,MySQL安装、配置环境、初始化
shortest-unsorted-continuous-subarray
多线程——Callable接口,lambda
字符串最长公共前缀
VLAN的配置及其应用(以华为eNSP为例)
Filter过滤器详解(监听器以及它们的应用)
CCF 201509-3 template generation system
四舍五入取近似值
21. Merge Two Sorted Lists
Summary of most consistency problems
文件的上传功能
Pytorch 张量列表转换为张量 List of Tensor to Tensor 使用 torch.stack()
拷贝过来老的项目变成web项目
基础背包问题