YuvrajSingh9886
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -1,22 +1,232 @@
|
|
|
|
1 |
---
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
license: apache-2.0
|
6 |
-
tags:
|
7 |
-
- text-generation-inference
|
8 |
-
- transformers
|
9 |
-
- unsloth
|
10 |
-
- mistral
|
11 |
-
- trl
|
12 |
---
|
13 |
|
|
|
14 |
# Uploaded model
|
15 |
|
16 |
- **Developed by:** YuvrajSingh9886
|
17 |
- **License:** apache-2.0
|
18 |
- **Finetuned from model :** unsloth/phi-3-mini-4k-instruct-bnb-4bit
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
This mistral model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
1 |
+
|
2 |
---
|
3 |
+
library_name: transformers
|
4 |
+
tags: [Text Generation, Question-Answering]
|
5 |
+
inference: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
---
|
7 |
|
8 |
+
|
9 |
# Uploaded model
|
10 |
|
11 |
- **Developed by:** YuvrajSingh9886
|
12 |
- **License:** apache-2.0
|
13 |
- **Finetuned from model :** unsloth/phi-3-mini-4k-instruct-bnb-4bit
|
14 |
|
15 |
+
|
16 |
+
|
17 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
18 |
+
|
19 |
+
It's a fine-tuned version of Phi-2 model by Microsoft on [Alpaca-Cleaned-52k](yahma/alpaca-cleaned).
|
20 |
+
|
21 |
+
|
22 |
+
## Uses
|
23 |
+
|
24 |
+
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
25 |
+
The above model, with applicable changes to the generation_config file, passed to model.generate() function can lead to the generation of better results which could then be used for Health Counseling Chatbot dev.
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
## Bias, Risks, and Limitations
|
30 |
+
|
31 |
+
The model was developed as a proof-of-concept type hobby project and is not intended to be used without careful consideration of its implications.
|
32 |
+
|
33 |
+
[More Information Needed]
|
34 |
+
|
35 |
+
|
36 |
+
## How to Get Started with the Model
|
37 |
+
|
38 |
+
Use the code below to get started with the model.
|
39 |
+
|
40 |
+
### Load in the model using the BitsandBytes library
|
41 |
+
|
42 |
+
```python
|
43 |
+
pip install bitsandbytes
|
44 |
+
```
|
45 |
+
|
46 |
+
#### Load model from Hugging Face Hub with model name and bitsandbytes configuration
|
47 |
+
|
48 |
+
```python
|
49 |
+
|
50 |
+
def load_model_tokenizer(model_name: str, bnb_config: BitsAndBytesConfig) -> Tuple[AutoModelForCausalLM, AutoTokenizer]:
|
51 |
+
"""
|
52 |
+
Load the model and tokenizer from the HuggingFace model hub using quantization.
|
53 |
+
|
54 |
+
Args:
|
55 |
+
model_name (str): The name of the model.
|
56 |
+
bnb_config (BitsAndBytesConfig): The quantization configuration of BitsAndBytes.
|
57 |
+
|
58 |
+
Returns:
|
59 |
+
Tuple[AutoModelForCausalLM, AutoTokenizer]: The model and tokenizer.
|
60 |
+
"""
|
61 |
+
|
62 |
+
|
63 |
+
model = AutoModelForCausalLM.from_pretrained(
|
64 |
+
model_name,
|
65 |
+
quantization_config = bnb_config,
|
66 |
+
# device_map = "auto",
|
67 |
+
torch_dtype="auto",
|
68 |
+
trust_remote_code=True
|
69 |
+
)
|
70 |
+
|
71 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token = True, trust_remote_code=True)
|
72 |
+
|
73 |
+
tokenizer.pad_token = tokenizer.eos_token
|
74 |
+
|
75 |
+
return model, tokenizer
|
76 |
+
|
77 |
+
|
78 |
+
bnb_config = BitsAndBytesConfig(
|
79 |
+
load_in_4bit = load_in_4bit,
|
80 |
+
bnb_4bit_use_double_quant = bnb_4bit_use_double_quant,
|
81 |
+
bnb_4bit_quant_type = bnb_4bit_quant_type,
|
82 |
+
bnb_4bit_compute_dtype = bnb_4bit_compute_dtype,
|
83 |
+
)
|
84 |
+
|
85 |
+
model, tokenizer = load_model_tokenizer(model_name, bnb_config)
|
86 |
+
|
87 |
+
```
|
88 |
+
|
89 |
+
```python
|
90 |
+
|
91 |
+
new_model = "YuvrajSingh9886/medicinal-QnA-phi2-custom"
|
92 |
+
|
93 |
+
prompt = "I have been feeling more and more down for over a month. I have started having trouble sleeping due to panic attacks, but they are almost never triggered by something that I know of."
|
94 |
+
|
95 |
+
tokens = tokenizer(f"### Question: {prompt}", return_tensors='pt').to('cuda')
|
96 |
+
tokenizer.pad_token = tokenizer.eos_token
|
97 |
+
outputs = model.generate(**tokens, max_new_tokens=1024, num_beams=5,
|
98 |
+
no_repeat_ngram_size=2,
|
99 |
+
early_stopping=True
|
100 |
+
)
|
101 |
+
print(tokenizer.batch_decode(outputs,skip_special_tokens=True)[0])
|
102 |
+
|
103 |
+
```
|
104 |
+
|
105 |
+
## Training Details
|
106 |
+
|
107 |
+
### Training Data
|
108 |
+
|
109 |
+
|
110 |
+
#### Hardware
|
111 |
+
|
112 |
+
Epcohs: 10
|
113 |
+
Hardware: (1) RTX 4090 (24GB VRAM) 48GB 8vCPU (RAM)
|
114 |
+
Hard Disk: 40GB
|
115 |
+
|
116 |
+
|
117 |
+
[More Information Needed]
|
118 |
+
|
119 |
+
### Training Procedure
|
120 |
+
|
121 |
+
QLoRA was used for quantization purposes.
|
122 |
+
|
123 |
+
Phi-2 model from Huggingface with BitsandBytes support
|
124 |
+
|
125 |
+
|
126 |
+
#### Preprocessing [optional]
|
127 |
+
|
128 |
+
```python
|
129 |
+
|
130 |
+
def format_phi2(row):
|
131 |
+
question = row['Context']
|
132 |
+
answer = row['Response']
|
133 |
+
|
134 |
+
# text = f"[INST] {question} [/INST] {answer}".replace('\xa0', ' ')
|
135 |
+
text = f"### Question: {question}\n ### Answer: {answer}"
|
136 |
+
|
137 |
+
return text
|
138 |
+
```
|
139 |
+
|
140 |
+
#### Training Hyperparameters
|
141 |
+
|
142 |
+
|
143 |
+
LoRA config-
|
144 |
+
```bash
|
145 |
+
# LoRA attention dimension (int)
|
146 |
+
lora_r = 64
|
147 |
+
|
148 |
+
# Alpha parameter for LoRA scaling (int)
|
149 |
+
lora_alpha = 16
|
150 |
+
|
151 |
+
# Dropout probability for LoRA layers (float)
|
152 |
+
lora_dropout = 0.05
|
153 |
+
|
154 |
+
# Bias (string)
|
155 |
+
bias = "none"
|
156 |
+
|
157 |
+
# Task type (string)
|
158 |
+
task_type = "CAUSAL_LM"
|
159 |
+
|
160 |
+
# Random seed (int)
|
161 |
+
seed = 33
|
162 |
+
```
|
163 |
+
|
164 |
+
Phi-2 config-
|
165 |
+
|
166 |
+
```bash
|
167 |
+
# Batch size per GPU for training (int)
|
168 |
+
per_device_train_batch_size = 6
|
169 |
+
|
170 |
+
# Number of update steps to accumulate the gradients for (int)
|
171 |
+
gradient_accumulation_steps = 2
|
172 |
+
|
173 |
+
# Initial learning rate (AdamW optimizer) (float)
|
174 |
+
learning_rate = 2e-4
|
175 |
+
|
176 |
+
# Optimizer to use (string)
|
177 |
+
optim = "paged_adamw_8bit"
|
178 |
+
|
179 |
+
# Number of training epochs (int)
|
180 |
+
num_train_epochs = 4
|
181 |
+
|
182 |
+
# Linear warmup steps from 0 to learning_rate (int)
|
183 |
+
warmup_steps = 10
|
184 |
+
|
185 |
+
# Enable fp16/bf16 training (set bf16 to True with an A100) (bool)
|
186 |
+
fp16 = True
|
187 |
+
|
188 |
+
# Log every X updates steps (int)
|
189 |
+
logging_steps = 100
|
190 |
+
|
191 |
+
#L2 regularization(prevents overfitting)
|
192 |
+
weight_decay=0.0
|
193 |
+
|
194 |
+
#Checkpoint saves
|
195 |
+
save_strategy="epoch"
|
196 |
+
```
|
197 |
+
|
198 |
+
BnB config
|
199 |
+
|
200 |
+
```bash
|
201 |
+
# Activate 4-bit precision base model loading (bool)
|
202 |
+
load_in_4bit = True
|
203 |
+
|
204 |
+
# Activate nested quantization for 4-bit base models (double quantization) (bool)
|
205 |
+
bnb_4bit_use_double_quant = True
|
206 |
+
|
207 |
+
# Quantization type (fp4 or nf4) (string)
|
208 |
+
bnb_4bit_quant_type = "nf4"
|
209 |
+
|
210 |
+
# Compute data type for 4-bit base models
|
211 |
+
bnb_4bit_compute_dtype = torch.bfloat16
|
212 |
+
|
213 |
+
```
|
214 |
+
|
215 |
+
### Results
|
216 |
+
|
217 |
+
Training loss: 2.229
|
218 |
+
Validation loss: 2.223
|
219 |
+
|
220 |
+
|
221 |
+
## More Information [optional]
|
222 |
+
|
223 |
+
[Phi-2](https://huggingface.co/microsoft/phi-2)
|
224 |
+
|
225 |
+
## Model Card Authors [optional]
|
226 |
+
|
227 |
+
[YuvrajSingh9886](https://huggingface.co/YuvrajSingh9886)
|
228 |
+
|
229 |
+
|
230 |
This mistral model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
231 |
|
232 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|