Update README.md
Browse files
README.md
CHANGED
@@ -4,23 +4,116 @@ datasets:
|
|
4 |
- timdettmers/openassistant-guanaco
|
5 |
library_name: adapter-transformers
|
6 |
pipeline_tag: text-generation
|
|
|
|
|
|
|
7 |
---
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
- timdettmers/openassistant-guanaco
|
5 |
library_name: adapter-transformers
|
6 |
pipeline_tag: text-generation
|
7 |
+
language:
|
8 |
+
- pt
|
9 |
+
- en
|
10 |
---
|
11 |
|
12 |
+
<div style="text-align:center;width:250px;height:250px;">
|
13 |
+
<img src="https://huggingface.co/Bruno/Harpia-7b-guanacoLora/blob/main/download.jpeg" alt="pomeranian logo"">
|
14 |
+
</div>
|
15 |
+
|
16 |
+
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
17 |
+
should probably proofread and complete it, then remove this comment. -->
|
18 |
+
|
19 |
+
# Harpia
|
20 |
+
|
21 |
+
## Adapter Description
|
22 |
+
This adapter was created with the [PEFT](https://github.com/huggingface/peft) library and allowed the base model **Falcon-7b** to be fine-tuned on the **timdettmers/openassistant-guanaco** by using the method **QLoRA**.
|
23 |
+
|
24 |
+
## Model description
|
25 |
+
|
26 |
+
[Falcon 7B](https://huggingface.co/tiiuae/falcon-7b)
|
27 |
+
|
28 |
+
## Intended uses & limitations
|
29 |
+
|
30 |
+
TBA
|
31 |
+
|
32 |
+
## Training and evaluation data
|
33 |
+
|
34 |
+
TBA
|
35 |
+
|
36 |
+
|
37 |
+
### Training results
|
38 |
+
|
39 |
+
|
40 |
+
### How to use
|
41 |
+
```py
|
42 |
+
import torch
|
43 |
+
from peft import PeftModel, PeftConfig
|
44 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, AutoTokenizer, GenerationConfig
|
45 |
+
|
46 |
+
peft_model_id = "Bruno/Harpia-7b-guanacoLora"
|
47 |
+
|
48 |
+
config = PeftConfig.from_pretrained(peft_model_id)
|
49 |
+
bnb_config = BitsAndBytesConfig(
|
50 |
+
load_in_4bit=True,
|
51 |
+
bnb_4bit_quant_type="nf4",
|
52 |
+
bnb_4bit_compute_dtype=torch.float16,
|
53 |
+
)
|
54 |
+
|
55 |
+
tokenizer = AutoTokenizer.from_pretrained(peft_model_id)
|
56 |
+
|
57 |
+
model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path,
|
58 |
+
return_dict=True,
|
59 |
+
quantization_config=bnb_config,
|
60 |
+
trust_remote_code=True,
|
61 |
+
device_map={"":0})
|
62 |
+
|
63 |
+
|
64 |
+
prompt_input = ""
|
65 |
+
prompt_no_input = ""
|
66 |
+
|
67 |
+
def create_prompt(instruction, input=None):
|
68 |
+
if input:
|
69 |
+
return prompt_input.format(instruction=instruction, input=input)
|
70 |
+
else:
|
71 |
+
return prompt_no_input.format(instruction=instruction)
|
72 |
+
|
73 |
+
def generate(
|
74 |
+
instruction,
|
75 |
+
input=None,
|
76 |
+
max_new_tokens=128,
|
77 |
+
temperature=0.1,
|
78 |
+
top_p=0.75,
|
79 |
+
top_k=40,
|
80 |
+
num_beams=4,
|
81 |
+
**kwargs,
|
82 |
+
):
|
83 |
+
prompt = create_prompt(instruction, input)
|
84 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
85 |
+
input_ids = inputs["input_ids"].to("cuda")
|
86 |
+
attention_mask = inputs["attention_mask"].to("cuda")
|
87 |
+
generation_config = GenerationConfig(
|
88 |
+
temperature=temperature,
|
89 |
+
top_p=top_p,
|
90 |
+
top_k=top_k,
|
91 |
+
num_beams=num_beams,
|
92 |
+
**kwargs,
|
93 |
+
)
|
94 |
+
with torch.no_grad():
|
95 |
+
generation_output = model.generate(
|
96 |
+
input_ids=input_ids,
|
97 |
+
attention_mask=attention_mask,
|
98 |
+
generation_config=generation_config,
|
99 |
+
return_dict_in_generate=True,
|
100 |
+
output_scores=True,
|
101 |
+
max_new_tokens=max_new_tokens
|
102 |
+
)
|
103 |
+
s = generation_output.sequences[0]
|
104 |
+
output = tokenizer.decode(s)
|
105 |
+
return output.split("### Respuesta:")[1]
|
106 |
+
|
107 |
+
instruction = "Dime algo sobre los halcones"
|
108 |
+
|
109 |
+
print("Instrucción:", instruction)
|
110 |
+
print("Respuesta:", generate(instruction))
|
111 |
+
```
|
112 |
+
|
113 |
+
|
114 |
+
### Framework versions
|
115 |
+
|
116 |
+
- Transformers 4.30.0.dev0
|
117 |
+
- Pytorch 2.0.1+cu118
|
118 |
+
- Datasets 2.12.0
|
119 |
+
- Tokenizers 0.13.3
|