基于SWIFT和Qwen1.5-0.5B-Chat进行大模型全参微调(魔搭社区)

一、环境安装

因魔搭社区中的Notebook有自己的机制来处理虚拟环境,因此我们直接使用原生镜像即可。

1,swift框架安装

pip install ms-swift

2,模型下载

git clone https://www.modelscope.cn/qwen/Qwen1.5-0.5B-Chat.git

二、数据集准备

使用ShenNong大模型-中医对话数据,选取前140条构建自己数据集ChatMed_TCM-v0.2.json。

数据集下载:git clone https://www.modelscope.cn/datasets/xiaofengalg/ShenNong_TCM_Dataset.git

三、微调

编写微调脚本:vim run.sh

输入--

CUDA_VISIBLE_DEVICES=0 \
swift sft \
    --model_type qwen1half-0_5b-chat \
    --model_id_or_path /mnt/workspace/Qwen1.5-0.5B-Chat \
    --model_revision master \
    --sft_type full \
    --tuner_backend swift \
    --template_type AUTO \
    --dtype AUTO \
    --output_dir ./llm_sft_output \
    --ddp_backend nccl \
    --custom_train_dataset_path /mnt/workspace/dataset/ChatMed_TCM-v0.2.json \
    --train_dataset_sample -1 \
    --num_train_epochs 1 \
    --max_length 4096 \
    --check_dataset_strategy warning \
    --gradient_checkpointing true \
    --batch_size 1 \
    --weight_decay 0.01 \
    --learning_rate 1e-4 \
    --gradient_accumulation_steps $(expr 8 / $nproc_per_node) \
    --max_grad_norm 0.5 \
    --warmup_ratio 0.03 \
    --eval_steps 100 \
    --save_steps 100 \
    --save_total_limit 3 \
    --logging_steps 10 \
    --use_flash_attn false \
    --save_only_model true \
    --self_cognition_sample 500 \
    --model_name "专属AI助手" "Dedicated AI Assistant" \
    --model_author "技术团队" "Tech Team"

执行--bash run.sh
 

1,微调前模型推理:CUDA_VISIBLE_DEVICES=0 swift infer --model_type qwen1half-0_5b-chat --model_id_or_path Qwen1.5-0.5B-Chat

效果如图--

2,微调后模型推理:CUDA_VISIBLE_DEVICES=0 swift infer --ckpt_dir llm_sft_output/qwen1half-0_5b-chat/v2-20240924-164207/checkpoint-79

效果如图--

注:清华镜像加速命令:

pip install 需安装包名 -i https://pypi.tuna.tsinghua.edu.cn/simple

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值