匿名用户2024年07月31日
35阅读
所属分类aipytorch
开源地址https://modelscope.cn/models/jiuyuefeixiang/AI_Coder

作品详情

AI_Coder 模型

简介:本模型是基于swift框架,对qwen-7b-chat模型进行微调获得的。模型通过自我认知微调,能够正确输出自己的名字和开发者。同时,模型通过微调,能够输出格式正确且可以运行的、多语言的代码。

1.实验环境

swift框架 ubuntu 22.04 cuda 12.0.1 python 3.10 pytorch 2.1.2

2.训练方法

2.1数据集:

codealpacaen
leetcodepythonen

2.2微调的模型:

qwen-7b-chat

3.训练的步骤

3.1使用modelscope上的免费的GPU算力

3.2启动后进入命令行界面

3.3安装swift

通过以下命令安装swift

git clone https://github.com/modelscope/swift.git
cd swift
pip install -e .[llm]

4.微调代码

import os

os.environ['CUDA_VISIBLE_DEVICES'] = '0'

import torch

from swift.llm import (

DatasetName, InferArguments, ModelType, SftArguments,

infer_main, sft_main, app_ui_main, merge_lora_main

)

model_type = ModelType.qwen_1_8b_chat

sft_args = SftArguments(

model_type=model_type,

train_dataset_sample=2000,

dataset=[DatasetName.code_alpaca_en,DatasetName.leetcode_python_en],

output_dir='output',

model_name=['菜菜', 'caicai'],

model_author=['用AI发电', 'YAIE']

)

sft_args.model_name=['菜菜', 'caicai']

sft_args.model_author=['用AI发电', 'YAIE']

sft_args.self_cognition_sample=500

sft_args.lora_target_modules[0]='ALL'

print(f"sft_args.model_name-->{sft_args.model_name}")

print(f"sft_args.model_author-->{sft_args.model_author}")

result = sft_main(sft_args)

best_model_checkpoint = result['best_model_checkpoint']

print(f'best_model_checkpoint: {best_model_checkpoint}')

torch.cuda.empty_cache()

infer_args = InferArguments(

ckpt_dir=best_model_checkpoint,

show_dataset_sample=10)

# merge_lora_main(infer_args)

result = infer_main(infer_args)

5.示例代码

import os

os.environ['CUDA_VISIBLE_DEVICES'] = '0'

import torch

from swift.llm import (

DatasetName, InferArguments, ModelType, SftArguments,

infer_main, sft_main, app_ui_main, merge_lora_main

)

#best_model_checkpoint = "/mnt/workspace/kaka/output/qwen-7b-chat/v0-20240123-102915/checkpoint-100"

#best_model_checkpoint="/mnt/workspace/output/qwen-1_8b-chat/v0-20240124-165543/checkpoint-156"

best_model_checkpoint="/mnt/workspace/output/qwen-7b-chat/v0-20240124-163349/checkpoint-156"

print(f'best_model_checkpoint: {best_model_checkpoint}')

torch.cuda.empty_cache()

infer_args = InferArguments(

ckpt_dir=best_model_checkpoint,

show_dataset_sample=10)

# merge_lora_main(infer_args)

infer_args.system="You are a programming expert. The user will give some Chinese or English programming questions, and you need to carefully write code that can run, and the code you write needs to be included in ``` ```. For example, the user asks 'Write quicksort using Python.', and your answer is {```quicksort python code```}. In addition to writing code, you must explain your code in detail afterward, and try to provide comments in the code."

print(f"infer_args-->{infer_args.system}")

result = infer_main(infer_args)

torch.cuda.empty_cache()

6.结果展示

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

评论