模型介绍
中文整理大模型实战训练营(XJTU)-作业一 代码助手模型
模型介绍
模型名称
中文名:基于qwen-7B的代码助手
英文名:Code assistant based on qwen-7B
模型简介
通义千问-7B(Qwen-7B)是阿里云研发的通义千问大模型系列的70亿参数规模的模型。Qwen-7B是基于Transformer的大语言模型, 在超大规模的预训练数据上进行训练得到。预训练数据类型多样,覆盖广泛,包括大量网络文本、专业书籍、代码等。同时,在Qwen-7B的基础上,我们使用对齐机制打造了基于大语言模型的AI助手Qwen-7B-Chat。相较于最初开源的Qwen-7B模型,我们现已将预训练模型和Chat模型更新到效果更优的版本。
本实验通过ModelScope提供的轻量级微调工具**SWIFT(Scalable lightWeight Infrastructure for Fine-Tuning)**,对**Qwen-7B-Chat**进行微调,实现以下功能:
代码生成能力
- 给出⼀个询问(e.g."使⽤python写快排."),模型可以给出正确的示例代码,以及适当的代码注释,输出的代码需要被\
# 微调模型参数
model type=ModelType.qwen 7b chat,
# 微调数据集参数
dataset=[DatasetName.codefuse evol instruction zh,DatasetName.alpaca zh, DatasetName.alpaca en],
train dataset sample=10000,
# 存储目录参数
output dir='output',
# 自我认知参数
lora target modules='ALL',
self cognition sample=500,
model name=['基于qwen-7B的代码助手', 'Code assistant based on qwen-7B'],
model author=['于子毅', 'YZY'],
# 训练参数
eval steps=100,
quantization bit=4,
gradient accumulation steps =16,
warmup ratio=0.03,
logging steps=10,
LLM微调
import os
import torch
from swift.llm import DatasetName, ModelType
from swift.llm import SftArguments, sft main
os.environ['CUDA VISIBLE DEVICES'] = '0'
torch.cuda.empty cache()
设置微调参数
sft args = SftArguments(
model type=ModelType.qwen 7b chat,
dataset=[DatasetName.codefuse evol instruction zh,DatasetName.alpaca zh, DatasetName.alpaca en],
train dataset sample=10000,
eval steps=100,
logging steps=10,
output dir='output',
lora target modules='ALL',
self cognition sample=500,
model name=['基于qwen-7B的代码助手', 'Code assistant based on qwen-7B'],
model author=['于子毅', 'YZY'],
quantization bit=4,
gradient accumulation steps =16,
warmup ratio=0.03,
)
output = sft main(sft args)
best model checkpoint = output['best model checkpoint']
print(f'best model checkpoint: {best model checkpoint}')
torch.cuda.empty cache()
LLM推理
import os
from swift.llm import InferArguments, merge lora main, infer main
os.environ['CUDA VISIBLE DEVICES'] = '0'
infer args = InferArguments(
ckpt dir=best model checkpoint,
eval human=True)
merge lora main(infer args)
result = infer main(infer args)
torch.cuda.empty cache()
模型上传
from modelscope.hub.api import HubApi
YOUR ACCESS TOKEN ="###" # 自己的SDK令牌
api = HubApi()
api.login(YOUR ACCESS TOKEN)
api.push model(
model id="flashyzy/qwen-7B-chat-code",
model dir=best model checkpoint # 本地模型目录,要求目录中必须包含configuration.json
)
推理效果
在image文件夹下面"自我认知.png","代码及多轮对话能力"
自我认知
代码以及多轮对话能力
优先采用原作者提供的中文模型卡片;仅有英文说明时由闲社AI翻译整理。重要参数、许可证和商用范围请以原文为准。
你将获得什么
完整仓库方式包含该固定版本中的权重、配置、分词器及说明文件;指定版本方式只下载所选文件或整组分片。多模态模型的投影文件、配置等依赖,请按作者说明配齐。
完整仓库可能包含多个权重格式,因此需要的磁盘空间可能大于单一格式的模型大小。下载文件不等于完成模型部署。
使用前须知
运行模型需要的设备、工具与依赖,以原作者说明为准。
是否允许商用、修改和分发,请查看模型许可证。
闲社提供资料与镜像下载方法,不代表已运行模型或完成安全审计。下载的代码应先检查,再执行。
Problem with the information or download?
Sign in to submit feedback.
