由于Llama2本身的中文对齐较弱,我们采用中文指令集,对meta-llama/Llama-2-7b-chat-hf进行LoRA微调,使其具备较强的中文对话能力。
🎯 该版本为LoRA中文微调参数FlagAlpha/Llama2-Chinese-7b-Chat-LoRA和meta-llama/Llama-2-7b-chat-hf参数结合后的版本,可直接使用
Github:Llama-Chinese
在线体验链接:llama.family
欢迎来到Llama2中文社区!
我们是一个专注于Llama2模型在中文方面的优化和上层建设的高级技术社区。
基于大规模中文数据,从预训练开始对Llama2模型进行中文能力的持续迭代升级。
我们热忱欢迎对大模型LLM充满热情的开发者和研究者加入我们的行列。
from openmind import AutoTokenizer, AutoModelForCausalLM, pipeline, is_torch_npu_available
from openmind_hub import snapshot_download
import openmind
import torch
import argparse
import time
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--model_name_or_path",
type=str,
help="Path to model",
default="jeffding/Llama2-Chinese-7b-Chat-openmind",
)
args = parser.parse_args()
return args
def main():
args = parse_args()
model_path = args.model_name_or_path
if is_torch_npu_available():
device = "npu:0"
else:
device = "cpu"
model = AutoModelForCausalLM.from_pretrained(model_path,
device_map=device,
trust_remote_code=False,
revision="main").to(device)
tokenizer = AutoTokenizer.from_pretrained(model_path, use_fast=True,trust_remote_code=False)
start_time = time.time()
prompt = "简单介绍一下llamas这个模型"
system_message = "你是一个故事写作小助手"
prompt_template=f'''[INST] {prompt} [/INST]
'''
print("*** Pipeline:")
pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
max_new_tokens=512,
do_sample=True,
temperature=0.7,
top_p=0.95,
top_k=40,
repetition_penalty=1.1,
)
print(pipe(prompt_template))
end_time = time.time()
print(f"硬件环境:{device},推理执行时间:{end_time - start_time}秒")
if __name__ == "__main__":
main()