01GangaPutraBheeshma
commited on
Commit
·
a305790
1
Parent(s):
d725995
Update README.md
Browse files
README.md
CHANGED
@@ -36,92 +36,172 @@ The data on which this model was trained is databricks/databricks-dolly-15k. Wit
|
|
36 |
|
37 |
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
38 |
|
39 |
-
###
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
### Training Data
|
78 |
|
79 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
80 |
-
|
81 |
-
[More Information Needed]
|
82 |
-
|
83 |
-
### Training Procedure
|
84 |
-
|
85 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
86 |
-
|
87 |
-
#### Preprocessing [optional]
|
88 |
-
|
89 |
-
[More Information Needed]
|
90 |
-
|
91 |
-
|
92 |
-
#### Training Hyperparameters
|
93 |
-
|
94 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
95 |
-
|
96 |
-
#### Speeds, Sizes, Times [optional]
|
97 |
-
|
98 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
99 |
-
|
100 |
-
[More Information Needed]
|
101 |
-
|
102 |
-
## Evaluation
|
103 |
-
|
104 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
105 |
-
|
106 |
-
### Testing Data, Factors & Metrics
|
107 |
-
|
108 |
-
#### Testing Data
|
109 |
-
|
110 |
-
<!-- This should link to a Dataset Card if possible. -->
|
111 |
-
|
112 |
-
[More Information Needed]
|
113 |
-
|
114 |
-
#### Factors
|
115 |
-
|
116 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
117 |
-
|
118 |
[More Information Needed]
|
119 |
|
120 |
#### Metrics
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
### Results
|
127 |
|
|
|
36 |
|
37 |
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
38 |
|
39 |
+
### How to get started with this Model
|
40 |
+
```
|
41 |
+
import torch
|
42 |
+
from peft import PeftModel, PeftConfig
|
43 |
+
|
44 |
+
model_name = "01GangaPutraBheeshma/facebook_opt2"
|
45 |
+
trained_model = AutoModelForCausalLM.from_pretrained(model_name)
|
46 |
+
trained_tokenizer = AutoTokenizer.from_pretrained(model_name)
|
47 |
+
|
48 |
+
prompt = """ Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
49 |
+
### Instruction:
|
50 |
+
if one gets corona and you are self-isolating and it is not severe, is there any meds that one can take?
|
51 |
+
|
52 |
+
### Response: """
|
53 |
+
input_ids = trained_tokenizer(prompt, return_tensors="pt", truncation=True).input_ids
|
54 |
+
|
55 |
+
print(f"After Training Response :")
|
56 |
+
outputs = trained_model.generate(input_ids=input_ids, max_new_tokens=100, do_sample=True, top_p=0.9,temperature=1.0)
|
57 |
+
print(f"-------------------------\n\n")
|
58 |
+
print(f"Generated instruction:\n{trained_tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0][len(prompt):]}")
|
59 |
+
print(f"-------------------------\n\n")
|
60 |
+
```
|
61 |
+
|
62 |
+
### Fine-tuning this Model on your own Dataset(Preprocessing the Input Data)
|
63 |
+
|
64 |
+
If you would like to fine-tune this model for other datasets, please try to develop a function, that can make our datasets to be in the same format as our function desires, thus using this below script.
|
65 |
+
```
|
66 |
+
INTRO_BLURB = "Below is an instruction that describes a task. Write a response that appropriately completes the request."
|
67 |
+
INSTRUCTION_KEY = "### Instruction:"
|
68 |
+
INPUT_KEY = "Input:"
|
69 |
+
RESPONSE_KEY = "### Response:"
|
70 |
+
END_KEY = "### End"
|
71 |
+
|
72 |
+
PROMPT_NO_INPUT_FORMAT = """{intro}
|
73 |
+
|
74 |
+
{instruction_key}
|
75 |
+
{instruction}
|
76 |
+
|
77 |
+
{response_key}
|
78 |
+
{response}
|
79 |
+
|
80 |
+
{end_key}""".format(
|
81 |
+
intro=INTRO_BLURB,
|
82 |
+
instruction_key=INSTRUCTION_KEY,
|
83 |
+
instruction="{instruction}",
|
84 |
+
response_key=RESPONSE_KEY,
|
85 |
+
response="{response}",
|
86 |
+
end_key=END_KEY
|
87 |
+
)
|
88 |
+
|
89 |
+
PROMPT_WITH_INPUT_FORMAT = """{intro}
|
90 |
+
|
91 |
+
{instruction_key}
|
92 |
+
{instruction}
|
93 |
+
|
94 |
+
{input_key}
|
95 |
+
{input}
|
96 |
+
|
97 |
+
{response_key}
|
98 |
+
{response}
|
99 |
+
|
100 |
+
{end_key}""".format(
|
101 |
+
intro=INTRO_BLURB,
|
102 |
+
instruction_key=INSTRUCTION_KEY,
|
103 |
+
instruction="{instruction}",
|
104 |
+
input_key=INPUT_KEY,
|
105 |
+
input="{input}",
|
106 |
+
response_key=RESPONSE_KEY,
|
107 |
+
response="{response}",
|
108 |
+
end_key=END_KEY
|
109 |
+
)
|
110 |
+
|
111 |
+
def apply_prompt_template(examples):
|
112 |
+
instruction = examples["instruction"]
|
113 |
+
response = examples["response"]
|
114 |
+
context = examples.get("context")
|
115 |
+
|
116 |
+
if context:
|
117 |
+
full_prompt = PROMPT_WITH_INPUT_FORMAT.format(instruction=instruction, response=response, input=context)
|
118 |
+
else:
|
119 |
+
full_prompt = PROMPT_NO_INPUT_FORMAT.format(instruction=instruction, response=response)
|
120 |
+
return { "text": full_prompt }
|
121 |
+
|
122 |
+
dataset = dataset.map(apply_prompt_template)
|
123 |
+
```
|
124 |
+
## Training Details and Procedure
|
125 |
+
```
|
126 |
+
from transformers import TrainingArguments
|
127 |
+
from trl import SFTTrainer
|
128 |
+
|
129 |
+
output_dir = "./facebook_opt2"
|
130 |
+
per_device_train_batch_size = 4
|
131 |
+
gradient_accumulation_steps = 4
|
132 |
+
optim = "paged_adamw_32bit"
|
133 |
+
save_steps = 500
|
134 |
+
logging_steps = 100
|
135 |
+
learning_rate = 2e-4
|
136 |
+
max_grad_norm = 0.3
|
137 |
+
max_steps = 1000
|
138 |
+
warmup_ratio = 0.03
|
139 |
+
lr_scheduler_type = "constant"
|
140 |
+
|
141 |
+
training_arguments = TrainingArguments(
|
142 |
+
output_dir=output_dir,
|
143 |
+
per_device_train_batch_size=per_device_train_batch_size,
|
144 |
+
gradient_accumulation_steps=gradient_accumulation_steps,
|
145 |
+
optim=optim,
|
146 |
+
save_steps=save_steps,
|
147 |
+
logging_steps=logging_steps,
|
148 |
+
learning_rate=learning_rate,
|
149 |
+
fp16=True,
|
150 |
+
max_grad_norm=max_grad_norm,
|
151 |
+
max_steps=max_steps,
|
152 |
+
warmup_ratio=warmup_ratio,
|
153 |
+
group_by_length=True,
|
154 |
+
lr_scheduler_type=lr_scheduler_type,
|
155 |
+
ddp_find_unused_parameters=False,
|
156 |
+
push_to_hub=True
|
157 |
+
)
|
158 |
+
|
159 |
+
max_seq_length = 512
|
160 |
+
|
161 |
+
trainer = SFTTrainer(
|
162 |
+
model=model,
|
163 |
+
train_dataset=dataset,
|
164 |
+
peft_config=peft_config,
|
165 |
+
dataset_text_field="text",
|
166 |
+
max_seq_length=max_seq_length,
|
167 |
+
tokenizer=tokenizer,
|
168 |
+
args=training_arguments,
|
169 |
+
)
|
170 |
+
```
|
171 |
+
|
172 |
+
output_dir: Directory to save the trained model and logs.
|
173 |
+
per_device_train_batch_size: Number of training samples per GPU.
|
174 |
+
gradient_accumulation_steps: Number of steps to accumulate gradients before updating the model.
|
175 |
+
optim: Optimizer for training (e.g., "paged_adamw_32bit").
|
176 |
+
save_steps: Save model checkpoints every N steps.
|
177 |
+
logging_steps: Log training information every N steps.
|
178 |
+
learning_rate: Initial learning rate for training.
|
179 |
+
max_grad_norm: Maximum gradient norm for gradient clipping.
|
180 |
+
max_steps: Maximum number of training steps.
|
181 |
+
warmup_ratio: Ratio of warmup steps during learning rate warmup.
|
182 |
+
lr_scheduler_type: Type of learning rate scheduler (e.g., "constant").
|
183 |
+
fp16: Enable mixed-precision training.
|
184 |
+
group_by_length: Group training samples by length for efficiency.
|
185 |
+
ddp_find_unused_parameters: Enable distributed training parameter setting.
|
186 |
+
push_to_hub: Push the trained model to the Hugging Face Model Hub.
|
187 |
|
188 |
### Training Data
|
189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
[More Information Needed]
|
191 |
|
192 |
#### Metrics
|
193 |
|
194 |
+
Step Training Loss
|
195 |
+
100 2.189900
|
196 |
+
200 2.014100
|
197 |
+
300 1.957200
|
198 |
+
400 1.990000
|
199 |
+
500 1.985200
|
200 |
+
600 1.986500
|
201 |
+
700 1.964300
|
202 |
+
800 1.951900
|
203 |
+
900 1.936900
|
204 |
+
1000 2.011200
|
205 |
|
206 |
### Results
|
207 |
|