chainyo
commited on
Commit
•
5a99b54
1
Parent(s):
d417c1f
update tokenizer + instructions
Browse files- README.md +66 -2
- special_tokens_map.json +1 -0
- tokenizer.model +3 -0
- tokenizer_config.json +1 -0
README.md
CHANGED
@@ -1,3 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# Alpaca LoRa 7B
|
2 |
|
3 |
This repository contains a LLaMA-7B fine-tuned model on the [Standford Alpaca](https://github.com/tatsu-lab/stanford_alpaca) cleaned version dataset.
|
@@ -6,20 +17,73 @@ This repository contains a LLaMA-7B fine-tuned model on the [Standford Alpaca](h
|
|
6 |
|
7 |
# Usage
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
## Using the model
|
10 |
|
11 |
```python
|
12 |
-
|
|
|
13 |
|
14 |
-
tokenizer = LlamaTokenizer.from_pretrained("
|
15 |
model = LlamaForCausalLM.from_pretrained(
|
16 |
"chainyo/alpaca-lora-7b",
|
17 |
load_in_8bit=True,
|
18 |
torch_dtype=torch.float16,
|
19 |
device_map="auto",
|
20 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
model.eval()
|
23 |
if torch.__version__ >= "2":
|
24 |
model = torch.compile(model)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
```
|
|
|
1 |
+
---
|
2 |
+
title: Alpaca LoRa 7B
|
3 |
+
language: en
|
4 |
+
license: other
|
5 |
+
tags:
|
6 |
+
- alpaca
|
7 |
+
- lora
|
8 |
+
- llama
|
9 |
+
- peft
|
10 |
+
---
|
11 |
+
|
12 |
# Alpaca LoRa 7B
|
13 |
|
14 |
This repository contains a LLaMA-7B fine-tuned model on the [Standford Alpaca](https://github.com/tatsu-lab/stanford_alpaca) cleaned version dataset.
|
|
|
17 |
|
18 |
# Usage
|
19 |
|
20 |
+
## Creating prompt
|
21 |
+
|
22 |
+
The model was trained on the following kind of prompt:
|
23 |
+
|
24 |
+
```python
|
25 |
+
def generate_prompt(instruction: str, input_ctxt: str = None) -> str:
|
26 |
+
if input:
|
27 |
+
return f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
28 |
+
|
29 |
+
### Instruction:
|
30 |
+
{instruction}
|
31 |
+
|
32 |
+
### Input:
|
33 |
+
{input}
|
34 |
+
|
35 |
+
### Response:"""
|
36 |
+
else:
|
37 |
+
return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
38 |
+
|
39 |
+
### Instruction:
|
40 |
+
{instruction}
|
41 |
+
|
42 |
+
### Response:"""
|
43 |
+
```
|
44 |
+
|
45 |
## Using the model
|
46 |
|
47 |
```python
|
48 |
+
import torch
|
49 |
+
from transformers import GenerationConfig, LlamaTokenizer, LlamaForCausalLM
|
50 |
|
51 |
+
tokenizer = LlamaTokenizer.from_pretrained("chainyo/alpaca-lora-7b")
|
52 |
model = LlamaForCausalLM.from_pretrained(
|
53 |
"chainyo/alpaca-lora-7b",
|
54 |
load_in_8bit=True,
|
55 |
torch_dtype=torch.float16,
|
56 |
device_map="auto",
|
57 |
)
|
58 |
+
generation_config = GenerationConfig(
|
59 |
+
temperature=0.2,
|
60 |
+
top_p=0.75,
|
61 |
+
top_k=40,
|
62 |
+
num_beams=4,
|
63 |
+
max_new_tokens=128,
|
64 |
+
)
|
65 |
|
66 |
model.eval()
|
67 |
if torch.__version__ >= "2":
|
68 |
model = torch.compile(model)
|
69 |
+
|
70 |
+
instruction = "What is the meaning of life?"
|
71 |
+
input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.
|
72 |
+
|
73 |
+
prompt = generate_prompt(instruction, input_ctxt)
|
74 |
+
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
|
75 |
+
input_ids = input_ids.to(model.device)
|
76 |
+
|
77 |
+
with torch.no_grad():
|
78 |
+
outputs = model.generate(
|
79 |
+
input_ids=input_ids,
|
80 |
+
generation_config=generation_config,
|
81 |
+
return_dict_in_generate=True,
|
82 |
+
output_scores=True,
|
83 |
+
)
|
84 |
+
|
85 |
+
response = tokenizer.decode(outputs.sequences[0], skip_special_tokens=True)
|
86 |
+
print(response)
|
87 |
+
|
88 |
+
>>> The meaning of life is to live a life of meaning.
|
89 |
```
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{}
|
tokenizer.model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347
|
3 |
+
size 499723
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"bos_token": "", "eos_token": "", "model_max_length": 1000000000000000019884624838656, "tokenizer_class": "LlaMATokenizer", "unk_token": ""}
|