File size: 26,619 Bytes
b4f4f9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
b4f4f9d
da59d46
 
 
 
 
b4f4f9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
 
dcfeee1
da59d46
 
 
 
 
 
b692321
da59d46
 
 
 
 
 
 
 
 
 
 
 
5b52ebb
da59d46
 
 
b4f4f9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dcfeee1
b4f4f9d
 
 
 
 
 
 
5b52ebb
b4f4f9d
 
9ef5a14
b4f4f9d
5b52ebb
b4f4f9d
 
5b52ebb
b4f4f9d
 
 
 
 
da59d46
b692321
5b52ebb
9ef5a14
b692321
b4f4f9d
 
 
da59d46
b4f4f9d
 
 
 
 
 
 
da59d46
b4f4f9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dcfeee1
b4f4f9d
 
 
 
dcfeee1
 
 
b4f4f9d
 
 
 
 
 
 
 
 
 
 
 
dcfeee1
b4f4f9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dcfeee1
b4f4f9d
 
da59d46
 
 
 
 
 
b692321
 
 
 
 
5b52ebb
 
 
 
 
dcfeee1
b692321
 
 
 
 
5b52ebb
 
 
 
 
da59d46
b692321
 
 
 
 
5b52ebb
 
 
 
 
dcfeee1
b692321
 
 
 
 
5b52ebb
 
 
 
 
da59d46
b692321
 
 
 
 
5b52ebb
 
 
 
 
da59d46
 
 
b4f4f9d
 
5b52ebb
 
b4f4f9d
 
 
dcfeee1
b4f4f9d
 
 
 
 
 
 
5b52ebb
b4f4f9d
5b52ebb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b692321
5b52ebb
 
 
 
 
 
 
 
 
 
b692321
5b52ebb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ef5a14
b692321
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b52ebb
 
 
 
 
 
 
 
b692321
5b52ebb
 
9ef5a14
b692321
 
5b52ebb
 
 
 
9ef5a14
b692321
5b52ebb
 
9ef5a14
b692321
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ef5a14
b692321
 
 
 
 
 
 
 
 
9ef5a14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4f4f9d
da59d46
 
 
 
5b52ebb
da59d46
 
 
b4f4f9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dcfeee1
b4f4f9d
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "21111b1f-7cce-4e8b-8337-8f0cdab5804e",
   "metadata": {},
   "source": [
    "# AutoTrain"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dd09a9fd-4b90-48f3-b61c-d2349eb7f43e",
   "metadata": {},
   "source": [
    "## Imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "52543575-f92e-4038-ad13-30967f47eb7a",
   "metadata": {
    "jupyter": {
     "is_executing": true
    }
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import subprocess\n",
    "\n",
    "import yaml"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74987944-abfb-44f8-9331-ffbb2f7698bb",
   "metadata": {},
   "source": [
    "## Config"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6992324b-173c-4335-b557-cf78fbb2dd93",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b5b27c90c4e849e6aa04587d526e108f",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "VBox(children=(HTML(value='<center> <img\\nsrc=https://huggingface.co/front/assets/huggingface_logo-noborder.sv…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from huggingface_hub import login, get_token, whoami\n",
    "login()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "97c25070-775a-4fb1-9694-4579250686a6",
   "metadata": {},
   "source": [
    "### Template\n",
    "Im creating a template so we can iterate through each of our experiments.\n",
    "\n",
    "Here you can see a few design decisions:\n",
    "- We leave `project_name` and `text_column` empty to overwrite later per experiment\n",
    "- We log in tensorboard, you can use wandb, but you will need to install it in the AutoTrain env that is run on spaces, which gets complex\n",
    "- I choose an `l4x1` from [these options](https://github.com/huggingface/autotrain-advanced/blob/2d787b2033414d06f1e9be2ea0caacad3097f5e8/src/autotrain/backends/base.py#L21)\n",
    "    - This is a [well priced](https://huggingface.co/pricing#spaces) way of training a 7B moodel \n",
    "    - It's very efficient as well at 24GB VRAM\n",
    "- It's becoming less common to use a `valid_split` \n",
    "- I run 2 epochs as the loss still decreases steadily, but some say for LoRAs you should just do 1\n",
    "- Its a good idea use `all-linear` when using LoRA "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "dc2a8514-51c1-404b-8cfa-6637cc810668",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Base config\n",
    "config_template = {\n",
    "    \"task\": \"llm-sft\",\n",
    "    \"base_model\": \"tiiuae/Falcon3-7B-Instruct\",\n",
    "    \"project_name\": \"\",\n",
    "    \"log\": \"tensorboard\",\n",
    "    \"backend\": \"spaces-a100-large\",\n",
    "    \"data\": {\n",
    "        \"path\": \"derek-thomas/labeled-multiple-choice-explained-falcon-tokenized\",\n",
    "        \"train_split\": \"train\",\n",
    "        \"valid_split\": None,\n",
    "        \"chat_template\": \"tokenizer\",\n",
    "        \"column_mapping\": {\n",
    "            \"text_column\": \"\"\n",
    "            },\n",
    "        },\n",
    "    \"params\": {\n",
    "        \"block_size\": 512,\n",
    "        \"model_max_length\": 1750,\n",
    "        \"epochs\": 4,\n",
    "        \"batch_size\": 8,\n",
    "        \"lr\": 5e-5,\n",
    "        \"peft\": True,\n",
    "        \"quantization\": \"int4\",\n",
    "        \"target_modules\": \"all-linear\",\n",
    "        \"padding\": \"right\",\n",
    "        \"optimizer\": \"adamw_torch\",\n",
    "        \"scheduler\": \"linear\",\n",
    "        \"gradient_accumulation\": 8,\n",
    "        \"mixed_precision\": \"bf16\",\n",
    "        },\n",
    "    \"hub\": {\n",
    "        \"username\": \"derek-thomas\",\n",
    "        \"token\": get_token(),\n",
    "        \"push_to_hub\": True,\n",
    "        },\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "22eb3d3a-0ab0-4f79-98c2-513a34ce1b6d",
   "metadata": {},
   "source": [
    "### Experiments\n",
    "Here we choose the `project_name` and `text_column` for each experiment."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "957eb2b7-feec-422f-ba46-b293d9a77c1b",
   "metadata": {},
   "outputs": [],
   "source": [
    "project_suffixes = [\"RFA-gpt3-5\", \"RFA-falcon\", \"FAR-gpt3-5\", \"FAR-falcon\", \"FA\"]\n",
    "text_columns = [\"conversation_RFA_gpt3_5\", \"conversation_RFA_falcon\", \"conversation_FAR_gpt3_5\",\n",
    "                \"conversation_FAR_falcon\", \"conversation_FA\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5913085-83c9-4133-a90d-318fd13cc14e",
   "metadata": {},
   "source": [
    "Directory to store generated configs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b86702bf-f494-4951-863e-be5b8462fbd1",
   "metadata": {},
   "outputs": [],
   "source": [
    "output_dir = \"./autotrain_configs\"\n",
    "os.makedirs(output_dir, exist_ok=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3053d1e1-ca40-460c-8999-0787a1751d00",
   "metadata": {},
   "source": [
    "## AutoTrain for each Experiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "025ccd2f-de54-4ac2-9f36-f606876dcd3c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running autotrain with config: ./autotrain_configs/conversation_RFA_gpt3_5.yml\n",
      "INFO     | 2025-01-10 13:45:51 | autotrain.cli.autotrain:main:58 - Using AutoTrain configuration: ./autotrain_configs/conversation_RFA_gpt3_5.yml\n",
      "INFO     | 2025-01-10 13:45:51 | autotrain.parser:__post_init__:165 - Running task: lm_training\n",
      "INFO     | 2025-01-10 13:45:51 | autotrain.parser:__post_init__:166 - Using backend: spaces-a100-large\n",
      "INFO     | 2025-01-10 13:45:51 | autotrain.parser:run:224 - {'model': 'tiiuae/Falcon3-7B-Instruct', 'project_name': 'falcon-v03-poe-RFA-gpt3-5', 'data_path': 'derek-thomas/labeled-multiple-choice-explained-falcon-tokenized', 'train_split': 'train', 'valid_split': None, 'add_eos_token': True, 'block_size': 512, 'model_max_length': 1750, 'padding': 'right', 'trainer': 'sft', 'use_flash_attention_2': False, 'log': 'tensorboard', 'disable_gradient_checkpointing': False, 'logging_steps': -1, 'eval_strategy': 'epoch', 'save_total_limit': 1, 'auto_find_batch_size': False, 'mixed_precision': 'bf16', 'lr': 5e-05, 'epochs': 4, 'batch_size': 8, 'warmup_ratio': 0.1, 'gradient_accumulation': 8, 'optimizer': 'adamw_torch', 'scheduler': 'linear', 'weight_decay': 0.0, 'max_grad_norm': 1.0, 'seed': 42, 'chat_template': 'tokenizer', 'quantization': 'int4', 'target_modules': 'all-linear', 'merge_adapter': False, 'peft': True, 'lora_r': 16, 'lora_alpha': 32, 'lora_dropout': 0.05, 'model_ref': None, 'dpo_beta': 0.1, 'max_prompt_length': 128, 'max_completion_length': None, 'prompt_text_column': None, 'text_column': 'conversation_RFA_gpt3_5', 'rejected_text_column': None, 'push_to_hub': True, 'username': 'derek-thomas', 'token': '*****', 'unsloth': False, 'distributed_backend': None}\n",
      "INFO     | 2025-01-10 13:45:54 | autotrain.parser:run:229 - Job ID: derek-thomas/autotrain-falcon-v03-poe-RFA-gpt3-5\n",
      "\n",
      "---\n",
      "https://huggingface.co/spaces/derek-thomas/autotrain-falcon-v03-poe-RFA-gpt3-5\n",
      "---\n",
      "\n",
      "Running autotrain with config: ./autotrain_configs/conversation_RFA_falcon.yml\n",
      "INFO     | 2025-01-10 13:45:58 | autotrain.cli.autotrain:main:58 - Using AutoTrain configuration: ./autotrain_configs/conversation_RFA_falcon.yml\n",
      "INFO     | 2025-01-10 13:45:58 | autotrain.parser:__post_init__:165 - Running task: lm_training\n",
      "INFO     | 2025-01-10 13:45:58 | autotrain.parser:__post_init__:166 - Using backend: spaces-a100-large\n",
      "INFO     | 2025-01-10 13:45:58 | autotrain.parser:run:224 - {'model': 'tiiuae/Falcon3-7B-Instruct', 'project_name': 'falcon-v03-poe-RFA-falcon', 'data_path': 'derek-thomas/labeled-multiple-choice-explained-falcon-tokenized', 'train_split': 'train', 'valid_split': None, 'add_eos_token': True, 'block_size': 512, 'model_max_length': 1750, 'padding': 'right', 'trainer': 'sft', 'use_flash_attention_2': False, 'log': 'tensorboard', 'disable_gradient_checkpointing': False, 'logging_steps': -1, 'eval_strategy': 'epoch', 'save_total_limit': 1, 'auto_find_batch_size': False, 'mixed_precision': 'bf16', 'lr': 5e-05, 'epochs': 4, 'batch_size': 8, 'warmup_ratio': 0.1, 'gradient_accumulation': 8, 'optimizer': 'adamw_torch', 'scheduler': 'linear', 'weight_decay': 0.0, 'max_grad_norm': 1.0, 'seed': 42, 'chat_template': 'tokenizer', 'quantization': 'int4', 'target_modules': 'all-linear', 'merge_adapter': False, 'peft': True, 'lora_r': 16, 'lora_alpha': 32, 'lora_dropout': 0.05, 'model_ref': None, 'dpo_beta': 0.1, 'max_prompt_length': 128, 'max_completion_length': None, 'prompt_text_column': None, 'text_column': 'conversation_RFA_falcon', 'rejected_text_column': None, 'push_to_hub': True, 'username': 'derek-thomas', 'token': '*****', 'unsloth': False, 'distributed_backend': None}\n",
      "INFO     | 2025-01-10 13:46:01 | autotrain.parser:run:229 - Job ID: derek-thomas/autotrain-falcon-v03-poe-RFA-falcon\n",
      "\n",
      "---\n",
      "https://huggingface.co/spaces/derek-thomas/autotrain-falcon-v03-poe-RFA-falcon\n",
      "---\n",
      "\n",
      "Running autotrain with config: ./autotrain_configs/conversation_FAR_gpt3_5.yml\n",
      "INFO     | 2025-01-10 13:46:05 | autotrain.cli.autotrain:main:58 - Using AutoTrain configuration: ./autotrain_configs/conversation_FAR_gpt3_5.yml\n",
      "INFO     | 2025-01-10 13:46:05 | autotrain.parser:__post_init__:165 - Running task: lm_training\n",
      "INFO     | 2025-01-10 13:46:05 | autotrain.parser:__post_init__:166 - Using backend: spaces-a100-large\n",
      "INFO     | 2025-01-10 13:46:05 | autotrain.parser:run:224 - {'model': 'tiiuae/Falcon3-7B-Instruct', 'project_name': 'falcon-v03-poe-FAR-gpt3-5', 'data_path': 'derek-thomas/labeled-multiple-choice-explained-falcon-tokenized', 'train_split': 'train', 'valid_split': None, 'add_eos_token': True, 'block_size': 512, 'model_max_length': 1750, 'padding': 'right', 'trainer': 'sft', 'use_flash_attention_2': False, 'log': 'tensorboard', 'disable_gradient_checkpointing': False, 'logging_steps': -1, 'eval_strategy': 'epoch', 'save_total_limit': 1, 'auto_find_batch_size': False, 'mixed_precision': 'bf16', 'lr': 5e-05, 'epochs': 4, 'batch_size': 8, 'warmup_ratio': 0.1, 'gradient_accumulation': 8, 'optimizer': 'adamw_torch', 'scheduler': 'linear', 'weight_decay': 0.0, 'max_grad_norm': 1.0, 'seed': 42, 'chat_template': 'tokenizer', 'quantization': 'int4', 'target_modules': 'all-linear', 'merge_adapter': False, 'peft': True, 'lora_r': 16, 'lora_alpha': 32, 'lora_dropout': 0.05, 'model_ref': None, 'dpo_beta': 0.1, 'max_prompt_length': 128, 'max_completion_length': None, 'prompt_text_column': None, 'text_column': 'conversation_FAR_gpt3_5', 'rejected_text_column': None, 'push_to_hub': True, 'username': 'derek-thomas', 'token': '*****', 'unsloth': False, 'distributed_backend': None}\n",
      "INFO     | 2025-01-10 13:46:08 | autotrain.parser:run:229 - Job ID: derek-thomas/autotrain-falcon-v03-poe-FAR-gpt3-5\n",
      "\n",
      "---\n",
      "https://huggingface.co/spaces/derek-thomas/autotrain-falcon-v03-poe-FAR-gpt3-5\n",
      "---\n",
      "\n",
      "Running autotrain with config: ./autotrain_configs/conversation_FAR_falcon.yml\n",
      "INFO     | 2025-01-10 13:46:13 | autotrain.cli.autotrain:main:58 - Using AutoTrain configuration: ./autotrain_configs/conversation_FAR_falcon.yml\n",
      "INFO     | 2025-01-10 13:46:13 | autotrain.parser:__post_init__:165 - Running task: lm_training\n",
      "INFO     | 2025-01-10 13:46:13 | autotrain.parser:__post_init__:166 - Using backend: spaces-a100-large\n",
      "INFO     | 2025-01-10 13:46:13 | autotrain.parser:run:224 - {'model': 'tiiuae/Falcon3-7B-Instruct', 'project_name': 'falcon-v03-poe-FAR-falcon', 'data_path': 'derek-thomas/labeled-multiple-choice-explained-falcon-tokenized', 'train_split': 'train', 'valid_split': None, 'add_eos_token': True, 'block_size': 512, 'model_max_length': 1750, 'padding': 'right', 'trainer': 'sft', 'use_flash_attention_2': False, 'log': 'tensorboard', 'disable_gradient_checkpointing': False, 'logging_steps': -1, 'eval_strategy': 'epoch', 'save_total_limit': 1, 'auto_find_batch_size': False, 'mixed_precision': 'bf16', 'lr': 5e-05, 'epochs': 4, 'batch_size': 8, 'warmup_ratio': 0.1, 'gradient_accumulation': 8, 'optimizer': 'adamw_torch', 'scheduler': 'linear', 'weight_decay': 0.0, 'max_grad_norm': 1.0, 'seed': 42, 'chat_template': 'tokenizer', 'quantization': 'int4', 'target_modules': 'all-linear', 'merge_adapter': False, 'peft': True, 'lora_r': 16, 'lora_alpha': 32, 'lora_dropout': 0.05, 'model_ref': None, 'dpo_beta': 0.1, 'max_prompt_length': 128, 'max_completion_length': None, 'prompt_text_column': None, 'text_column': 'conversation_FAR_falcon', 'rejected_text_column': None, 'push_to_hub': True, 'username': 'derek-thomas', 'token': '*****', 'unsloth': False, 'distributed_backend': None}\n",
      "INFO     | 2025-01-10 13:46:16 | autotrain.parser:run:229 - Job ID: derek-thomas/autotrain-falcon-v03-poe-FAR-falcon\n",
      "\n",
      "---\n",
      "https://huggingface.co/spaces/derek-thomas/autotrain-falcon-v03-poe-FAR-falcon\n",
      "---\n",
      "\n",
      "Running autotrain with config: ./autotrain_configs/conversation_FA.yml\n",
      "INFO     | 2025-01-10 13:46:20 | autotrain.cli.autotrain:main:58 - Using AutoTrain configuration: ./autotrain_configs/conversation_FA.yml\n",
      "INFO     | 2025-01-10 13:46:20 | autotrain.parser:__post_init__:165 - Running task: lm_training\n",
      "INFO     | 2025-01-10 13:46:20 | autotrain.parser:__post_init__:166 - Using backend: spaces-a100-large\n",
      "INFO     | 2025-01-10 13:46:20 | autotrain.parser:run:224 - {'model': 'tiiuae/Falcon3-7B-Instruct', 'project_name': 'falcon-v03-poe-FA', 'data_path': 'derek-thomas/labeled-multiple-choice-explained-falcon-tokenized', 'train_split': 'train', 'valid_split': None, 'add_eos_token': True, 'block_size': 512, 'model_max_length': 1750, 'padding': 'right', 'trainer': 'sft', 'use_flash_attention_2': False, 'log': 'tensorboard', 'disable_gradient_checkpointing': False, 'logging_steps': -1, 'eval_strategy': 'epoch', 'save_total_limit': 1, 'auto_find_batch_size': False, 'mixed_precision': 'bf16', 'lr': 5e-05, 'epochs': 4, 'batch_size': 8, 'warmup_ratio': 0.1, 'gradient_accumulation': 8, 'optimizer': 'adamw_torch', 'scheduler': 'linear', 'weight_decay': 0.0, 'max_grad_norm': 1.0, 'seed': 42, 'chat_template': 'tokenizer', 'quantization': 'int4', 'target_modules': 'all-linear', 'merge_adapter': False, 'peft': True, 'lora_r': 16, 'lora_alpha': 32, 'lora_dropout': 0.05, 'model_ref': None, 'dpo_beta': 0.1, 'max_prompt_length': 128, 'max_completion_length': None, 'prompt_text_column': None, 'text_column': 'conversation_FA', 'rejected_text_column': None, 'push_to_hub': True, 'username': 'derek-thomas', 'token': '*****', 'unsloth': False, 'distributed_backend': None}\n",
      "INFO     | 2025-01-10 13:46:23 | autotrain.parser:run:229 - Job ID: derek-thomas/autotrain-falcon-v03-poe-FA\n",
      "\n",
      "---\n",
      "https://huggingface.co/spaces/derek-thomas/autotrain-falcon-v03-poe-FA\n",
      "---\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Generate configs and run commands\n",
    "autotrain_spaces = []\n",
    "autotrain_models = []\n",
    "for project_suffix, text_column in zip(project_suffixes, text_columns):\n",
    "    # Modify the config\n",
    "    config = config_template.copy()\n",
    "    config[\"project_name\"] = f\"falcon-v03-poe-{project_suffix}\"\n",
    "    config[\"data\"][\"column_mapping\"][\"text_column\"] = text_column\n",
    "\n",
    "    # Save the config to a YAML file\n",
    "    config_path = os.path.join(output_dir, f\"{text_column}.yml\")\n",
    "    with open(config_path, \"w\") as f:\n",
    "        yaml.dump(config, f)\n",
    "\n",
    "    # # Run the command\n",
    "    print(f\"Running autotrain with config: {config_path}\")\n",
    "    subprocess.run([\"autotrain\", \"--config\", config_path])\n",
    "\n",
    "    space_name = f\"{whoami()['name']}/autotrain-{config['project_name']}\"\n",
    "    model_name = f\"{whoami()['name']}/{config['project_name']}\"\n",
    "    autotrain_spaces.append(space_name)\n",
    "    autotrain_models.append(model_name)\n",
    "    print(f'\\n---\\nhttps://huggingface.co/spaces/{space_name}\\n---\\n')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bf3d3324-202b-45df-8897-58cf89931c45",
   "metadata": {},
   "source": [
    "# Cleanup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "adf09687-ab1e-4f1e-8bf9-317cc928467a",
   "metadata": {},
   "outputs": [],
   "source": [
    "from huggingface_hub import HfApi\n",
    "api = HfApi()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "19d80d26-cda4-41fb-a125-06060c3f90ce",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['derek-thomas/autotrain-falcon-v03-poe-RFA-gpt3-5',\n",
      " 'derek-thomas/autotrain-falcon-v03-poe-RFA-falcon',\n",
      " 'derek-thomas/autotrain-falcon-v03-poe-FAR-gpt3-5',\n",
      " 'derek-thomas/autotrain-falcon-v03-poe-FAR-falcon',\n",
      " 'derek-thomas/autotrain-falcon-v03-poe-FA']\n",
      "\n",
      "['derek-thomas/falcon-v03-poe-RFA-gpt3-5',\n",
      " 'derek-thomas/falcon-v03-poe-RFA-falcon',\n",
      " 'derek-thomas/falcon-v03-poe-FAR-gpt3-5',\n",
      " 'derek-thomas/falcon-v03-poe-FAR-falcon',\n",
      " 'derek-thomas/falcon-v03-poe-FA']\n"
     ]
    }
   ],
   "source": [
    "from pprint import pprint\n",
    "pprint(autotrain_spaces)\n",
    "print()\n",
    "pprint(autotrain_models)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0040e05b-39c2-4aff-a40e-01577a388eff",
   "metadata": {},
   "source": [
    "<span style=\"color:red; font-size:20px; font-weight:bold;\">\n",
    "WAIT TO RUN THIS UNTIL YOUR SPACES ARE FINISHED TRAINING!\n",
    "</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "de150f086f1c72fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Are you sure you want to delete the space 'derek-thomas/autotrain-falcon-v03-poe-RFA-gpt3-5'? (y/n):  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deleted derek-thomas/autotrain-falcon-v03-poe-RFA-gpt3-5\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Are you sure you want to delete the space 'derek-thomas/autotrain-falcon-v03-poe-RFA-falcon'? (y/n):  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deleted derek-thomas/autotrain-falcon-v03-poe-RFA-falcon\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Are you sure you want to delete the space 'derek-thomas/autotrain-falcon-v03-poe-FAR-gpt3-5'? (y/n):  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deleted derek-thomas/autotrain-falcon-v03-poe-FAR-gpt3-5\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Are you sure you want to delete the space 'derek-thomas/autotrain-falcon-v03-poe-FAR-falcon'? (y/n):  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deleted derek-thomas/autotrain-falcon-v03-poe-FAR-falcon\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Are you sure you want to delete the space 'derek-thomas/autotrain-falcon-v03-poe-FA'? (y/n):  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deleted derek-thomas/autotrain-falcon-v03-poe-FA\n"
     ]
    }
   ],
   "source": [
    "for space in autotrain_spaces:\n",
    "    confirm = input(f\"Are you sure you want to delete the space '{space}'? (y/n): \")\n",
    "    if confirm.lower() == 'y':\n",
    "        api.delete_repo(space, repo_type='space')\n",
    "        print(f\"Deleted {space}\")\n",
    "    else:\n",
    "        print(f\"Skipped {space}\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6aa4788fe8b0297",
   "metadata": {},
   "source": [
    "<span style=\"color:red; font-size:20px; font-weight:bold;\">\n",
    "ONLY RUN THIS IF YOU NEED TO RESTART FROM SCRATCH\n",
    "THIS WILL DELETE YOUR MODELS\n",
    "</span>\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c887e61558785e69",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Are you sure you want to delete the model 'derek-thomas/falcon-v03-poe-RFA-gpt3-5'? (y/n):  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deleted derek-thomas/falcon-v03-poe-RFA-gpt3-5\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Are you sure you want to delete the model 'derek-thomas/falcon-v03-poe-RFA-falcon'? (y/n):  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deleted derek-thomas/falcon-v03-poe-RFA-falcon\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Are you sure you want to delete the model 'derek-thomas/falcon-v03-poe-FAR-gpt3-5'? (y/n):  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deleted derek-thomas/falcon-v03-poe-FAR-gpt3-5\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Are you sure you want to delete the model 'derek-thomas/falcon-v03-poe-FAR-falcon'? (y/n):  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deleted derek-thomas/falcon-v03-poe-FAR-falcon\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Are you sure you want to delete the model 'derek-thomas/falcon-v03-poe-FA'? (y/n):  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deleted derek-thomas/falcon-v03-poe-FA\n"
     ]
    }
   ],
   "source": [
    "for model in autotrain_models:\n",
    "    confirm = input(f\"Are you sure you want to delete the model '{model}'? (y/n): \")\n",
    "    if confirm.lower() == 'y':\n",
    "        api.delete_repo(model, repo_type='model')\n",
    "        print(f\"Deleted {model}\")\n",
    "    else:\n",
    "        print(f\"Skipped {model}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a8a8d4c2-0fb5-438c-9fbf-436144d05543",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Are you sure you want to move the model from 'derek-thomas/falcon-v03-poe-RFA-gpt3-5' to derek-thomas/falcon-v03-poe-RFA-gpt3-5_backup? (y/n):  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Moved derek-thomas/falcon-v03-poe-RFA-gpt3-5 to derek-thomas/falcon-v03-poe-RFA-gpt3-5_backup\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Are you sure you want to move the model from 'derek-thomas/falcon-v03-poe-RFA-falcon' to derek-thomas/falcon-v03-poe-RFA-falcon_backup? (y/n):  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Moved derek-thomas/falcon-v03-poe-RFA-falcon to derek-thomas/falcon-v03-poe-RFA-falcon_backup\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Are you sure you want to move the model from 'derek-thomas/falcon-v03-poe-FAR-gpt3-5' to derek-thomas/falcon-v03-poe-FAR-gpt3-5_backup? (y/n):  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Moved derek-thomas/falcon-v03-poe-FAR-gpt3-5 to derek-thomas/falcon-v03-poe-FAR-gpt3-5_backup\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Are you sure you want to move the model from 'derek-thomas/falcon-v03-poe-FAR-falcon' to derek-thomas/falcon-v03-poe-FAR-falcon_backup? (y/n):  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Moved derek-thomas/falcon-v03-poe-FAR-falcon to derek-thomas/falcon-v03-poe-FAR-falcon_backup\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Are you sure you want to move the model from 'derek-thomas/falcon-v03-poe-FA' to derek-thomas/falcon-v03-poe-FA_backup? (y/n):  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Moved derek-thomas/falcon-v03-poe-FA to derek-thomas/falcon-v03-poe-FA_backup\n"
     ]
    }
   ],
   "source": [
    "from huggingface_hub import move_repo\n",
    "\n",
    "for model in autotrain_models:\n",
    "    user, model_tag = model.split('/')\n",
    "    to = f\"{user}/{model_tag}_backup\"\n",
    "    confirm = input(f\"Are you sure you want to move the model from '{model}' to {to}? (y/n): \")\n",
    "    if confirm.lower() == 'y':\n",
    "        move_repo(from_id=model, to_id=to)\n",
    "        print(f\"Moved {model} to {to}\")\n",
    "    else:\n",
    "        print(f\"Skipped {model}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c2a2c864-2082-4be9-8e28-92fd01833e38",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}