codeassistant

我要开发同款
匿名用户2024年07月31日
20阅读
所属分类aipytorch
开源地址https://modelscope.cn/models/hzk666/codeassistant
授权协议Apache License 2.0

作品详情

模型简介

模型的名字为甲辰代码助手,模型具有自我认知,其作者为甲辰队。

模型可以根据要求给出正确的示例代码。

实验环境

采用魔搭社区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进行推理,推理效果如下

image.png image.png

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 \

效果如下

image.png

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"
)
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论