# 内容 - [内容](#内容) - [环境配置](#环境配置) - [下载词汇文件](#下载词汇文件) - [下载训练数据](#下载训练数据) - [训练](#训练) - [数据预处理](#数据预处理) - [GPT预训练](#gpt预训练) - [单卡训练](#单卡训练) - [分布式多卡训练](#分布式多卡训练) - [GPT文本生成](#gpt文本生成) - [参考](#参考) # 环境配置 1. 安装基础依赖包
pip install -r requirements.txt2. 安装DCU相关whl包 DCU相关包下载目录:[https://cancon.hpccube.com:65024/4/main](https://cancon.hpccube.com:65024/4/main) pytorch whl包:pytorch ---> dtk-24.04 根据python版本,下载对应pytorch的whl包
pip install torch* (下载的torch的whl包)torchvision whl包:vision ---> dtk-24.04 根据python版本,下载对应torchvision的whl包
pip install torchvision* (下载的torchvision的whl包)apex whl包:apex ---> dtk-24.04 根据python版本,下载对应apex的whl包
pip install apex* (下载的apex的whl包)若使用 pip install 下载安装过慢,可添加源:-i https://pypi.tuna.tsinghua.edu.cn/simple/ # 下载词汇文件
wget https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-vocab.json wget https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-merges.txt# 下载训练数据 使用1GB 79K jsonl数据集
wget https://huggingface.co/bigscience/misc-test-data/resolve/main/stas/oscar-1GB.jsonl.xz xz -d oscar-1GB.jsonl.xz# 训练 ## 数据预处理
python tools/preprocess_data.py \
--input oscar-1GB.jsonl \
--output-prefix ./dataset/my-gpt2 \
--vocab gpt2-vocab.json \
--dataset-impl mmap \
--tokenizer-type GPT2BPETokenizer \
--merge-file gpt2-merges.txt \
--append-eod \
--workers 8
参数说明
--input 输入数据集路径,即oscar-1GB.jsonl.xz解压后的文件路径
--output-prefix 输出数据路径,处理后会自动加上_text_document后缀
--vocab 下载的gpt2-vocab.json词表文件路径
--dataset-impl dataset类型
--tokenizer-type tokenizer类型
--merge-file 下载的gpt2-merges.txt文件路径
--append-eod 添加结束标志符
--workers 进程数
## GPT预训练
### 分布式训练
- 修改DATA_PATH路径(示例脚本中使用的是mixtral数据集,实际运行时请自行修改)
```bash
VOCAB_FILE=gpt2-vocab.json
MERGE_FILE=gpt2-merges.txt
DATA_PATH=./dataset/my-gpt2_text_document
```
- 执行多卡训练
```
#np为起的进程数,np\hostfile均需按实际填写
mpirun -np 4 --hostfile hostfile train_mixtral_8x7B_1nodes.sh(基于单节点四卡)
```
# 参考
- [README_ORIGIN](README_ORIGIN.md)