拉取代码
你可以通过克隆此仓库到 GPU 服务器来开始学习:
git clone https://github.com/DjangoPeng/LLM-quickstart.git
搭建开发环境
本项目对于硬件有一定要求:GPU 显存不小于16GB,支持最低配置显卡型号为 NVIDIA Tesla T4。
建议使用 GPU 云服务器来进行模型训练和微调。
项目使用 Python 版本为 3.10,环境关键依赖的官方文档如下:
- Python 环境管理 Miniconda
- Python 交互式开发环境 Jupyter Lab
安装 CUDA Toolkit 和 GPU 驱动
根据你的实际情况,找到对应的 CUDA 12.04:
下载并安装 CUDA 12.04 Toolkit(包含GPU驱动):
wget https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_550.54.14_linux.run
sudo sh cuda_12.4.0_550.54.14_linux.run
安装完成后,使用 nvidia-smi
指令查看版本
nvidia-smi
Mon Dec 18 12:10:47 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.129.03 Driver Version: 535.129.03 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| 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 Tesla T4 Off | 00000000:00:0D.0 Off | 0 |
| N/A 44C P0 26W / 70W | 2MiB / 15360MiB | 6% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| No running processes found |
+---------------------------------------------------------------------------------------+
安装操作系统级软件依赖
sudo apt update && sudo apt upgrade
sudo apt install ffmpeg
## 检查是否安装成功
ffmpeg -version
安装 Python 环境管理工具 Miniconda
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh
安装完成后,建议新建一个 Python 虚拟环境,命名为 peft
。
conda create -n peft python=3.10
# 激活环境
conda activate peft
之后每次使用需要激活此环境!!
安装 Python 依赖软件包
完整 Python 依赖软件包见requirements.txt
安装和配置 Jupyter Lab
上述开发环境安装完成后,使用 Miniconda 安装 Jupyter Lab:
conda install -c conda-forge jupyterlab
使用 Jupyter Lab 开发的最佳实践是后台常驻,下面是相关配置(以 root 用户为例):
# 生成 Jupyter Lab 配置文件,
jupyter lab --generate-config
打开上面执行输出的jupyter_lab_config.py
配置文件后,修改以下配置项:
c.ServerApp.allow_root = True # 非 root 用户启动,无需修改
c.ServerApp.ip = '*'
使用 nohup 后台启动 Jupyter Lab
$ nohup jupyter lab --port=8000 --NotebookApp.token='替换为你的密码' --notebook-dir=./ &
Jupyter Lab 输出的日志将会保存在 nohup.out
文件(已在 .gitignore中过滤)。
自此,已经结束!