Commit
·
d92d198
1
Parent(s):
b144fb9
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
pipeline_tag: text2text-generation
|
6 |
+
---
|
7 |
+
|
8 |
+
First install the following package in a python3.9 environment:
|
9 |
+
|
10 |
+
```batch
|
11 |
+
|
12 |
+
pip install -q git+https://github.com/zphang/transformers@c3dc391
|
13 |
+
pip install bitsandbytes peft torch
|
14 |
+
pip install -q datasets loralib sentencepiece
|
15 |
+
|
16 |
+
```
|
17 |
+
|
18 |
+
How to run inference:
|
19 |
+
|
20 |
+
```python
|
21 |
+
from peft import PeftModel
|
22 |
+
from transformers import LLaMATokenizer, LLaMAForCausalLM, GenerationConfig
|
23 |
+
|
24 |
+
|
25 |
+
tokenizer = LLaMATokenizer.from_pretrained("decapoda-research/llama-7b-hf")
|
26 |
+
|
27 |
+
model = LLaMAForCausalLM.from_pretrained(
|
28 |
+
"decapoda-research/llama-7b-hf",
|
29 |
+
load_in_8bit=True,
|
30 |
+
device_map="auto",
|
31 |
+
)
|
32 |
+
model = PeftModel.from_pretrained(model, "maxime7770/alpaca7B-test")
|
33 |
+
|
34 |
+
PROMPT = """Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
35 |
+
### Instruction:
|
36 |
+
Tell me something about alpacas.
|
37 |
+
### Response:"""
|
38 |
+
|
39 |
+
inputs = tokenizer(
|
40 |
+
PROMPT,
|
41 |
+
return_tensors="pt",
|
42 |
+
)
|
43 |
+
input_ids = inputs["input_ids"].cuda()
|
44 |
+
|
45 |
+
generation_config = GenerationConfig(
|
46 |
+
temperature=0.6,
|
47 |
+
top_p=0.95,
|
48 |
+
repetition_penalty=1.15,
|
49 |
+
)
|
50 |
+
print("Generating...")
|
51 |
+
generation_output = model.generate(
|
52 |
+
input_ids=input_ids,
|
53 |
+
generation_config=generation_config,
|
54 |
+
return_dict_in_generate=True,
|
55 |
+
output_scores=True,
|
56 |
+
max_new_tokens=128,
|
57 |
+
)
|
58 |
+
for s in generation_output.sequences:
|
59 |
+
print(tokenizer.decode(s))
|
60 |
+
|
61 |
+
```
|