ModelScope-Agent-Qwen-7B
模型简介
ModelScope-Agent是魔搭社区推出的智能体Agent框架。MSAgent-Qwen-7B是基于Qwen-7B基础上微调训练后的,驱动该Agent框架的核心模型。其中Qwen-7B是基于Transformer的大语言模型, 在超大规模的预训练数据上进行训练得到。预训练数据类型多样,覆盖广泛,包括大量网络文本、专业书籍、代码等。在Qwen-7B-Chat模型的基础上,我们使用MSAgent-Bench数据集训练增强其作为Agent中枢的调用AI模型,工具和利用检索知识问答的能力。
如果您想了解更多关于ModelScope-Agent的细节,我们建议您参阅ModelScope-Agent Github代码库。
依赖项(Dependency)
运行MSAgent-Qwen-7B,请确保机器环境pytorch版本不低于1.12,再执行以下pip命令安装依赖库
pip install modelscope
pip install transformers_stream_generator
另外,推荐安装flash-attention
库,以实现更高的效率和更低的显存占用。
In addition, it is recommended to install the flash-attention
library for higher efficiency and lower memory usage.
git clone -b v1.0.8 https://github.com/Dao-AILab/flash-attention
cd flash-attention && pip install .
pip install csrc/layer_norm
pip install csrc/rotary
版本介绍
- v1.0.2: 该版本为通用Agent版本,在AI模型调用和通用工具调用以及工具调用的泛化性上都比较强,通过MSAgent-Bench全量训练数据训练得到
- v1.0.1: 该版本为魔搭GPT应用的开源模型,主要在AI模型调用上能力比较强,包括图片生成,视频生成等,具体能力可在右侧创空间体验
快速使用
下面我们展示了一个使用MSAgent-Qwen-7B模型,进行多轮对话交互的样例(非流式):
from modelscope import AutoModelForCausalLM, AutoTokenizer
from modelscope import GenerationConfig
tokenizer = AutoTokenizer.from_pretrained("damo/MSAgent-Qwen-7B", revision = 'v1.0.2',trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("damo/MSAgent-Qwen-7B", revision = 'v1.0.2',device_map="auto", trust_remote_code=True,fp16=True).eval()
model.generation_config = GenerationConfig.from_pretrained("damo/MSAgent-Qwen-7B",revision = 'v1.0.2', trust_remote_code=True) # 可指定不同的生成长度、top_p等相关超参
system = """
<|system|>:当前对话可以使用的插件信息如下,请自行判断是否需要调用插件来解决当前用户问题。若需要调用插件,则需要将插件调用请求按
照json格式给出,必须包含api_name、url、parameters字段,并在其前后使用<|startofthink|>和<|endofthink|>作为标志。然后你需要根据插
件API调用结果生成合理的答复;若无需调用插件,则直接给出对应回复即可:
1. {"name": "modelscope_image-generation", "description": "图片生成服务,针对文本输入,生成对应的图片,插图等", "parameters": [{"name": "text", "description": "用户输入的文本信息", "required": true}]}
2. {"name": "modelscope_speech-generation", "description": "朗读文本内容,将文本转语音服务,将文字转换为自然而逼真的语音,可配置男声/女声", "parameters": [{"name": "input", "description": "要转成语音的文本", "required": true}, {"name": "gender", "description": "用户身份", "required": true}]}
"""
response, history = model.chat(tokenizer, "嗨,storyagent,我正在为一个新的电子绘本构思一个故事。我希望这是一个关于友谊和冒险的故事,主角是一只勇敢的小狐狸和其他小动物,生成三个故事情节,分段写出。", history=None, system=system)
print(response)
response, history = model.chat(tokenizer, "生成一张插图,根据故事情节一的内容。", history=history, system=system)
print(response)
response, history = model.chat(tokenizer, "请用女生语音读下这个故事的第一段内容。", history=history, system=system)
print(response)
模型细节(Model)
与Qwen-7B预训练模型相同,MSAgent-Qwen-7B模型规模基本情况如下所示
Hyperparameter | Value |
---|---|
n_layers | 32 |
n_heads | 32 |
d_model | 4096 |
vocab size | 151851 |
sequence length | 2048 |
在分词器方面,相比目前主流开源模型以中英词表为主,Qwen-7B-Chat使用了约15万token大小的词表。
该词表在GPT-4使用的BPE词表cl100k_base
基础上,对中文、多语言进行了优化,在对中、英、代码数据的高效编解码的基础上,对部分多语言更加友好,方便用户在不扩展词表的情况下对部分语种进行能力增强。
词表对数字按单个数字位切分。调用较为高效的tiktoken分词库进行分词。
评测效果(Evaluation)
使用协议(License Agreement)
我们的代码和模型权重对学术研究完全开放,并支持商用。请查看LICENSE了解具体的开源协议细节。
Our code and checkpoints are open to research purpose, and they are allowed for commercial purposes. Check LICENSE for more details about the license.
评论