Sandiago21 commited on
Commit
3fd3337
2 Parent(s): ab187da 1c07f34

Merge branch 'main' of https://huggingface.co/Sandiago21/falcon-7b-prompt-answering into main

Browse files
Files changed (1) hide show
  1. README.md +42 -41
README.md CHANGED
@@ -13,9 +13,9 @@ tags:
13
 
14
  ## Model Card for Model ID
15
 
16
- This repository contains a LLaMA-7B further fine-tuned model on conversations and question answering prompts.
17
 
18
- **I used falcon-7b (https://huggingface.co/tiiuae/falcon-7b) as a base model, so this model is for Research purpose only (See the [license](https://huggingface.co/tiiuae/falcon-7b/blob/main/LICENSE))**
19
 
20
 
21
  ## Model Details
@@ -34,7 +34,7 @@ The tiiuae/falcon-7b model was finetuned on conversations and question answering
34
 
35
  **Language(s) (NLP):** English, multilingual
36
 
37
- **License:** Research
38
 
39
  **Finetuned from model:** tiiuae/falcon-7b
40
 
@@ -72,24 +72,11 @@ Users (both direct and downstream) should be made aware of the risks, biases and
72
  The model was trained on the following kind of prompt:
73
 
74
  ```python
75
- def generate_prompt(instruction: str, input_ctxt: str = None) -> str:
76
- if input_ctxt:
77
- 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.
78
-
79
- ### Instruction:
80
- {instruction}
81
-
82
- ### Input:
83
- {input_ctxt}
84
-
85
- ### Response:"""
86
- else:
87
- return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
88
-
89
- ### Instruction:
90
- {instruction}
91
-
92
- ### Response:"""
93
  ```
94
 
95
  ## How to Get Started with the Model
@@ -101,20 +88,27 @@ Use the code below to get started with the model.
101
  ```python
102
  import torch
103
  from peft import PeftConfig, PeftModel
104
- from transformers import GenerationConfig, LlamaTokenizer, LlamaForCausalLM
105
 
106
- MODEL_NAME = "Sandiago21/llama-7b-hf-prompt-answering"
107
 
108
- config = PeftConfig.from_pretrained(MODEL_NAME)
109
 
110
- model = LlamaForCausalLM.from_pretrained(
 
 
 
 
 
 
 
111
  config.base_model_name_or_path,
112
- load_in_8bit=True,
113
- torch_dtype=torch.float16,
114
  device_map="auto",
 
115
  )
116
 
117
- tokenizer = LlamaTokenizer.from_pretrained(MODEL_NAME)
118
 
119
  model = PeftModel.from_pretrained(model, MODEL_NAME)
120
 
@@ -133,10 +127,9 @@ if torch.__version__ >= "2":
133
 
134
  ### Example of Usage
135
  ```python
136
- instruction = "What is the capital city of Greece and with which countries does Greece border?"
137
- input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.
138
 
139
- prompt = generate_prompt(instruction, input_ctxt)
140
  input_ids = tokenizer(prompt, return_tensors="pt").input_ids
141
  input_ids = input_ids.to(model.device)
142
 
@@ -159,21 +152,30 @@ print(response)
159
  ```python
160
  import torch
161
  from peft import PeftConfig, PeftModel
162
- from transformers import GenerationConfig, LlamaTokenizer, LlamaForCausalLM
163
 
164
- MODEL_NAME = "Sandiago21/llama-7b-hf-prompt-answering"
165
  BASE_MODEL = "tiiuae/falcon-7b"
166
 
167
- config = PeftConfig.from_pretrained(MODEL_NAME)
 
 
 
 
 
 
 
 
 
168
 
169
- model = LlamaForCausalLM.from_pretrained(
170
  BASE_MODEL,
171
- load_in_8bit=True,
172
- torch_dtype=torch.float16,
173
  device_map="auto",
 
174
  )
175
 
176
- tokenizer = LlamaTokenizer.from_pretrained(MODEL_NAME)
177
 
178
  model = PeftModel.from_pretrained(model, MODEL_NAME)
179
 
@@ -193,10 +195,9 @@ if torch.__version__ >= "2":
193
  ### Example of Usage
194
 
195
  ```python
196
- instruction = "What is the capital city of Greece and with which countries does Greece border?"
197
- input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.
198
 
199
- prompt = generate_prompt(instruction, input_ctxt)
200
  input_ids = tokenizer(prompt, return_tensors="pt").input_ids
201
  input_ids = input_ids.to(model.device)
202
 
 
13
 
14
  ## Model Card for Model ID
15
 
16
+ This repository contains further fine-tuned Falcon-7B model on conversations and question answering prompts.
17
 
18
+ **I used falcon-7b (https://huggingface.co/tiiuae/falcon-7b) as a base model, so this model has the same license with Falcon-7b model (Apache-2.0)**
19
 
20
 
21
  ## Model Details
 
34
 
35
  **Language(s) (NLP):** English, multilingual
36
 
37
+ **License:** Apache-2.0
38
 
39
  **Finetuned from model:** tiiuae/falcon-7b
40
 
 
72
  The model was trained on the following kind of prompt:
73
 
74
  ```python
75
+ def generate_prompt(prompt: str) -> str:
76
+ return f"""
77
+ <human>: {prompt}
78
+ <assistant>:
79
+ """.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  ```
81
 
82
  ## How to Get Started with the Model
 
88
  ```python
89
  import torch
90
  from peft import PeftConfig, PeftModel
91
+ from transformers import GenerationConfig, AutoTokenizer, AutoModelForCausalLM
92
 
93
+ MODEL_NAME = "Sandiago21/falcon-7b-prompt-answering"
94
 
95
+ compute_dtype = getattr(torch, "float16")
96
 
97
+ bnb_config = BitsAndBytesConfig(
98
+ load_in_4bit=True,
99
+ bnb_4bit_quant_type="nf4",
100
+ bnb_4bit_compute_dtype=compute_dtype,
101
+ bnb_4bit_use_double_quant=True,
102
+ )
103
+
104
+ model = AutoModelForCausalLM.from_pretrained(
105
  config.base_model_name_or_path,
106
+ quantization_config=bnb_config,
 
107
  device_map="auto",
108
+ trust_remote_code=True,
109
  )
110
 
111
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
112
 
113
  model = PeftModel.from_pretrained(model, MODEL_NAME)
114
 
 
127
 
128
  ### Example of Usage
129
  ```python
130
+ prompt = "What is the capital city of Greece and with which countries does Greece border?"
 
131
 
132
+ prompt = generate_prompt(prompt)
133
  input_ids = tokenizer(prompt, return_tensors="pt").input_ids
134
  input_ids = input_ids.to(model.device)
135
 
 
152
  ```python
153
  import torch
154
  from peft import PeftConfig, PeftModel
155
+ from transformers import GenerationConfig, AutoTokenizer, AutoModelForCausalLM
156
 
157
+ MODEL_NAME = "Sandiago21/falcon-7b-prompt-answering"
158
  BASE_MODEL = "tiiuae/falcon-7b"
159
 
160
+ compute_dtype = getattr(torch, "float16")
161
+
162
+ bnb_config = BitsAndBytesConfig(
163
+ load_in_4bit=True,
164
+ bnb_4bit_quant_type="nf4",
165
+ bnb_4bit_compute_dtype=compute_dtype,
166
+ bnb_4bit_use_double_quant=True,
167
+ )
168
+
169
+ MODEL_NAME = "Sandiago21/falcon-7b-prompt-answering"
170
 
171
+ model = AutoModelForCausalLM.from_pretrained(
172
  BASE_MODEL,
173
+ quantization_config=bnb_config,
 
174
  device_map="auto",
175
+ trust_remote_code=True,
176
  )
177
 
178
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
179
 
180
  model = PeftModel.from_pretrained(model, MODEL_NAME)
181
 
 
195
  ### Example of Usage
196
 
197
  ```python
198
+ prompt = "What is the capital city of Greece and with which countries does Greece border?"
 
199
 
200
+ prompt = generate_prompt(prompt)
201
  input_ids = tokenizer(prompt, return_tensors="pt").input_ids
202
  input_ids = input_ids.to(model.device)
203