框架:
- PyTorch
许可证: llama3
任务:
- 文本生成
#模型类型:
##如 gpt、phi、llama、chatglm、baichuan 等
#- gpt
#领域:
##如 自然语言处理、计算机视觉、音频、多模态
#- 自然语言处理
#语言:
##语言代码列表 https://help.aliyun.com/document_detail/215387.html?spm=a2c4g.11186623.0.0.9f8d7467kni6Aa
#- 中文
#评估指标:
##如 CIDEr、Blue、ROUGE 等
#- CIDEr
#标签:
##各种自定义,包括预训练、微调、指令调优、强化学习调优等训练方法和其他
#- 预训练
#工具:
##如 vllm、fastchat、llamacpp、AdaSeq 等
#- vllm
魔搭Llama3 8B中文智能体模型
本模型基于Llama3-8b-instruct基础模型训练,适配中文通用场景,并支持ReACT格式的智能体调用。
模型使用指南
推理部署
# 安装依赖
pip install ms-swift -U
swift infer --model_type llama3-8b-instruct --model_id_or_path swift/Llama3-Chinese-8B-Instruct-Agent-v1
# 服务部署
swift deploy --model_type llama3-8b-instruct --model_id_or_path swift/Llama3-Chinese-8B-Instruct-Agent-v1
本模型可与ModelScopeAgent框架协同使用,具体参考:
https://github.com/modelscope/swift/blob/main/docs/source/LLM/Agent微调最佳实践.md#搭配modelscope-agent使用
训练数据配置
为优化中文及智能体场景适配,我们采用以下混合语料进行训练:
- COIG-CQIA:https://modelscope.cn/datasets/AI-ModelScope/COIG-CQIA/summary 包含中国传统知识、豆瓣、弱智吧、知乎等中文互联网内容
- 魔搭智能体训练集:https://modelscope.cn/datasets/AI-ModelScope/ms-agent-for-agentfabric/summary
- alpaca英文数据集:https://modelscope.cn/datasets/AI-ModelScope/alpaca-gpt4-data-en/summary
- ms-bench中文问答集:https://modelscope.cn/datasets/iic/ms_bench/summary
超参配置 |
数值 |
学习率 |
5e-5 |
训练轮次 |
2 |
LoRA秩数 |
8 |
LoRA缩放系数 |
32 |
LoRA目标模块 |
全连接 |
批处理量 |
2 |
梯度累积步数 |
16 |
训练执行命令
NPROC_PER_NODE=8 \
swift sft \
--model_type llama3-8b-instruct \
--dataset ms-agent-for-agentfabric-default alpaca-en ms-bench ms-agent-for-agentfabric-addition coig-cqia-ruozhiba coig-cqia-zhihu coig-cqia-exam coig-cqia-chinese-traditional coig-cqia-logi-qa coig-cqia-segmentfault coig-cqia-wiki \
--batch_size 2 \
--max_length 2048 \
--use_loss_scale true \
--gradient_accumulation_steps 16 \
--learning_rate 5e-5 \
--use_flash_attn true \
--eval_steps 500 \
--save_steps 500 \
--train_dataset_sample -1 \
--dataset_test_ratio 0.1 \
--val_dataset_sample 10000 \
--num_train_epochs 2 \
--check_dataset_strategy none \
--gradient_checkpointing true \
--weight_decay 0.01 \
--warmup_ratio 0.03 \
--save_total_limit 2 \
--logging_steps 10 \
--sft_type lora \
--lora_target_modules ALL \
--lora_rank 8 \
--lora_alpha 32
基准测试结果
评估模型 |
ARC |
CEVAL |
GSM8K |
Llama3-8b-instruct原版 |
0.7645 |
0.5089 |
0.7475 |
中文智能体优化版 |
0.7577 |
0.4903 |
0.652 |
注:GSM8K英文数学能力下降约8个百分点,消融实验表明移除alpaca-en语料会导致该指标下降超10个百分点。