AtomGradient
commited on
Commit
•
dc405e7
1
Parent(s):
7ac0e4d
Update README.md
Browse files
README.md
CHANGED
@@ -21,3 +21,39 @@ The following `bitsandbytes` quantization config was used during training:
|
|
21 |
|
22 |
### 额外说明
|
23 |
这是基于LLaMA使用QLoRA技术微调的一个适配器模型
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
### 额外说明
|
23 |
这是基于LLaMA使用QLoRA技术微调的一个适配器模型
|
24 |
+
|
25 |
+
```
|
26 |
+
# imports
|
27 |
+
from peft import PeftModel
|
28 |
+
from transformers import GenerationConfig, LlamaForCausalLM, LlamaTokenizer
|
29 |
+
import torch
|
30 |
+
|
31 |
+
# create tokenizer
|
32 |
+
base_model = "huggyllama/llama-7b"
|
33 |
+
tokenizer = LlamaTokenizer.from_pretrained(base_model)
|
34 |
+
|
35 |
+
# base model
|
36 |
+
model = LlamaForCausalLM.from_pretrained(
|
37 |
+
base_model,
|
38 |
+
torch_dtype=torch.float16,
|
39 |
+
device_map="auto",
|
40 |
+
)
|
41 |
+
|
42 |
+
# LORA PEFT adapters
|
43 |
+
adapter_model = "AtomGradient/adjust_llama-7b"
|
44 |
+
|
45 |
+
model = PeftModel.from_pretrained(
|
46 |
+
model,
|
47 |
+
adapter_model,
|
48 |
+
#torch_dtype=torch.float16,
|
49 |
+
)
|
50 |
+
model.eval()
|
51 |
+
|
52 |
+
# prompt
|
53 |
+
prompt = "美国的总统是谁"
|
54 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
55 |
+
|
56 |
+
# Generate
|
57 |
+
generate_ids = model.generate(**inputs, max_new_tokens=30)
|
58 |
+
print(tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0])
|
59 |
+
```
|