PetrovDE commited on
Commit
8b21bf3
1 Parent(s): 0637def

Add app and some data to model

Browse files
app.py ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+
4
+ import fire
5
+ import gradio as gr
6
+ import torch
7
+ import transformers
8
+ from peft import PeftModel
9
+ from transformers import GenerationConfig, LlamaForCausalLM, LlamaTokenizer
10
+
11
+ from typing import Union
12
+ import re
13
+
14
+
15
+ class Prompter(object):
16
+ def generate_prompt(
17
+ self,
18
+ instruction: str,
19
+ label: Union[None, str] = None,
20
+ ) -> str:
21
+ res = f"{instruction}\nAnswer: "
22
+
23
+ if label:
24
+ res = f"{res}{label}"
25
+
26
+ return res
27
+
28
+ def get_response(self, output: str) -> str:
29
+ return (
30
+ output.split("Answer:")[1]
31
+ .strip()
32
+ .replace("/", "\u00F7")
33
+ .replace("*", "\u00D7")
34
+ )
35
+
36
+
37
+ load_8bit = True # for Colab
38
+ base_model = "baffo32/decapoda-research-llama-7B-hf"
39
+ lora_weights = "tiedong/goat-lora-7b"
40
+ share_gradio = True
41
+
42
+ if torch.cuda.is_available():
43
+ device = "cuda"
44
+ else:
45
+ device = "cpu"
46
+
47
+ try:
48
+ if torch.backends.mps.is_available():
49
+ device = "mps"
50
+ except:
51
+ pass
52
+
53
+ prompter = Prompter()
54
+
55
+ tokenizer = LlamaTokenizer.from_pretrained("hf-internal-testing/llama-tokenizer")
56
+ if device == "cuda":
57
+ model = LlamaForCausalLM.from_pretrained(
58
+ base_model,
59
+ load_in_8bit=load_8bit,
60
+ torch_dtype=torch.float16,
61
+ device_map="auto",
62
+ )
63
+ model = PeftModel.from_pretrained(
64
+ model,
65
+ lora_weights,
66
+ torch_dtype=torch.float16,
67
+ device_map={"": 0},
68
+ )
69
+ elif device == "mps":
70
+ model = LlamaForCausalLM.from_pretrained(
71
+ base_model,
72
+ device_map={"": device},
73
+ torch_dtype=torch.float16,
74
+ )
75
+ model = PeftModel.from_pretrained(
76
+ model,
77
+ lora_weights,
78
+ device_map={"": device},
79
+ torch_dtype=torch.float16,
80
+ )
81
+ else:
82
+ model = LlamaForCausalLM.from_pretrained(
83
+ base_model, device_map={"": device}, low_cpu_mem_usage=True
84
+ )
85
+ model = PeftModel.from_pretrained(
86
+ model,
87
+ lora_weights,
88
+ device_map={"": device},
89
+ )
90
+
91
+ if not load_8bit:
92
+ model.half()
93
+
94
+ model.eval()
95
+ if torch.__version__ >= "2" and sys.platform != "win32":
96
+ model = torch.compile(model)
97
+
98
+
99
+ def evaluate(
100
+ instruction,
101
+ temperature=0.1,
102
+ top_p=0.75,
103
+ top_k=40,
104
+ num_beams=4,
105
+ max_new_tokens=512,
106
+ stream_output=True,
107
+ **kwargs,
108
+ ):
109
+ prompt = prompter.generate_prompt(instruction)
110
+ inputs = tokenizer(prompt, return_tensors="pt")
111
+ input_ids = inputs["input_ids"].to(device)
112
+ generation_config = GenerationConfig(
113
+ temperature=temperature,
114
+ top_p=top_p,
115
+ top_k=top_k,
116
+ num_beams=num_beams,
117
+ **kwargs,
118
+ )
119
+
120
+ generate_params = {
121
+ "input_ids": input_ids,
122
+ "generation_config": generation_config,
123
+ "return_dict_in_generate": True,
124
+ "output_scores": True,
125
+ "max_new_tokens": max_new_tokens,
126
+ }
127
+
128
+ # Without streaming
129
+ with torch.no_grad():
130
+ generation_output = model.generate(
131
+ input_ids=input_ids,
132
+ generation_config=generation_config,
133
+ return_dict_in_generate=True,
134
+ output_scores=True,
135
+ max_new_tokens=max_new_tokens,
136
+ )
137
+ s = generation_output.sequences[0]
138
+ output = tokenizer.decode(s, skip_special_tokens=True).strip()
139
+ yield prompter.get_response(output)
140
+
141
+
142
+ gr.Interface(
143
+ fn=evaluate,
144
+ inputs=[
145
+ gr.components.Textbox(
146
+ lines=1,
147
+ label="Arithmetic",
148
+ placeholder="What is 63303235 + 20239503",
149
+ ),
150
+ gr.components.Slider(minimum=0, maximum=1, value=0.1, label="Temperature"),
151
+ gr.components.Slider(minimum=0, maximum=1, value=0.75, label="Top p"),
152
+ gr.components.Slider(minimum=0, maximum=100, step=1, value=40, label="Top k"),
153
+ gr.components.Slider(minimum=1, maximum=4, step=1, value=4, label="Beams"),
154
+ gr.components.Slider(
155
+ minimum=1, maximum=1024, step=1, value=512, label="Max tokens"
156
+ ),
157
+ ],
158
+ outputs=[
159
+ gr.Textbox(
160
+ lines=5,
161
+ label="Output",
162
+ )
163
+ ],
164
+ title="test model",
165
+ description="Это пример реализации из goat", # noqa: E501
166
+ ).queue().launch(share=share_gradio)
chkp/adapter_config.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "base_model_name_or_path": "nickypro/tinyllama-15M",
3
+ "bias": "none",
4
+ "enable_lora": null,
5
+ "fan_in_fan_out": false,
6
+ "inference_mode": true,
7
+ "lora_alpha": 64,
8
+ "lora_dropout": 0.05,
9
+ "merge_weights": false,
10
+ "modules_to_save": null,
11
+ "peft_type": "LORA",
12
+ "r": 64,
13
+ "target_modules": [
14
+ "q_proj",
15
+ "v_proj",
16
+ "k_proj",
17
+ "o_proj"
18
+ ],
19
+ "task_type": "CAUSAL_LM"
20
+ }
chkp/adapter_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:49891d6a9e5d6098f4048189ae2bf4df53022b58c7689f25da4e6b9c481a018a
3
+ size 3556350
chkp/optimizer.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e68114a0c0afc9a77f9bd91ed114283dc2093c3bf42383e62897601f2b4f8129
3
+ size 7118586
chkp/rng_state.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cb69e610873a8142e0245cca374768d45ddb50a0c4891436e6dbf04d069a7122
3
+ size 14244
chkp/scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:90ba5da359c992d8f0dc912ca51bea8184b55a457a5f5fdfc7bc2702765e7d0d
3
+ size 1064
chkp/trainer_state.json ADDED
@@ -0,0 +1,349 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 0.23157894736842105,
5
+ "eval_steps": 500,
6
+ "global_step": 550,
7
+ "is_hyper_param_search": false,
8
+ "is_local_process_zero": true,
9
+ "is_world_process_zero": true,
10
+ "log_history": [
11
+ {
12
+ "epoch": 0.0,
13
+ "learning_rate": 1e-05,
14
+ "loss": 4.8744,
15
+ "step": 10
16
+ },
17
+ {
18
+ "epoch": 0.01,
19
+ "learning_rate": 2e-05,
20
+ "loss": 4.1114,
21
+ "step": 20
22
+ },
23
+ {
24
+ "epoch": 0.01,
25
+ "learning_rate": 3e-05,
26
+ "loss": 3.528,
27
+ "step": 30
28
+ },
29
+ {
30
+ "epoch": 0.02,
31
+ "learning_rate": 4e-05,
32
+ "loss": 3.2573,
33
+ "step": 40
34
+ },
35
+ {
36
+ "epoch": 0.02,
37
+ "learning_rate": 5e-05,
38
+ "loss": 3.1417,
39
+ "step": 50
40
+ },
41
+ {
42
+ "epoch": 0.03,
43
+ "learning_rate": 6e-05,
44
+ "loss": 3.0506,
45
+ "step": 60
46
+ },
47
+ {
48
+ "epoch": 0.03,
49
+ "learning_rate": 7e-05,
50
+ "loss": 2.9644,
51
+ "step": 70
52
+ },
53
+ {
54
+ "epoch": 0.03,
55
+ "learning_rate": 8e-05,
56
+ "loss": 2.8399,
57
+ "step": 80
58
+ },
59
+ {
60
+ "epoch": 0.04,
61
+ "learning_rate": 9e-05,
62
+ "loss": 2.6935,
63
+ "step": 90
64
+ },
65
+ {
66
+ "epoch": 0.04,
67
+ "learning_rate": 0.0001,
68
+ "loss": 2.5259,
69
+ "step": 100
70
+ },
71
+ {
72
+ "epoch": 0.05,
73
+ "learning_rate": 9.956043956043956e-05,
74
+ "loss": 2.3713,
75
+ "step": 110
76
+ },
77
+ {
78
+ "epoch": 0.05,
79
+ "learning_rate": 9.912087912087913e-05,
80
+ "loss": 2.2237,
81
+ "step": 120
82
+ },
83
+ {
84
+ "epoch": 0.05,
85
+ "learning_rate": 9.868131868131869e-05,
86
+ "loss": 2.0999,
87
+ "step": 130
88
+ },
89
+ {
90
+ "epoch": 0.06,
91
+ "learning_rate": 9.824175824175824e-05,
92
+ "loss": 2.0211,
93
+ "step": 140
94
+ },
95
+ {
96
+ "epoch": 0.06,
97
+ "learning_rate": 9.780219780219781e-05,
98
+ "loss": 1.949,
99
+ "step": 150
100
+ },
101
+ {
102
+ "epoch": 0.07,
103
+ "learning_rate": 9.736263736263737e-05,
104
+ "loss": 1.8819,
105
+ "step": 160
106
+ },
107
+ {
108
+ "epoch": 0.07,
109
+ "learning_rate": 9.692307692307692e-05,
110
+ "loss": 1.8244,
111
+ "step": 170
112
+ },
113
+ {
114
+ "epoch": 0.08,
115
+ "learning_rate": 9.64835164835165e-05,
116
+ "loss": 1.7849,
117
+ "step": 180
118
+ },
119
+ {
120
+ "epoch": 0.08,
121
+ "learning_rate": 9.604395604395605e-05,
122
+ "loss": 1.7288,
123
+ "step": 190
124
+ },
125
+ {
126
+ "epoch": 0.08,
127
+ "learning_rate": 9.560439560439561e-05,
128
+ "loss": 1.6914,
129
+ "step": 200
130
+ },
131
+ {
132
+ "epoch": 0.09,
133
+ "learning_rate": 9.516483516483517e-05,
134
+ "loss": 1.6534,
135
+ "step": 210
136
+ },
137
+ {
138
+ "epoch": 0.09,
139
+ "learning_rate": 9.472527472527473e-05,
140
+ "loss": 1.6332,
141
+ "step": 220
142
+ },
143
+ {
144
+ "epoch": 0.1,
145
+ "learning_rate": 9.428571428571429e-05,
146
+ "loss": 1.5944,
147
+ "step": 230
148
+ },
149
+ {
150
+ "epoch": 0.1,
151
+ "learning_rate": 9.384615384615386e-05,
152
+ "loss": 1.5789,
153
+ "step": 240
154
+ },
155
+ {
156
+ "epoch": 0.11,
157
+ "learning_rate": 9.340659340659341e-05,
158
+ "loss": 1.5583,
159
+ "step": 250
160
+ },
161
+ {
162
+ "epoch": 0.11,
163
+ "learning_rate": 9.296703296703297e-05,
164
+ "loss": 1.5485,
165
+ "step": 260
166
+ },
167
+ {
168
+ "epoch": 0.11,
169
+ "learning_rate": 9.252747252747253e-05,
170
+ "loss": 1.5124,
171
+ "step": 270
172
+ },
173
+ {
174
+ "epoch": 0.12,
175
+ "learning_rate": 9.208791208791209e-05,
176
+ "loss": 1.5004,
177
+ "step": 280
178
+ },
179
+ {
180
+ "epoch": 0.12,
181
+ "learning_rate": 9.164835164835165e-05,
182
+ "loss": 1.5042,
183
+ "step": 290
184
+ },
185
+ {
186
+ "epoch": 0.13,
187
+ "learning_rate": 9.12087912087912e-05,
188
+ "loss": 1.4991,
189
+ "step": 300
190
+ },
191
+ {
192
+ "epoch": 0.13,
193
+ "learning_rate": 9.076923076923078e-05,
194
+ "loss": 1.4692,
195
+ "step": 310
196
+ },
197
+ {
198
+ "epoch": 0.13,
199
+ "learning_rate": 9.032967032967033e-05,
200
+ "loss": 1.4628,
201
+ "step": 320
202
+ },
203
+ {
204
+ "epoch": 0.14,
205
+ "learning_rate": 8.989010989010989e-05,
206
+ "loss": 1.4481,
207
+ "step": 330
208
+ },
209
+ {
210
+ "epoch": 0.14,
211
+ "learning_rate": 8.945054945054946e-05,
212
+ "loss": 1.454,
213
+ "step": 340
214
+ },
215
+ {
216
+ "epoch": 0.15,
217
+ "learning_rate": 8.901098901098901e-05,
218
+ "loss": 1.4409,
219
+ "step": 350
220
+ },
221
+ {
222
+ "epoch": 0.15,
223
+ "learning_rate": 8.857142857142857e-05,
224
+ "loss": 1.4339,
225
+ "step": 360
226
+ },
227
+ {
228
+ "epoch": 0.16,
229
+ "learning_rate": 8.813186813186814e-05,
230
+ "loss": 1.4262,
231
+ "step": 370
232
+ },
233
+ {
234
+ "epoch": 0.16,
235
+ "learning_rate": 8.76923076923077e-05,
236
+ "loss": 1.4298,
237
+ "step": 380
238
+ },
239
+ {
240
+ "epoch": 0.16,
241
+ "learning_rate": 8.725274725274725e-05,
242
+ "loss": 1.4247,
243
+ "step": 390
244
+ },
245
+ {
246
+ "epoch": 0.17,
247
+ "learning_rate": 8.681318681318682e-05,
248
+ "loss": 1.4191,
249
+ "step": 400
250
+ },
251
+ {
252
+ "epoch": 0.17,
253
+ "learning_rate": 8.637362637362638e-05,
254
+ "loss": 1.4156,
255
+ "step": 410
256
+ },
257
+ {
258
+ "epoch": 0.18,
259
+ "learning_rate": 8.593406593406593e-05,
260
+ "loss": 1.4102,
261
+ "step": 420
262
+ },
263
+ {
264
+ "epoch": 0.18,
265
+ "learning_rate": 8.54945054945055e-05,
266
+ "loss": 1.4121,
267
+ "step": 430
268
+ },
269
+ {
270
+ "epoch": 0.19,
271
+ "learning_rate": 8.505494505494506e-05,
272
+ "loss": 1.4033,
273
+ "step": 440
274
+ },
275
+ {
276
+ "epoch": 0.19,
277
+ "learning_rate": 8.461538461538461e-05,
278
+ "loss": 1.3986,
279
+ "step": 450
280
+ },
281
+ {
282
+ "epoch": 0.19,
283
+ "learning_rate": 8.417582417582419e-05,
284
+ "loss": 1.3935,
285
+ "step": 460
286
+ },
287
+ {
288
+ "epoch": 0.2,
289
+ "learning_rate": 8.373626373626374e-05,
290
+ "loss": 1.399,
291
+ "step": 470
292
+ },
293
+ {
294
+ "epoch": 0.2,
295
+ "learning_rate": 8.32967032967033e-05,
296
+ "loss": 1.3888,
297
+ "step": 480
298
+ },
299
+ {
300
+ "epoch": 0.21,
301
+ "learning_rate": 8.285714285714287e-05,
302
+ "loss": 1.3958,
303
+ "step": 490
304
+ },
305
+ {
306
+ "epoch": 0.21,
307
+ "learning_rate": 8.241758241758242e-05,
308
+ "loss": 1.3758,
309
+ "step": 500
310
+ },
311
+ {
312
+ "epoch": 0.21,
313
+ "learning_rate": 8.197802197802198e-05,
314
+ "loss": 1.3779,
315
+ "step": 510
316
+ },
317
+ {
318
+ "epoch": 0.22,
319
+ "learning_rate": 8.153846153846155e-05,
320
+ "loss": 1.3754,
321
+ "step": 520
322
+ },
323
+ {
324
+ "epoch": 0.22,
325
+ "learning_rate": 8.10989010989011e-05,
326
+ "loss": 1.3754,
327
+ "step": 530
328
+ },
329
+ {
330
+ "epoch": 0.23,
331
+ "learning_rate": 8.065934065934066e-05,
332
+ "loss": 1.3854,
333
+ "step": 540
334
+ },
335
+ {
336
+ "epoch": 0.23,
337
+ "learning_rate": 8.021978021978022e-05,
338
+ "loss": 1.3579,
339
+ "step": 550
340
+ }
341
+ ],
342
+ "logging_steps": 10,
343
+ "max_steps": 2375,
344
+ "num_train_epochs": 1,
345
+ "save_steps": 50,
346
+ "total_flos": 271592074027008.0,
347
+ "trial_name": null,
348
+ "trial_params": null
349
+ }
chkp/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6f2106e8a7b7aaf8d6c8f70689f1a1f3239d79f9126f142a9ce1a3ba53c11449
3
+ size 4536