基于mindspore的大模型llama2-7b---微调/推理

环境信息:
1.mindformers指导链接:
https://gitee.com/mindspore/mindformers/blob/dev/docs/model_cards/llama2.md#%E6%A8%A1%E5%9E%8B%E6%9D%83%E9%87%8D%E4%B8%8B%E8%BD%BD%E4%B8%8E%E8%BD%AC%E6%8D%A2

2.镜像:mindformers0.8.0_ms2.2.0-cann7.0rc1_py_3.9:dog
代码:mindformers-dev 代码
权重转换过程中:需要安装pytorch, 原始的中文权重需要下载到存放的目录。[lfx-obs]
英文权重:obs://lfx/weights/llama2_7b_english/
中文权重:obs://lfx/weights/llama2-Chines-7b-Chat

  1. 转换脚本:
    python mindformers/models/llama/convert_weight.py
    –torch_ckpt_dir /home/ma-user/work/llama2_pytorch_weight
    –mindspore_ckpt_path /home/ma-user/work/llama2-hy.ckpt

4.推理脚本:单卡
要保证MA有网,可以直接执行推理,若没有,则需要在当前目录下创建checkpoint_download文件夹,切里面包含llama/llama-7b.yaml的配置文件
python run_mindformer.py --config configs/llama2/run_llama2_7b.yaml --load_checkpoint /home/ma-user/work/mindformers-dev/llama2-hy.ckpt --run_mode predict --predict_data ‘我爱北京, 因为’ --use_parallel False

python run_mindformer.py --config configs/llama2/run_llama2_7b.yaml --run_mode predict --predict_data ‘i love beijing ,because’ --use_parallel False

4.预训练脚本:
数据集转换:
# 使用tools/dataset_preprocess/llama/llama_preprocess.py进行数据预处理+Mindrecord数据生成

python llama_preprocess.py
–dataset_type wiki
-input_glob /home/ma-user/work/mindformers-dev/dataset/wikitext-2/wiki.train.tokens
-model_file /home/ma-user/work/mindformers-dev/dataset/wikitext-2/tokenizer.model
-seq_length 4096
-output_file /home/ma-user/work/mindformers-dev/dataset/mindrecord/wiki4096.mindrecord

5.lora微调脚本:

脚本路径:tools/dataset_preprocess/llama/alpaca_converter.py

执行转换脚本

python alpaca_converter.py
–data_path /home/ma-user/work/weitiao_dataset/alpaca_data.json
–output_path /home/ma-user/work/weitiao_dataset/alpaca-data-conversation.json

pip install fschat
python llama_preprocess.py
–dataset_type qa
–input_glob /home/ma-user/work/weitiao_dataset/alpaca-data-conversation.json
–model_file /home/ma-user/work/mindformers-dev/dataset/wikitext-2/tokenizer.model
–seq_length 2048
–output_file /home/ma-user/work/mindformers-dev/dataset/wikitext-2/alpaca-fastchat2048.mindrecord

中文权重文件:/home/ma-user/work/llama2-hy.ckpt
configs/llama2/run_llama2_7b_lora_910b.yaml 修改dataset_dir:

以llama2-7b为例

load_checkpoint: /home/ma-user/work/llama2-hy.ckpt
auto_trans_ckpt: False
use_parallel参数置为False

启动微调:
cd scripts

单卡启动

bash run_standalone.sh …/configs/llama2/run_llama2_7b_lora_910b.yaml [DEVICE_ID] finetune
./run_standalone.sh …/configs/llama2/run_llama2_7b_lora_910b.yaml 0 finetune > lora.txt 2>&1 &

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hlhy0906

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值