模型简介
模型的名字为甲辰代码助手,模型具有自我认知,其作者为甲辰队。
模型可以根据要求给出正确的示例代码。
实验环境
采用魔搭社区Notebook开发,环境为ubuntu22.04-cuda12.1.0-py310-torch2.1.2-tf2.14.0-1.11.0
gradio版本为3.50.1
训练方法
数据集为code-alpaca-en、codefuse-python-en
微调的模型为qwen-7b-chat
超参数
- system 你是一个代码助手,可以根据用户的要求输出对应的代码。
- train_dataset_sample 3000
- save_steps 500
- lora_target_modules ALL
- learning_rate 1e-5
- gradient_accumulation_steps 1
- eval_batch_size 1
- self_cognition_sample 500
- model_name 甲辰代码助手
- model_author 甲辰队
示例代码
1.安装swift及gradio
pip install ms-swift -U
pip install gradio==3.50.1
2.启动web-ui
swift web-ui
3.设置好参数启动训练,训练命令如下
python /opt/conda/lib/python3.10/site-packages/swift/cli/sft.py --model_id_or_path qwen/Qwen-7B-Chat --template_type qwen --system 你是一个代码助手,可以根据用户的要求输出对应的代码。 --dataset code-alpaca-en codefuse-python-en --train_dataset_sample 3000 --save_steps 500 --lora_target_modules ALL --learning_rate 1e-5 --gradient_accumulation_steps 1 --eval_batch_size 1 --self_cognition_sample 500 --model_name 甲辰代码助手 --model_author 甲辰队 --add_output_dir_suffix False --output_dir /mnt/workspace/output/qwen-7b-chat/v0-20240124-134958 --logging_dir /mnt/workspace/output/qwen-7b-chat/v0-20240124-134958/runs
4.训练好后用web-ui进行推理,推理效果如下
5.使用命令行进行推理,命令如下
CUDA_VISIBLE_DEVICES=0 \
swift infer \
--ckpt_dir "output/qwen-7b-chat/v0-20240124-134958/checkpoint-3000" \
--load_dataset_config true \
--max_length 2048 \
--max_new_tokens 2048 \
--temperature 0.7 \
--top_p 0.7 \
--repetition_penalty 1. \
--do_sample true \
--merge_lora_and_save false \
效果如下
6.编写代码将模型上传,代码如下
from modelscope.hub.api import HubApi
YOUR_ACCESS_TOKEN = '访问令牌'
api = HubApi()
api.login(YOUR_ACCESS_TOKEN)
api.push_model(
model_id="xxxxxxxx",
model_dir="xxxxxx/checkpoint-xxxx"
)
评论