AutoDL平台transformers环境搭建

AutoDL平台transformers环境搭建

租借GPU可以参考

AutoDL平台租借GPU详解

一、激活base环境

1.进入终端

shell 复制代码
vim  ~/.bashrc

2、然后按英文模式的 i 进入编辑,按键盘下键到最后输入

shell 复制代码
source root/miniconda3/etc/profile.d/conda.sh

3、然后先按键盘Esc键,使用命令 :wq 保存退出

4、输入以下命令刷新

shell 复制代码
bash

5、进入conda环境

shell 复制代码
conda activate base
# 可能会报错'...conda init'
#1、执行:
conda init
#2、执行:
bash
#3、重新激活:
conda activate base

二、创建自己的环境

shell 复制代码
# 1、创建transformers环境
(base) root@autodl-container-adbc11ae52-f2ebff02:~# conda create -n transformers python=3.9 -y



# 2、此时,会有两个环境
(base) root@autodl-container-adbc11ae52-f2ebff02:~# conda info --envs
# conda environments:
#
base                  *  /root/miniconda3
transformers             /root/miniconda3/envs/transformers

# 3、激活创建的环境
(base) root@autodl-container-adbc11ae52-f2ebff02:~# conda activate transformers
(transformers) root@autodl-container-adbc11ae52-f2ebff02:~# 


# 4、安装pytorch

# 4.1 查看机器支持的cuda版本,可以看到最高支持到CUDA Version: 12.0
(transformers) root@autodl-container-adbc11ae52-f2ebff02:~# nvidia-smi 
Sat Oct 14 11:40:39 2023       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.89.02    Driver Version: 525.89.02    CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  On   | 00000000:3D:00.0 Off |                  N/A |
| 30%   32C    P8    19W / 250W |     14MiB / 11264MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

# 4.2 设置下载源为清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple


# 4.3 进入pytorch官网下载最新版pytorch
# https://pytorch.org/
# 推荐使用pip安装

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
shell 复制代码
# 4.4 测试是否安装成功
(transformers) root@autodl-container-adbc11ae52-f2ebff02:~# python
Python 3.9.18 (main, Sep 11 2023, 13:41:44) 
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> 
>>> print(torch.__version__)
2.1.0+cu118
>>> print(torch.cuda.is_available())
True
>>> 


# 5、安装transformers相关库
pip install transformers datasets evaluate peft accelerate gradio optimum sentencepiece
pip install scikit-learn pandas matplotlib tensorboard nltk rouge

# 6、验证安装是否成功
>>> from transformers import *
>>> 



# 7、虚拟环境添加到可选的kernel
conda install ipykernel
ipython kernel install --user --name=transformers

此时我们在jupyter上刷新页面,就能看到自己刚装的环境

以后使用的时候,可以选择此环境

相关推荐
用户83562907805114 小时前
无需 Office:Python 批量转换 PPT 为图片
后端·python
用户14748530797414 小时前
AI-动手深度学习环境搭建-d2l
深度学习
markfeng816 小时前
Python+Django+H5+MySQL项目搭建
python·django
GinoWi16 小时前
Chapter 2 - Python中的变量和简单的数据类型
python
JordanHaidee17 小时前
Python 中 `if x:` 到底在判断什么?
后端·python
OpenBayes贝式计算17 小时前
解决视频模型痛点,TurboDiffusion 高效视频扩散生成系统;Google Streetview 涵盖多个国家的街景图像数据集
人工智能·深度学习·机器学习
ServBay17 小时前
10分钟彻底终结冗长代码,Python f-string 让你重获编程自由
后端·python
OpenBayes贝式计算17 小时前
OCR教程汇总丨DeepSeek/百度飞桨/华中科大等开源创新技术,实现OCR高精度、本地化部署
人工智能·深度学习·机器学习
闲云一鹤17 小时前
Python 入门(二)- 使用 FastAPI 快速生成后端 API 接口
python·fastapi
Rockbean18 小时前
用40行代码搭建自己的无服务器OCR
服务器·python·deepseek