File size: 3,657 Bytes
9a86263 15342ad 1b462a1 15342ad 9a86263 15342ad 1b462a1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
---
frameworks:
- Pytorch
license: llama3
tasks:
- text-generation
#model-type:
##如 gpt、phi、llama、chatglm、baichuan 等
#- gpt
#domain:
##如 nlp、cv、audio、multi-modal
#- nlp
#language:
##语言代码列表 https://help.aliyun.com/document_detail/215387.html?spm=a2c4g.11186623.0.0.9f8d7467kni6Aa
#- cn
#metrics:
##如 CIDEr、Blue、ROUGE 等
#- CIDEr
#tags:
##各种自定义,包括 pretrained、fine-tuned、instruction-tuned、RL-tuned 等训练方法和其他
#- pretrained
#tools:
##如 vllm、fastchat、llamacpp、AdaSeq 等
#- vllm
---
# 魔搭Llama3 8b中文Agent智能体模型
本模型使用Llama3-8b-instruct基模型进行训练,适配中文通用场景,且支持ReACT格式的Agent调用。
## 模型使用
### 推理
```shell
# 安装依赖
pip install ms-swift -U
```
```python
# 推理
swift infer --model_type llama3-8b-instruct --model_id_or_path swift/Llama3-Chinese-8B-Instruct-Agent-v1
```
```shell
# 部署
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%E5%BE%AE%E8%B0%83%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5.md#%E6%90%AD%E9%85%8Dmodelscope-agent%E4%BD%BF%E7%94%A8
### 模型训练信息
为了适配中文及Agent场景,我们针对语料进行了一定混合配比,训练Llama3使用的语料如下:
\- COIG-CQIA:https://modelscope.cn/datasets/AI-ModelScope/COIG-CQIA/summary 该数据集包含了中国传统知识、豆瓣、弱智吧、知乎等中文互联网信息
\- 魔搭通用Agent训练数据集: https://modelscope.cn/datasets/AI-ModelScope/ms-agent-for-agentfabric/summary
\- alpaca-en: https://modelscope.cn/datasets/AI-ModelScope/alpaca-gpt4-data-en/summary
\- ms-bench魔搭通用中文问答数据集: https://modelscope.cn/datasets/iic/ms_bench/summary
| **超参数** | **值** |
| --------------------------- | ------ |
| lr | 5e-5 |
| epoch | 2 |
| lora_rank | 8 |
| lora_alpha | 32 |
| lora_target_modules | ALL |
| batch_size | 2 |
| gradient_accumulation_steps | 16 |
## 模型训练命令
```shell
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 |
| Llama3-Chinese-8B-Instruct-Agent-v1 | 0.7577 | 0.4903 | 0.652 |
GSM8K英文数学能力下降了8个点左右,经过消融实验我们发现去除alpaca-en语料会导致GSM8K下降至少十个点以上。
|