Views
No views yet
LoRA模块,提供给已有Alpaca-2-13B模型的用户。14.69B,通用语料与金融预料比例约为2:1,中英配比约为2:1。1import torch
2from transformers import LlamaForCausalLM, LlamaTokenizer
3from peft import PeftModel
4model_name_or_path = ""
5peft_model_path = ""
6tokenizer = LlamaTokenizer.from_pretrained(model_name_or_path, use_fast=False, legacy=True)
7model = LlamaForCausalLM.from_pretrained(model_name_or_path, torch_dtype=torch.bfloat16,device_map="auto")
8if peft_model_path is not None:
9 model = PeftModel.from_pretrained(
10 model,
11 peft_model_path,
12 torch_dtype=(
13 torch.bfloat16
14 if torch.cuda.is_bf16_supported()
15 else torch.float32
16 ),
17 )
18inputs = tokenizer("什么是A股?", return_tensors="pt").to("cuda")
19outputs = model.generate(**inputs, max_new_tokens=64, repetition_penalty=1.1)
20outputs = tokenizer.decode(outputs.cpu()[0][len(inputs.input_ids[0]):], skip_special_tokens=True)
21print(outputs)