Tencent / TencentPretrain

Tencent Pre-training framework in PyTorch & Pre-trained Model Zoo
https://github.com/Tencent/TencentPretrain/wiki
Other
1.03k stars 142 forks source link

add mt classifier by using deepspeed #117

Closed yuzhangogogo closed 10 months ago

yuzhangogogo commented 10 months ago

TencentPretrain支持基于deepspeed的多任务微调,通过配置文件的方式选择ZeRO1/ZeRO2/ZeRO3,包括训练和推理代码,且训练和推理代码均支持数据的并行处理,另外,模型加载支持切片的模型,通过参数pretrained_model_path指定模型加载是切片的还是非切片的,如果是文件夹格式,代表为切片的模型,如果是文件格式,代表为非切片的模型

训练脚本示例: deepspeed finetune/run_classifier_mt_deepspeed.py --spm_model_path models/spm.model --config_path models/llama2/7b_config.json --deepspeed_config models/deepspeed_zero3_config.json --dataset_path_list ./train.tsv --epochs_num 3 --batch_size 48 --world_size 8 --scheduler cosine --warmup 0.03 --seq_length 300 --pooling last --deepspeed_checkpoint_activations --report_steps 2 --learning_rate 1e-5 --pretrained_model_path models_init.bin --output_model_path models/output

模型转化脚本: 模型训练完后,通过以下脚本将模型转换为torch格式 python3 zero_to_fp32.py ./model.bin

推理脚本示例: deepspeed inference/run_classifier_mt_deepspeed_infer.py --spm_model_path models/spm.model --config_path models/llama2/7b_config.json --deepspeed_config models/deepspeed_zero3_config.json --load_model_path models/output/model.bin --test_path dev.tsv --labels_num_list 2 2 2 2 2 2 2 2 2 2 2 --prediction_path result.tsv --output_logits --output_prob --pooling last --world_size 8

此外,基于deepspeed的单任务微调也支持了数据并行处理,包括训练和推理代码

训练脚本示例: deepspeed finetune/run_classifier_deepspeed.py --spm_model_path models/spm.model --config_path models/llama2/7b_config.json --deepspeed_config models/deepspeed_zero3_config.json --train_path datasets/book_review/train.tsv --dev_path datasets/book_review/dev.tsv --test_path datasets/book_review/test.tsv --epochs_num 3 --batch_size 48 --world_size 8 --scheduler cosine --warmup 0.03 --seq_length 300 --pooling last --deepspeed_checkpoint_activations --report_steps 100 --learning_rate 1e-5 --pretrained_model_path models_init.bin --output_model_path models/output

模型转化脚本: 模型训练完后,通过以下脚本将模型转换为torch格式 python3 zero_to_fp32.py ./model.bin

推理脚本示例 deepspeed inference/run_classifier_deepspeed_infer.py --spm_model_path models/spm.model --config_path models/llama2/7b_config.json --deepspeed_config models/deepspeed_zero3_config.json --test_path datasets/book_review/test.tsv --world_size 8 --seq_length 300 --pooling last --labels_num 2 --load_model_path models/output/model.bin --prediction_path result.tsv --output_logits --output_prob