Zeyu Chen 918b77fb39 | 9 months ago | |
---|---|---|
.. | ||
ernie-tokenizer | 9 months ago | |
README.md | 9 months ago | |
configuration.py | 9 months ago | |
data.py | 9 months ago | |
ernie_dataset.py | 9 months ago | |
finetune_generation.py | 9 months ago | |
modeling.py | 9 months ago | |
predict_generation.py | 9 months ago | |
run_finetune.sh | 9 months ago | |
run_predict.sh | 9 months ago | |
run_pretrain.py | 9 months ago | |
run_trainer_stage2.sh | 9 months ago | |
tokenizer.py | 9 months ago | |
utils.py | 9 months ago |
目录
ERNIE-3.5-SE 的代码开源主要包括模型组网、分布式预训练代码、微调以及预测服务。
Parallel Transformer | “掐头去尾”策略 |
预训练数据制作参考此处
为了方便用户运行测试本模型,本项目提供了处理好的100k条doc的训练样本:
wget https://bj.bcebos.com/paddlenlp/models/transformers/ernie/data/ernie_openwebtext_100k_ids.npy
wget https://bj.bcebos.com/paddlenlp/models/transformers/ernie/data/ernie_openwebtext_100k_idx.npz
将所有预处理得到的文件统一放入一个文件夹中,以备训练使用:
mkdir data
mv ernie_openwebtext_100k_ids.npy ./data
mv ernie_openwebtext_100k_idx.npz ./data
使用下面脚本,即可启动 ernie-3.5-se-3b 的预训练,也可直接参考 run_trainer_stage2.sh。
task_name="ernie35_hybid"
python -u -m paddle.distributed.launch \
--gpus "0,1,2,3,4,5,6,7" \
--log_dir "output/$task_name""_log" \
run_pretrain.py \
--model_type "ernie" \
--model_name_or_path "baidu/ernie-3.5-se-3b" \
--tokenizer_name_or_path "ernie-tokenizer" \
--input_dir "./data" \
--output_dir "output/$task_name" \
--split 949,50,1 \
--max_seq_length 4096 \
--per_device_train_batch_size 1 \
--per_device_eval_batch_size 1 \
--use_flash_attention 1 \
--use_fused_ln 1 \
--bf16 \
--fp16_opt_level "O2" \
--scale_loss 512 \
--learning_rate 0.0003 \
--min_learning_rate 0.00003 \
--lr_scheduler_type "cosine" \
--max_steps 300000 \
--save_steps 200 \
--adam_beta2 0.95 \
--weight_decay 0.1 \
--warmup_steps 2000 \
--max_grad_norm 1.0 \
--logging_steps 2 \
--dataloader_num_workers 0 \
--sharding "stage2" \
--sharding_parallel_degree 8 \
--eval_steps 200 \
--report_to "visualdl" \
--disable_tqdm true \
--continue_training 0\
--recompute 1 \
--do_train \
--do_eval \
--save_total_limit 10 \
--device "gpu"
注意:
pip install tool_helpers visualdl==2.5.3
等相关缺失whl包use_flash_attention
需要在A100机器开启,否则loss可能不正常(很快变成0.00x,非常小不正常)。建议使用cuda11.8环境。continue_training
表示从现有的预训练模型加载训练,如果需要从头开始预训练模型,则设置为0。use_fused_ln
需要安装此目录下的自定义OP, python setup.py install
。如果安装后仍然找不到算子,需要额外设置PYTHONPATH微调脚本具体可见 run_finetune.sh。
python -m paddle.distributed.launch \
--gpus "0,1,2,3,4,5,6,7" \
finetune_generation.py \
--output_dir "output_sft/$task_name" \
--per_device_train_batch_size 4 \
--gradient_accumulation_steps 2 \
--per_device_eval_batch_size 8 \
--model_name_or_path <PATH_TO_CKPT> \
--task_name squad \
--num_train_epochs 2 \
--learning_rate 3e-5 \
--warmup_steps 30 \
--logging_steps 1 \
--evaluation_strategy epoch \
--save_strategy epoch \
--src_length 1024 \
--tgt_length 1024 \
--bf16 \
--fp16_opt_level O2 \
--do_train \
--do_eval \
--disable_tqdm True \
--load_best_model_at_end True \
--metric_for_best_model accuracy \
--eval_with_do_generation False \
--recompute \
--save_total_limit 1 \
--overwrite_output_dir \
--sharding "stage2" \
--sharding_parallel_degree 8
python -m paddle.distributed.launch \
--gpus "0" \
--log_dir "output_sft/$task_name""_log" \
finetune_generation.py \
--output_dir ./checkpoints/ \
--per_device_train_batch_size 4 \
--gradient_accumulation_steps 2 \
--per_device_eval_batch_size 8 \
--model_name_or_path <PATH_TO_CKPT> \
--task_name squad \
--num_train_epochs 2 \
--learning_rate 3e-4 \
--warmup_steps 30 \
--logging_steps 1 \
--evaluation_strategy epoch \
--save_strategy epoch \
--src_length 1024 \
--tgt_length 1024 \
--bf16 \
--fp16_opt_level O2 \
--do_train \
--do_eval \
--disable_tqdm True \
--load_best_model_at_end True \
--metric_for_best_model accuracy \
--eval_with_do_generation False \
--recompute \
--save_total_limit 1 \
--overwrite_output_dir \
--lora True \
--lora_rank 8
其中参数释义如下:
model_name_or_path
: 预训练模型内置名称或者模型所在目录.num_train_epochs
: 要执行的训练 epoch 总数(如果不是整数,将在停止训练之前执行最后一个 epochmax_steps
: 模型训练步数。learning_rate
: 参数更新的学习率。warmup_steps
: 学习率热启的步数。eval_steps
: 模型评估的间隔步数。logging_steps
: 训练日志打印的间隔步数。save_steps
: 模型参数保存的间隔步数。save_total_limit
: 模型 checkpoint 保存的份数。output_dir
: 模型参数保存目录。src_length
: 上下文的最大输入长度,默认为128.tgt_length
: 生成文本的最大长度,默认为160.gradient_accumulation_steps
: 模型参数梯度累积的步数,可用于扩大 batch size。实际的 batch_size = per_device_train_batch_size * gradient_accumulation_steps。bf16
: 使用 bfloat16 精度进行模型训练和推理。fp16_opt_level
: bfloat16 精度训练模式,O2
表示纯 bfloat16 训练。recompute
: 使用重计算策略,开启后可节省训练显存。do_train
: 是否训练模型。do_eval
: 是否评估模型。tensor_parallel_degree
: 模型并行数量。eval_with_do_generation
: 在评估的时候是否调用model.generate,默认为False。lora
: 是否使用 LoRA 技术。merge_weights
: 是否合并原始模型和 LoRA 模型的权重。lora_rank
: LoRA 算法中rank(秩)的值,默认为8。lora_path
: LoRA 参数和配置路径,对 LoRA 参数进行初始化。task_name
: 内置数据集任务名data_name
: 内置数据集名,定义数据集名必须同时定义数据集任务名dataset_path
: 自定义数据集路径。预测脚本具体可见 run_predict.sh。
python -m paddle.distributed.launch --gpus "0" predict_generation.py \
--model_name_or_path <PATH_TO_CKPT> \
--tokenizer_name_or_path ernie-tokenizer
👑 Easy-to-use and powerful NLP library with 🤗 Awesome model zoo, supporting wide-range of NLP tasks from research to industrial applications, including 🗂Text Classification, 🔍 Neural Search, ❓ Question Answering, ℹ️ Information Extraction, 📄 Documen
Python C++ Cuda Shell Markdown other
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》