大模型第三节跟连及操作视频 #88

Closed
opened 2024-09-14 14:33:07 +08:00 by 21547230244cs · 0 comments

准备API Key

首先,根据自己的需求申请API key

创建开发环境

由于待会需要运用2机8卡训练,所以先在平台上创建2个notebook。

打开notebook进入VS Code

打开文件夹,输入/code/进入code栏目

在右上角打开终端

设置环境变量

网络连接配置

在两台服务器上都配置HuggingFace镜像和网络代理:

export HF_HOME=/code/huggingface-cache/

export HF_ENDPOINT=https://hf-mirror.com

export http_proxy=http://10.10.9.50:3000

export https_proxy=http://10.10.9.50:3000

export no_proxy=localhost,127.0.0.1

设置对应的API-Key

export ZHIPUAI_API_KEY=*****

配置IB网卡

在两台服务器上分别输入:

export NCCL_DEBUG=INFO

export NCCL_IB_DISABLE=0

export NCCL_IB_HCA=mlx5

export NCCL_SOCKET_IFNAME=eth0

export GLOO_SOCKET_IFNAME=eth0

开始训练

获取 master IP 地址

任意选择一台服务做(notebook)作为主服务器(master),并用ifconfig获取该服务器的IP地址

启动训练

使用刚刚查询的主服务器IP地址,启动训练的命令如下:

在第一台服务器输入:

NPROC_PER_NODE=4NNODES=2PORT=12345ADDR=10.244.132.114 NODE_RANK=0 xtuner train llama2_7b_chat_qlora_sql_e3_copy.py --work-dir /code/xtuner-workdir --deepspeed deepspeed_zero3_offload

在第二台服务器输入:

NPROC_PER_NODE=4NNODES=2PORT=12345ADDR=10.244.132.114 NODE_RANK=1 xtuner train llama2_7b_chat_qlora_sql_e3_copy.py --work-dir /code/xtuner-workdir --deepspeed deepspeed_zero3_offload

训练结束后

模型转换

将lora模型训练的checkpoint转成hf格式的模型:

xtuner convert pth_to_hf /code/llama2_7b_chat_qlora_sql_e3_copy.py /code/xtuner-workdir/iter_500.pth/ /code/iter_500_hf/

执行测试

用如下命令测试微调后的结果:

python final_test.py

微调后结果如下:

## 准备API Key 首先,根据自己的需求申请API key ![](https://cdn.nlark.com/yuque/0/2024/png/48118617/1726218502472-45c2ad8a-e56f-482a-8ae7-7b12dd80d9c8.png) ## 创建开发环境 由于待会需要运用2机8卡训练,所以先在平台上创建2个notebook。 ![](https://cdn.nlark.com/yuque/0/2024/png/48118617/1726217797723-9a7a6999-83bc-4c6f-a43e-f00b24c33bd4.png) 打开notebook进入VS Code ![](https://cdn.nlark.com/yuque/0/2024/png/48118617/1726218698632-3f65645a-288d-479c-9028-185fa0b77ace.png) 打开文件夹,输入/code/进入code栏目 ![](https://cdn.nlark.com/yuque/0/2024/png/48118617/1726285814509-1b8f6599-9fa2-49f8-b3a3-fdef23195b45.png) 在右上角打开终端 ![](https://cdn.nlark.com/yuque/0/2024/png/48118617/1726285890423-f1cd03b3-85fd-4370-b537-c61490ed9827.png) ## 设置环境变量 #### 网络连接配置 在两台服务器上都配置HuggingFace镜像和网络代理: <font style="color:#000000;">export</font><font style="color:#000000;"> HF_HOME=/code/huggingface-cache/</font> <font style="color:#000000;">export HF_ENDPOINT=https://hf-mirror.com</font> <font style="color:#000000;">export http_proxy=http://10.10.9.50:3000</font> <font style="color:#000000;">export https_proxy=http://10.10.9.50:3000</font> <font style="color:#000000;">export no_proxy=localhost,127.0.0.1</font> ![](https://cdn.nlark.com/yuque/0/2024/png/48118617/1726285655646-2f5bb9c4-5f4b-4c6b-acba-ab3afb1da8a4.png) #### 设置对应的API-Key <font style="color:#000000;">export ZHIPUAI_API_KEY</font><font style="color:#9a6e3a;">=*****</font> #### 配置IB网卡 在两台服务器上分别输入: <font style="color:#000000;">export NCCL_DEBUG=INFO</font> <font style="color:#000000;">export NCCL_IB_DISABLE=0</font> <font style="color:#000000;">export NCCL_IB_HCA=mlx5</font> <font style="color:#000000;">export NCCL_SOCKET_IFNAME=eth0</font> <font style="color:#000000;">export GLOO_SOCKET_IFNAME=eth0</font> ![](https://cdn.nlark.com/yuque/0/2024/png/48118617/1726286244869-36cc72dc-865b-4a01-9b13-c99ff8dfab55.png) ## 开始训练 #### 获取 master IP 地址 任意选择一台服务做(notebook)作为主服务器(master),并用ifconfig获取该服务器的IP地址 ![](https://cdn.nlark.com/yuque/0/2024/png/48118617/1726286513422-a629bb97-4393-4424-a9a0-2abed1c5e5cf.png) #### 启动训练 使用刚刚查询的主服务器IP地址,启动训练的命令如下: 在第一台服务器输入: <font style="color:#000000;">NPROC_PER_NODE</font><font style="color:#9a6e3a;">=</font><font style="color:#990055;">4</font><font style="color:#000000;">NNODES</font><font style="color:#9a6e3a;">=</font><font style="color:#990055;">2</font><font style="color:#000000;">PORT</font><font style="color:#9a6e3a;">=</font><font style="color:#990055;">12345</font><font style="color:#000000;">ADDR</font><font style="color:#9a6e3a;">=</font><font style="color:#990055;">10.244</font><font style="color:#000000;">.132.114 NODE_RANK</font><font style="color:#9a6e3a;">=</font><font style="color:#990055;">0</font><font style="color:#000000;"> xtuner train llama2_7b_chat_qlora_sql_e3_copy.py --work-dir /code/xtuner-workdir --deepspeed deepspeed_zero3_offload</font> <font style="color:#000000;">在第二台服务器输入:</font> <font style="color:#000000;">NPROC_PER_NODE</font><font style="color:#9a6e3a;">=</font><font style="color:#990055;">4</font><font style="color:#000000;">NNODES</font><font style="color:#9a6e3a;">=</font><font style="color:#990055;">2</font><font style="color:#000000;">PORT</font><font style="color:#9a6e3a;">=</font><font style="color:#990055;">12345</font><font style="color:#000000;">ADDR</font><font style="color:#9a6e3a;">=</font><font style="color:#990055;">10.244</font><font style="color:#000000;">.132.114 NODE_RANK</font><font style="color:#9a6e3a;">=</font><font style="color:#990055;">1</font><font style="color:#000000;"> xtuner train llama2_7b_chat_qlora_sql_e3_copy.py --work-dir /code/xtuner-workdir --deepspeed deepspeed_zero3_offload</font> ## <font style="color:#000000;">训练结束后</font> #### 模型转换 将lora模型训练的checkpoint转成hf格式的模型: <font style="color:#000000;">xtuner convert pth_to_hf /code/llama2_7b_chat_qlora_sql_e3_copy.py /code/xtuner-workdir/iter_500.pth/ /code/iter_500_hf/</font> #### <font style="color:#000000;">执行测试</font> 用如下命令测试微调后的结果: <font style="color:#000000;">python final_test.py</font> <font style="color:#000000;"></font> <font style="color:#000000;">微调后结果如下:</font> ![](https://cdn.nlark.com/yuque/0/2024/png/48118617/1726294999306-0834f645-d4b6-41b1-82ae-660bc6c9f7b4.png) <font style="color:#000000;"></font>
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: HswOAuth/llm_course#88
No description provided.