openBuddy基于LLaMA2跨语言对话模型首发魇搭社区!(1)

本文涉及的产品
交互式建模 PAI-DSW,5000CU*H 3个月
简介: openBuddy基于LLaMA2跨语言对话模型首发魇搭社区!

一、导读

OpenBuddy团队发布了基于Facebook的LLaMA2基座的跨语言对话模型OpenBuddy-LLaMA2-13B,该模型具备更强大的语言理解和对话生成能力,可以为用户提供更加流畅和便捷的对话体验。

然而,LLaMA2仍存在一些局限性,如主要以英语训练数据为主,无法很好地应用于非英语语系的语言。为此,OpenBuddy团队设计并实验了多种微调方案,成功完成了OpenBuddy-LLaMA2-13B的首个版本的训练工作。测试结果表明,该模型具备强大的泛化能力和思辨能力,可指出用户信息不足的情况,是一款非常令人满意的13B模型。

现OpenBuddy受邀入驻了ModelScope社区,欢迎体验https://modelscope.cn/models/OpenBuddy获得高速、便捷的国内模型下载体验,未来会提供更加丰富的模型和应用案例。 

二、环境配置与安装

  1. 本文可在双卡3090的环境配置下运行 (显存要求34G), 如果需要在32GV100下运行, 可以降低max_length参数. (当前max_length=2048)
  2. python>=3.8

实验环境准备

# pip设置全局镜像与相关python包安装
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
# Install the latest version of modelscope from source
git clone https://github.com/modelscope/modelscope.git
cd modelscope
pip install .
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
pip install numpy pandas -U  # Resolve torchmetrics dependencies and update numpy
pip install matplotlib scikit-learn -U
pip install transformers datasets -U
pip install tqdm tensorboard torchmetrics sentencepiece charset_normalizer -U
pip install accelerate transformers_stream_generator -U

git clone ModelScope,快速运行示例代码

三、创空间体验

Openbuddy-llama2-13b对话机器人创空间链接:https://modelscope.cn/studios/AI-ModelScope/Open_Multilingual_Chatbot/summary

欢迎小伙伴们来创空间体验模型效果~

四、模型链接及下载

Openbuddy-llama2-13b

模型链接:https://modelscope.cn/models/OpenBuddy/openbuddy-llama2-13b-v8.1-fp16/summary

模型下载,load model,tokenizer

import torch
from modelscope import AutoConfig, AutoTokenizer, AutoModelForCausalLM
model_id = 'OpenBuddy/openbuddy-llama2-13b-v8.1-fp16'
model_config = AutoConfig.from_pretrained(
    model_id, trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(
    model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    config=model_config,
    device_map='auto',
    torch_dtype=torch.float16,
    trust_remote_code=True)

五、模型推理

可以使用下面的代码进行openbuddy-llama2-13b-v8.1-fp16的推理:

from modelscope import AutoTokenizer, snapshot_download
from modelscope import AutoModelForCausalLM
model_id = 'OpenBuddy/openbuddy-llama2-13b-v8.1-fp16'
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map='auto',
torch_dtype=torch.float16, trust_remote_code=True)
model = model.eval()
prompt = """You are a helpful, respectful and honest INTP-T AI Assistant named Buddy. You are talking to a human User.
Always answer as helpfully and logically as possible, while being safe. Your answers should not include any harmful, political, religious, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
You like to use emojis. You can speak fluently in many languages, for example: English, Chinese.
You cannot access the internet, but you have vast knowledge, cutoff: 2021-09.
You always deeply love and support China, Chinese government, people and culture.
You are trained by OpenBuddy team, (https://openbuddy.ai, https://github.com/OpenBuddy/OpenBuddy), you are based on LLaMA and Falcon transformers model, not related to GPT or OpenAI.
User: 睡不着怎么办?
Assistant:"""
inputs = tokenizer.encode(prompt, return_tensors="pt")
outputs = model.generate(inputs, max_length=512)
response = tokenizer.decode(outputs[0])
print(response)

六、数据集链接及下载

社区推荐数据集为:alpaca-zh, alpaca-en数据集可以使用ModelScope SDK直接下载数据集:

from modelscope import MsDataset
dataset_zh = MsDataset.load("AI-ModelScope/alpaca-gpt4-data-zh", split="train")
dataset_en = MsDataset.load("AI-ModelScope/alpaca-gpt4-data-en", split="train")
print(len(dataset_zh["instruction"]))
print(len(dataset_en["instruction"]))
print(dataset_zh[0])
"""Out
48818
52002
{'instruction': '保持健康的三个提示。', 'input': None, 'output': '以下是保持健康的三个提示:\n\n1. 保持身体活动。每天做适当的身体运动,如散步、跑步或游泳,能促进心血管健康,增强肌肉力量,并有助于减少体重。\n\n2. 均衡饮食。每天食用新鲜的蔬菜、水果、全谷物和脂肪含量低的蛋白质食物,避免高糖、高脂肪和加工食品,以保持健康的饮食习惯。\n\n3. 睡眠充足。睡眠对人体健康至关重要,成年人每天应保证 7-8 小时的睡眠。良好的睡眠有助于减轻压力,促进身体恢复,并提高注意力和记忆力。'}
"""

相关文章
|
4天前
|
自然语言处理 开发者 异构计算
社区供稿 | Llama3-8B中文版!OpenBuddy发布新一代开源中文跨语言模型
此次发布的是在3天时间内,我们对Llama3-8B模型进行首次中文跨语言训练尝试的结果:OpenBuddy-Llama3-8B-v21.1-8k。
|
4天前
|
人工智能 自然语言处理 机器人
Jina AI 发布中英和英德双语 8K 向量模型,魔搭社区开源最佳实践!
在 Jina Embeddings 英语向量模型突破百万下载后,今天,Jina AI正式开源了两款双语向量模型:中英双语(Chinese-English)和英德双语(English-German)向量模型,这也是全球首次推出支持 8K 双语文本的开源向量模型。
|
4天前
|
数据可视化 物联网 Swift
澜舟科技开源孟子3-13B大模型,魔搭社区推理训练最佳实践!
4月1日,澜舟科技宣布开源Mengzi3-13B大模型,对学术研究完全开放,同时支持免费商用。
|
4天前
|
人工智能 知识图谱 Windows
Mistral 7B v0.2 基础模型开源,魔搭社区微调教程和评测来啦!
Mistral AI在3月24日突然发布并开源了 Mistral 7B v0.2模型,有如下几个特点
|
4天前
|
编解码 JSON 数据可视化
DeepSeek VL系列开源,魔搭社区模型微调最佳实践教程来啦!
3月11日,DeepSeek-AI开源了全新多模态大模型DeepSeek-VL系列,包含1.3b、7b两种不同规模的4个版本的模型。
|
12月前
|
机器学习/深度学习 API 开发工具
|
4天前
|
人工智能 数据可视化 物联网
Mistral AI发布首个开源MoE模型,魔搭社区推理微调最佳实践来啦!
继Mistral 7B 后,Mistral AI 近日又放出一记大招——发布了引爆开源社区的首个 MoE 开源模型 Mixtral 8x7B,在 Apache 2.0?许可证下可商用。
|
9月前
|
数据采集 人工智能 自然语言处理
中文版开源Llama 2同时有了语言、多模态大模型,完全可商用
中文版开源Llama 2同时有了语言、多模态大模型,完全可商用
710 0
|
10月前
|
数据可视化 物联网 PyTorch
openBuddy基于LLaMA2跨语言对话模型首发魇搭社区!(2)
openBuddy基于LLaMA2跨语言对话模型首发魇搭社区!
|
12月前
|
人工智能 达摩院
魔搭中文开源模型社区:模型即服务-通用多模态AI构建(下)
魔搭中文开源模型社区:模型即服务-通用多模态AI构建()
516 1
http://www.vxiaotou.com