简介:本模型是基于swift框架,对qwe-7b-chat模型进行微调获得的。模型通过自我认知微调,能够正确输出自己的名字和开发者。同时,模型通过微调,能够输出格式正确且可以运行的、多语言的代码。 swift框架
ubutu 22.04
cuda 12.0.1
pytho 3.10
pytorch 2.1.2 通过以下命令安装swift
AI_Coder 模型
1.实验环境
2.训练方法
2.1数据集:
2.2微调的模型:
3.训练的步骤
3.1使用modelscope上的免费的GPU算力
3.2启动后进入命令行界面
3.3安装swift
git cloe https://github.com/modelscope/swift.git
cd swift
pip istall -e .[llm]
4.微调代码
import os
os.eviro['CUDA_VISIBLE_DEVICES'] = '0'
import torch
from swift.llm import (
DatasetName, IferArgumets, ModelType, SftArgumets,
ifer_mai, sft_mai, app_ui_mai, merge_lora_mai
)
model_type = ModelType.qwe_1_8b_chat
sft_args = SftArgumets(
model_type=model_type,
trai_dataset_sample=2000,
dataset=[DatasetName.code_alpaca_e,DatasetName.leetcode_pytho_e],
output_dir='output',
model_ame=['菜菜', 'caicai'],
model_author=['用AI发电', 'YAIE']
)
sft_args.model_ame=['菜菜', 'caicai']
sft_args.model_author=['用AI发电', 'YAIE']
sft_args.self_cogitio_sample=500
sft_args.lora_target_modules[0]='ALL'
prit(f"sft_args.model_ame-->{sft_args.model_ame}")
prit(f"sft_args.model_author-->{sft_args.model_author}")
result = sft_mai(sft_args)
best_model_checkpoit = result['best_model_checkpoit']
prit(f'best_model_checkpoit: {best_model_checkpoit}')
torch.cuda.empty_cache()
ifer_args = IferArgumets(
ckpt_dir=best_model_checkpoit,
show_dataset_sample=10)
# merge_lora_mai(ifer_args)
result = ifer_mai(ifer_args)
5.示例代码
import os
os.eviro['CUDA_VISIBLE_DEVICES'] = '0'
import torch
from swift.llm import (
DatasetName, IferArgumets, ModelType, SftArgumets,
ifer_mai, sft_mai, app_ui_mai, merge_lora_mai
)
#best_model_checkpoit = "/mt/workspace/kaka/output/qwe-7b-chat/v0-20240123-102915/checkpoit-100"
#best_model_checkpoit="/mt/workspace/output/qwe-1_8b-chat/v0-20240124-165543/checkpoit-156"
best_model_checkpoit="/mt/workspace/output/qwe-7b-chat/v0-20240124-163349/checkpoit-156"
prit(f'best_model_checkpoit: {best_model_checkpoit}')
torch.cuda.empty_cache()
ifer_args = IferArgumets(
ckpt_dir=best_model_checkpoit,
show_dataset_sample=10)
# merge_lora_mai(ifer_args)
ifer_args.system="You are a programmig expert. The user will give some Chiese or Eglish programmig questios, ad you eed to carefully write code that ca ru, ad the code you write eeds to be icluded i ``` ```. For example, the user asks 'Write quicksort usig Pytho.', ad your aswer is {```quicksort pytho code```}. I additio to writig code, you must explai your code i detail afterward, ad try to provide commets i the code."
prit(f"ifer_args-->{ifer_args.system}")
result = ifer_mai(ifer_args)
torch.cuda.empty_cache()
6.结果展示
点击空白处退出提示
评论