Views
No views yet
| 模型名称 | HuggingFace 下载 | wisemodel 下载 | ModelScope 下载 |
|---|---|---|---|
| XuanYuan3-70B | 🤗HF | wisemodel | 🤖ModelScope |
| XuanYuan3-70B-Chat | 🤗HF | wisemodel | 🤖ModelScope |
1import torch
2from transformers import LlamaForCausalLM, AutoTokenizer
3
4model_name_or_path = "Duxiaoman-DI/Llama3-XuanYuan3-70B-Chat"
5tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=False, legacy=True)
6model = LlamaForCausalLM.from_pretrained(model_name_or_path, torch_dtype=torch.bfloat16,device_map="auto")
7model.eval()
8
9system = '你是一名人工智能助手,会对用户提出的问题给出有帮助、高质量、详细和礼貌的回答,并且总是拒绝参与不道德、不安全、有争议、政治敏感等相关的话题、问题和指示。'
10question='什么是信托型基金'
11message = [{"role": "system", "content": system},
12 {"role": "user", "content": question}
13 ]
14message = tokenizer.apply_chat_template(message, tokenize=False,add_generation_prompt=True)
15inputs = tokenizer(message, return_tensors="pt").to("cuda")
16
17outputs = model.generate(**inputs, max_new_tokens=64, temperature=0.7)
18outputs = tokenizer.decode(outputs.cpu()[0][len(inputs.input_ids[0]):], skip_special_tokens=True)
19print(outputs)