Update README.md
Browse files
README.md
CHANGED
@@ -4,9 +4,9 @@ language:
|
|
4 |
pipeline_tag: conversational
|
5 |
---
|
6 |
|
7 |
-
|
8 |
|
9 |
-
|
10 |
import torch
|
11 |
import bitsandbytes as bnb
|
12 |
from transformers import LlamaTokenizer, LlamaForCausalLM, GenerationConfig
|
@@ -19,4 +19,47 @@ model = LlamaForCausalLM.from_pretrained("decapoda-research/llama-7b-hf",
|
|
19 |
load_in_8bit=True,
|
20 |
device_map="auto")
|
21 |
# Load the LoRA model
|
22 |
-
model = PeftModel.from_pretrained(model, peft_model_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
pipeline_tag: conversational
|
5 |
---
|
6 |
|
7 |
+
# How to Use
|
8 |
|
9 |
+
```python
|
10 |
import torch
|
11 |
import bitsandbytes as bnb
|
12 |
from transformers import LlamaTokenizer, LlamaForCausalLM, GenerationConfig
|
|
|
19 |
load_in_8bit=True,
|
20 |
device_map="auto")
|
21 |
# Load the LoRA model
|
22 |
+
model = PeftModel.from_pretrained(model, peft_model_id)
|
23 |
+
|
24 |
+
def generate_prompt(instruction, input=None):
|
25 |
+
if input:
|
26 |
+
return f"""Berikut ini adalah petunjuk yang menjelaskan tugas, serta masukan yang menyediakan konteks tambahan. Tulis balasan yang melengkapi permintaan dengan tepat.
|
27 |
+
|
28 |
+
Petunjuk:
|
29 |
+
{instruction}
|
30 |
+
|
31 |
+
Masukan:
|
32 |
+
{input}
|
33 |
+
|
34 |
+
Output:"""
|
35 |
+
|
36 |
+
else:
|
37 |
+
return f"""Berikut ini terdapat panduan yang menjelaskan tugas. Mohon tuliskan balasan yang melengkapi permintaan dengan tepat.
|
38 |
+
|
39 |
+
Panduan:
|
40 |
+
{instruction}
|
41 |
+
|
42 |
+
Output:"""
|
43 |
+
|
44 |
+
generation_config = GenerationConfig(
|
45 |
+
temperature=0.2,
|
46 |
+
top_p=0.75,
|
47 |
+
num_beams=8
|
48 |
+
)
|
49 |
+
|
50 |
+
def evaluate(instruction, input=None):
|
51 |
+
prompt = generate_prompt(instruction, input)
|
52 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
53 |
+
input_ids = inputs["input_ids"].cuda()
|
54 |
+
generation_output = model.generate(
|
55 |
+
input_ids=input_ids,
|
56 |
+
generation_config=generation_config,
|
57 |
+
return_dict_in_generate=True,
|
58 |
+
output_scores=True,
|
59 |
+
max_new_tokens=256
|
60 |
+
)
|
61 |
+
for s in generation_output.sequences:
|
62 |
+
output = tokenizer.decode(s)
|
63 |
+
print("Output:", output.split("Output:")[1].strip())
|
64 |
+
```
|
65 |
+
|