zetavg commited on
Commit
fdddf65
1 Parent(s): 9c6781a

better way to manage JS and CSS

Browse files
LLaMA_LoRA.ipynb CHANGED
@@ -324,9 +324,10 @@
324
  "cell_type": "code",
325
  "source": [
326
  "import gradio as gr\n",
327
- "from llama_lora.llama_lora.ui.main_page import main_page, get_page_title, main_page_custom_css\n",
 
328
  "\n",
329
- "with gr.Blocks(title=get_page_title(), css=main_page_custom_css()) as app:\n",
330
  " main_page()\n",
331
  "\n",
332
  "app.queue(concurrency_count=1).launch(share=True, debug=True, server_name=\"127.0.0.1\")"
 
324
  "cell_type": "code",
325
  "source": [
326
  "import gradio as gr\n",
327
+ "from llama_lora.llama_lora.ui.main_page import main_page, get_page_title\n",
328
+ "from llama_lora.ui.css_styles import get_css_styles\n",
329
  "\n",
330
+ "with gr.Blocks(title=get_page_title(), css=get_css_styles()) as app:\n",
331
  " main_page()\n",
332
  "\n",
333
  "app.queue(concurrency_count=1).launch(share=True, debug=True, server_name=\"127.0.0.1\")"
app.py CHANGED
@@ -10,8 +10,9 @@ from llama_lora.globals import initialize_global
10
  from llama_lora.models import prepare_base_model
11
  from llama_lora.utils.data import init_data_dir
12
  from llama_lora.ui.main_page import (
13
- main_page, get_page_title, main_page_custom_css
14
  )
 
15
 
16
 
17
  def main(
@@ -97,7 +98,7 @@ def main(
97
  if (not skip_loading_base_model) and (not Config.ui_dev_mode):
98
  prepare_base_model(Config.default_base_model_name)
99
 
100
- with gr.Blocks(title=get_page_title(), css=main_page_custom_css()) as demo:
101
  main_page()
102
 
103
  demo.queue(concurrency_count=1).launch(
 
10
  from llama_lora.models import prepare_base_model
11
  from llama_lora.utils.data import init_data_dir
12
  from llama_lora.ui.main_page import (
13
+ main_page, get_page_title
14
  )
15
+ from llama_lora.ui.css_styles import get_css_styles
16
 
17
 
18
  def main(
 
98
  if (not skip_loading_base_model) and (not Config.ui_dev_mode):
99
  prepare_base_model(Config.default_base_model_name)
100
 
101
+ with gr.Blocks(title=get_page_title(), css=get_css_styles()) as demo:
102
  main_page()
103
 
104
  demo.queue(concurrency_count=1).launch(
llama_lora/ui/css_styles.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ css_styles = []
2
+
3
+
4
+ def get_css_styles():
5
+ global css_styles
6
+ return "\n".join(css_styles)
7
+
8
+
9
+ def register_css_style(name, style):
10
+ global css_styles
11
+ css_styles.append(style)
llama_lora/ui/finetune/__init__.py ADDED
File without changes
llama_lora/ui/{finetune_ui.py → finetune/finetune_ui.py} RENAMED
@@ -11,18 +11,22 @@ from random_word import RandomWords
11
  from transformers import TrainerCallback
12
  from huggingface_hub import try_to_load_from_cache, snapshot_download
13
 
14
- from ..config import Config
15
- from ..globals import Global
16
- from ..models import (
17
  get_new_base_model, get_tokenizer,
18
  clear_cache, unload_models)
19
- from ..utils.data import (
20
  get_available_template_names,
21
  get_available_dataset_names,
22
  get_dataset_content,
23
  get_available_lora_model_names
24
  )
25
- from ..utils.prompter import Prompter
 
 
 
 
26
 
27
 
28
  def random_hyphenated_word():
@@ -1284,193 +1288,7 @@ def finetune_ui():
1284
  stop_timeoutable_btn.click(
1285
  fn=None, inputs=None, outputs=None, cancels=things_that_might_timeout)
1286
 
1287
- finetune_ui_blocks.load(_js="""
1288
- function finetune_ui_blocks_js() {
1289
- // Auto load options
1290
- setTimeout(function () {
1291
- document.getElementById('finetune_reload_selections_button').click();
1292
- }, 100);
1293
-
1294
- // Add tooltips
1295
- setTimeout(function () {
1296
- tippy('#finetune_reload_selections_button', {
1297
- placement: 'bottom-end',
1298
- delay: [500, 0],
1299
- animation: 'scale-subtle',
1300
- content: 'Press to reload options.',
1301
- });
1302
-
1303
- tippy('#finetune_template', {
1304
- placement: 'bottom-start',
1305
- delay: [500, 0],
1306
- animation: 'scale-subtle',
1307
- content:
1308
- 'Select a template for your prompt. <br />To see how the selected template work, select the "Preview" tab and then check "Show actual prompt". <br />Templates are loaded from the "templates" folder of your data directory.',
1309
- allowHTML: true,
1310
- });
1311
-
1312
- tippy('#finetune_load_dataset_from', {
1313
- placement: 'bottom-start',
1314
- delay: [500, 0],
1315
- animation: 'scale-subtle',
1316
- content:
1317
- '<strong>Text Input</strong>: Paste the dataset directly in the UI.<br/><strong>Data Dir</strong>: Select a dataset in the data directory.',
1318
- allowHTML: true,
1319
- });
1320
-
1321
- tippy('#finetune_dataset_preview_show_actual_prompt', {
1322
- placement: 'bottom-start',
1323
- delay: [500, 0],
1324
- animation: 'scale-subtle',
1325
- content:
1326
- 'Check to show the prompt that will be feed to the language model.',
1327
- });
1328
-
1329
- tippy('#dataset_plain_text_input_variables_separator', {
1330
- placement: 'bottom',
1331
- delay: [500, 0],
1332
- animation: 'scale-subtle',
1333
- content:
1334
- 'Define a separator to separate input variables. Use "\\\\n" for new lines.',
1335
- });
1336
-
1337
- tippy('#dataset_plain_text_input_and_output_separator', {
1338
- placement: 'bottom',
1339
- delay: [500, 0],
1340
- animation: 'scale-subtle',
1341
- content:
1342
- 'Define a separator to separate the input (prompt) and the output (completion). Use "\\\\n" for new lines.',
1343
- });
1344
-
1345
- tippy('#dataset_plain_text_data_separator', {
1346
- placement: 'bottom',
1347
- delay: [500, 0],
1348
- animation: 'scale-subtle',
1349
- content:
1350
- 'Define a separator to separate different rows of the train data. Use "\\\\n" for new lines.',
1351
- });
1352
-
1353
- tippy('#finetune_dataset_text_load_sample_button', {
1354
- placement: 'bottom-start',
1355
- delay: [500, 0],
1356
- animation: 'scale-subtle',
1357
- content:
1358
- 'Press to load a sample dataset of the current selected format into the textbox.',
1359
- });
1360
-
1361
- tippy('#finetune_evaluate_data_count', {
1362
- placement: 'bottom',
1363
- delay: [500, 0],
1364
- animation: 'scale-subtle',
1365
- content:
1366
- 'While setting a value larger than 0, the checkpoint with the lowest loss on the evaluation data will be saved as the final trained model, thereby helping to prevent overfitting.',
1367
- });
1368
-
1369
- tippy('#finetune_save_total_limit', {
1370
- placement: 'bottom',
1371
- delay: [500, 0],
1372
- animation: 'scale-subtle',
1373
- content:
1374
- 'Total amount of checkpoints to preserve. Older checkpoints will be deleted.',
1375
- });
1376
- tippy('#finetune_save_steps', {
1377
- placement: 'bottom',
1378
- delay: [500, 0],
1379
- animation: 'scale-subtle',
1380
- content:
1381
- 'Number of updates steps before two checkpoint saves.',
1382
- });
1383
- tippy('#finetune_logging_steps', {
1384
- placement: 'bottom',
1385
- delay: [500, 0],
1386
- animation: 'scale-subtle',
1387
- content:
1388
- 'Number of update steps between two logs.',
1389
- });
1390
-
1391
- tippy('#finetune_model_name', {
1392
- placement: 'bottom',
1393
- delay: [500, 0],
1394
- animation: 'scale-subtle',
1395
- content:
1396
- 'The name of the new LoRA model. Must be unique.',
1397
- });
1398
-
1399
- tippy('#finetune_continue_from_model', {
1400
- placement: 'bottom',
1401
- delay: [500, 0],
1402
- animation: 'scale-subtle',
1403
- content:
1404
- 'Select a LoRA model to train a new model on top of that model. You can also type in a model name on Hugging Face Hub, such as <code>tloen/alpaca-lora-7b</code>.<br /><br />💡 To reload the training parameters of one of your previously trained models, select it here and click the <code>Load training parameters from selected model</code> button, then un-select it.',
1405
- allowHTML: true,
1406
- });
1407
-
1408
- tippy('#finetune_continue_from_checkpoint', {
1409
- placement: 'bottom',
1410
- delay: [500, 0],
1411
- animation: 'scale-subtle',
1412
- content:
1413
- 'If a checkpoint is selected, training will resume from that specific checkpoint, bypassing any previously completed steps up to the checkpoint\\'s moment. <br /><br />💡 Use this option to resume an unfinished training session. Remember to click the <code>Load training parameters from selected model</code> button and select the same dataset for training.',
1414
- allowHTML: true,
1415
- });
1416
- }, 100);
1417
-
1418
- // Show/hide start and stop button base on the state.
1419
- setTimeout(function () {
1420
- // Make the '#finetune_training_status > .wrap' element appear
1421
- if (!document.querySelector('#finetune_training_status > .wrap')) {
1422
- document.getElementById('finetune_confirm_stop_btn').click();
1423
- }
1424
-
1425
- setTimeout(function () {
1426
- let resetStopButtonTimer;
1427
- document
1428
- .getElementById('finetune_stop_btn')
1429
- .addEventListener('click', function () {
1430
- if (resetStopButtonTimer) clearTimeout(resetStopButtonTimer);
1431
- resetStopButtonTimer = setTimeout(function () {
1432
- document.getElementById('finetune_stop_btn').style.display = 'block';
1433
- document.getElementById('finetune_confirm_stop_btn').style.display =
1434
- 'none';
1435
- }, 5000);
1436
- document.getElementById('finetune_confirm_stop_btn').style['pointer-events'] =
1437
- 'none';
1438
- setTimeout(function () {
1439
- document.getElementById('finetune_confirm_stop_btn').style['pointer-events'] =
1440
- 'inherit';
1441
- }, 300);
1442
- document.getElementById('finetune_stop_btn').style.display = 'none';
1443
- document.getElementById('finetune_confirm_stop_btn').style.display =
1444
- 'block';
1445
- });
1446
- const output_wrap_element = document.querySelector(
1447
- '#finetune_training_status > .wrap'
1448
- );
1449
- function handle_output_wrap_element_class_change() {
1450
- if (Array.from(output_wrap_element.classList).includes('hide')) {
1451
- if (resetStopButtonTimer) clearTimeout(resetStopButtonTimer);
1452
- document.getElementById('finetune_start_btn').style.display = 'block';
1453
- document.getElementById('finetune_stop_btn').style.display = 'none';
1454
- document.getElementById('finetune_confirm_stop_btn').style.display =
1455
- 'none';
1456
- } else {
1457
- document.getElementById('finetune_start_btn').style.display = 'none';
1458
- document.getElementById('finetune_stop_btn').style.display = 'block';
1459
- document.getElementById('finetune_confirm_stop_btn').style.display =
1460
- 'none';
1461
- }
1462
- }
1463
- new MutationObserver(function (mutationsList, observer) {
1464
- handle_output_wrap_element_class_change();
1465
- }).observe(output_wrap_element, {
1466
- attributes: true,
1467
- attributeFilter: ['class'],
1468
- });
1469
- handle_output_wrap_element_class_change();
1470
- }, 500);
1471
- }, 0);
1472
- }
1473
- """)
1474
 
1475
 
1476
  def get_val_from_arr(arr, index, default=None):
 
11
  from transformers import TrainerCallback
12
  from huggingface_hub import try_to_load_from_cache, snapshot_download
13
 
14
+ from ...config import Config
15
+ from ...globals import Global
16
+ from ...models import (
17
  get_new_base_model, get_tokenizer,
18
  clear_cache, unload_models)
19
+ from ...utils.data import (
20
  get_available_template_names,
21
  get_available_dataset_names,
22
  get_dataset_content,
23
  get_available_lora_model_names
24
  )
25
+ from ...utils.prompter import Prompter
26
+ from ...utils.relative_read_file import relative_read_file
27
+ from ..css_styles import register_css_style
28
+
29
+ register_css_style('finetune', relative_read_file(__file__, "style.css"))
30
 
31
 
32
  def random_hyphenated_word():
 
1288
  stop_timeoutable_btn.click(
1289
  fn=None, inputs=None, outputs=None, cancels=things_that_might_timeout)
1290
 
1291
+ finetune_ui_blocks.load(_js=relative_read_file(__file__, "script.js"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1292
 
1293
 
1294
  def get_val_from_arr(arr, index, default=None):
llama_lora/ui/finetune/script.js ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function finetune_ui_blocks_js() {
2
+ // Auto load options
3
+ setTimeout(function () {
4
+ document.getElementById('finetune_reload_selections_button').click();
5
+ }, 100);
6
+
7
+ // Add tooltips
8
+ setTimeout(function () {
9
+ tippy('#finetune_reload_selections_button', {
10
+ placement: 'bottom-end',
11
+ delay: [500, 0],
12
+ animation: 'scale-subtle',
13
+ content: 'Press to reload options.',
14
+ });
15
+
16
+ tippy('#finetune_template', {
17
+ placement: 'bottom-start',
18
+ delay: [500, 0],
19
+ animation: 'scale-subtle',
20
+ content:
21
+ 'Select a template for your prompt. <br />To see how the selected template work, select the "Preview" tab and then check "Show actual prompt". <br />Templates are loaded from the "templates" folder of your data directory.',
22
+ allowHTML: true,
23
+ });
24
+
25
+ tippy('#finetune_load_dataset_from', {
26
+ placement: 'bottom-start',
27
+ delay: [500, 0],
28
+ animation: 'scale-subtle',
29
+ content:
30
+ '<strong>Text Input</strong>: Paste the dataset directly in the UI.<br/><strong>Data Dir</strong>: Select a dataset in the data directory.',
31
+ allowHTML: true,
32
+ });
33
+
34
+ tippy('#finetune_dataset_preview_show_actual_prompt', {
35
+ placement: 'bottom-start',
36
+ delay: [500, 0],
37
+ animation: 'scale-subtle',
38
+ content:
39
+ 'Check to show the prompt that will be feed to the language model.',
40
+ });
41
+
42
+ tippy('#dataset_plain_text_input_variables_separator', {
43
+ placement: 'bottom',
44
+ delay: [500, 0],
45
+ animation: 'scale-subtle',
46
+ content:
47
+ 'Define a separator to separate input variables. Use "\\n" for new lines.',
48
+ });
49
+
50
+ tippy('#dataset_plain_text_input_and_output_separator', {
51
+ placement: 'bottom',
52
+ delay: [500, 0],
53
+ animation: 'scale-subtle',
54
+ content:
55
+ 'Define a separator to separate the input (prompt) and the output (completion). Use "\\n" for new lines.',
56
+ });
57
+
58
+ tippy('#dataset_plain_text_data_separator', {
59
+ placement: 'bottom',
60
+ delay: [500, 0],
61
+ animation: 'scale-subtle',
62
+ content:
63
+ 'Define a separator to separate different rows of the train data. Use "\\n" for new lines.',
64
+ });
65
+
66
+ tippy('#finetune_dataset_text_load_sample_button', {
67
+ placement: 'bottom-start',
68
+ delay: [500, 0],
69
+ animation: 'scale-subtle',
70
+ content:
71
+ 'Press to load a sample dataset of the current selected format into the textbox.',
72
+ });
73
+
74
+ tippy('#finetune_evaluate_data_count', {
75
+ placement: 'bottom',
76
+ delay: [500, 0],
77
+ animation: 'scale-subtle',
78
+ content:
79
+ 'While setting a value larger than 0, the checkpoint with the lowest loss on the evaluation data will be saved as the final trained model, thereby helping to prevent overfitting.',
80
+ });
81
+
82
+ tippy('#finetune_save_total_limit', {
83
+ placement: 'bottom',
84
+ delay: [500, 0],
85
+ animation: 'scale-subtle',
86
+ content:
87
+ 'Total amount of checkpoints to preserve. Older checkpoints will be deleted.',
88
+ });
89
+ tippy('#finetune_save_steps', {
90
+ placement: 'bottom',
91
+ delay: [500, 0],
92
+ animation: 'scale-subtle',
93
+ content:
94
+ 'Number of updates steps before two checkpoint saves.',
95
+ });
96
+ tippy('#finetune_logging_steps', {
97
+ placement: 'bottom',
98
+ delay: [500, 0],
99
+ animation: 'scale-subtle',
100
+ content:
101
+ 'Number of update steps between two logs.',
102
+ });
103
+
104
+ tippy('#finetune_model_name', {
105
+ placement: 'bottom',
106
+ delay: [500, 0],
107
+ animation: 'scale-subtle',
108
+ content:
109
+ 'The name of the new LoRA model. Must be unique.',
110
+ });
111
+
112
+ tippy('#finetune_continue_from_model', {
113
+ placement: 'bottom',
114
+ delay: [500, 0],
115
+ animation: 'scale-subtle',
116
+ content:
117
+ 'Select a LoRA model to train a new model on top of that model. You can also type in a model name on Hugging Face Hub, such as <code>tloen/alpaca-lora-7b</code>.<br /><br />💡 To reload the training parameters of one of your previously trained models, select it here and click the <code>Load training parameters from selected model</code> button, then un-select it.',
118
+ allowHTML: true,
119
+ });
120
+
121
+ tippy('#finetune_continue_from_checkpoint', {
122
+ placement: 'bottom',
123
+ delay: [500, 0],
124
+ animation: 'scale-subtle',
125
+ content:
126
+ 'If a checkpoint is selected, training will resume from that specific checkpoint, bypassing any previously completed steps up to the checkpoint\'s moment. <br /><br />💡 Use this option to resume an unfinished training session. Remember to click the <code>Load training parameters from selected model</code> button and select the same dataset for training.',
127
+ allowHTML: true,
128
+ });
129
+ }, 100);
130
+
131
+ // Show/hide start and stop button base on the state.
132
+ setTimeout(function () {
133
+ // Make the '#finetune_training_status > .wrap' element appear
134
+ if (!document.querySelector('#finetune_training_status > .wrap')) {
135
+ document.getElementById('finetune_confirm_stop_btn').click();
136
+ }
137
+
138
+ setTimeout(function () {
139
+ let resetStopButtonTimer;
140
+ document
141
+ .getElementById('finetune_stop_btn')
142
+ .addEventListener('click', function () {
143
+ if (resetStopButtonTimer) clearTimeout(resetStopButtonTimer);
144
+ resetStopButtonTimer = setTimeout(function () {
145
+ document.getElementById('finetune_stop_btn').style.display = 'block';
146
+ document.getElementById('finetune_confirm_stop_btn').style.display =
147
+ 'none';
148
+ }, 5000);
149
+ document.getElementById('finetune_confirm_stop_btn').style['pointer-events'] =
150
+ 'none';
151
+ setTimeout(function () {
152
+ document.getElementById('finetune_confirm_stop_btn').style['pointer-events'] =
153
+ 'inherit';
154
+ }, 300);
155
+ document.getElementById('finetune_stop_btn').style.display = 'none';
156
+ document.getElementById('finetune_confirm_stop_btn').style.display =
157
+ 'block';
158
+ });
159
+ const output_wrap_element = document.querySelector(
160
+ '#finetune_training_status > .wrap'
161
+ );
162
+ function handle_output_wrap_element_class_change() {
163
+ if (Array.from(output_wrap_element.classList).includes('hide')) {
164
+ if (resetStopButtonTimer) clearTimeout(resetStopButtonTimer);
165
+ document.getElementById('finetune_start_btn').style.display = 'block';
166
+ document.getElementById('finetune_stop_btn').style.display = 'none';
167
+ document.getElementById('finetune_confirm_stop_btn').style.display =
168
+ 'none';
169
+ } else {
170
+ document.getElementById('finetune_start_btn').style.display = 'none';
171
+ document.getElementById('finetune_stop_btn').style.display = 'block';
172
+ document.getElementById('finetune_confirm_stop_btn').style.display =
173
+ 'none';
174
+ }
175
+ }
176
+ new MutationObserver(function (mutationsList, observer) {
177
+ handle_output_wrap_element_class_change();
178
+ }).observe(output_wrap_element, {
179
+ attributes: true,
180
+ attributeFilter: ['class'],
181
+ });
182
+ handle_output_wrap_element_class_change();
183
+ }, 500);
184
+ }, 0);
185
+ }
llama_lora/ui/finetune/style.css ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #finetune_dataset_text_load_sample_button {
2
+ margin: -4px 12px 8px;
3
+ }
4
+
5
+ #finetune_reload_selections_button {
6
+ position: absolute;
7
+ top: 0;
8
+ right: 0;
9
+ margin: 16px;
10
+ margin-bottom: auto;
11
+ height: 42px !important;
12
+ min-width: 42px !important;
13
+ width: 42px !important;
14
+ z-index: 1;
15
+ }
16
+
17
+ #finetune_dataset_from_data_dir {
18
+ border: 0;
19
+ box-shadow: none;
20
+ }
21
+
22
+ #finetune_ui_content > .tabs > .tab-nav::before {
23
+ content: "Training Dataset:";
24
+ display: flex;
25
+ justify-content: center;
26
+ align-items: center;
27
+ padding-right: 12px;
28
+ padding-left: 8px;
29
+ }
30
+
31
+ #finetune_template,
32
+ #finetune_template + * {
33
+ border: 0;
34
+ box-shadow: none;
35
+ }
36
+
37
+ #finetune_dataset_text_input_group .form {
38
+ border: 0;
39
+ box-shadow: none;
40
+ padding: 0;
41
+ }
42
+
43
+ #finetune_dataset_text_input_textbox > .wrap:last-of-type {
44
+ margin-top: -20px;
45
+ }
46
+
47
+ #finetune_dataset_plain_text_separators_group * {
48
+ font-size: 0.8rem;
49
+ }
50
+ #finetune_dataset_plain_text_separators_group textarea {
51
+ height: auto !important;
52
+ }
53
+ #finetune_dataset_plain_text_separators_group > .form {
54
+ gap: 0 !important;
55
+ }
56
+
57
+ #finetune_dataset_from_text_message p,
58
+ #finetune_dataset_from_text_message + * p {
59
+ font-size: 80%;
60
+ }
61
+ #finetune_dataset_from_text_message,
62
+ #finetune_dataset_from_text_message *,
63
+ #finetune_dataset_from_text_message + *,
64
+ #finetune_dataset_from_text_message + * * {
65
+ display: inline;
66
+ }
67
+
68
+
69
+ #finetune_dataset_from_data_dir_message,
70
+ #finetune_dataset_from_data_dir_message * {
71
+ min-height: 0 !important;
72
+ }
73
+ #finetune_dataset_from_data_dir_message {
74
+ margin: -20px 24px 0;
75
+ font-size: 0.8rem;
76
+ }
77
+
78
+ #finetune_dataset_from_text_message > .wrap > *:first-child,
79
+ #finetune_dataset_from_data_dir_message > .wrap > *:first-child {
80
+ display: none;
81
+ }
82
+ #finetune_dataset_from_data_dir_message > .wrap {
83
+ top: -18px;
84
+ }
85
+ #finetune_dataset_from_text_message > .wrap svg,
86
+ #finetune_dataset_from_data_dir_message > .wrap svg {
87
+ margin: -32px -16px;
88
+ }
89
+
90
+ #finetune_continue_from_model_box {
91
+ /* padding: 0; */
92
+ }
93
+ #finetune_continue_from_model_box .block {
94
+ border: 0;
95
+ box-shadow: none;
96
+ padding: 0;
97
+ }
98
+ #finetune_continue_from_model_box > * {
99
+ /* gap: 0; */
100
+ }
101
+ #finetune_continue_from_model_box button {
102
+ margin-top: 16px;
103
+ }
104
+ #finetune_continue_from_model {
105
+ flex-grow: 2;
106
+ }
107
+
108
+ .finetune_dataset_error_message {
109
+ color: var(--error-text-color) !important;
110
+ }
111
+
112
+ #finetune_dataset_preview_info_message {
113
+ align-items: flex-end;
114
+ flex-direction: row;
115
+ display: flex;
116
+ margin-bottom: -4px;
117
+ }
118
+
119
+ #finetune_dataset_preview td {
120
+ white-space: pre-wrap;
121
+ }
122
+
123
+ /*
124
+ #finetune_dataset_preview {
125
+ max-height: 100vh;
126
+ overflow: auto;
127
+ border: var(--block-border-width) solid var(--border-color-primary);
128
+ border-radius: var(--radius-lg);
129
+ }
130
+ #finetune_dataset_preview .table-wrap {
131
+ border: 0 !important;
132
+ }
133
+ */
134
+
135
+ #finetune_max_seq_length {
136
+ flex: 2;
137
+ }
138
+
139
+ #finetune_lora_target_modules_box,
140
+ #finetune_lora_target_modules_box + #finetune_lora_modules_to_save_box {
141
+ margin-top: calc((var(--layout-gap) + 8px) * -1);
142
+ flex-grow: 0 !important;
143
+ }
144
+ #finetune_lora_target_modules_box > .form,
145
+ #finetune_lora_target_modules_box + #finetune_lora_modules_to_save_box > .form {
146
+ padding-top: calc((var(--layout-gap) + 8px) / 3);
147
+ border-top: 0;
148
+ border-top-left-radius: 0;
149
+ border-top-right-radius: 0;
150
+ background: var(--block-background-fill);
151
+ position: relative;
152
+ }
153
+ #finetune_lora_target_modules_box > .form::before,
154
+ #finetune_lora_target_modules_box + #finetune_lora_modules_to_save_box > .form::before {
155
+ content: "";
156
+ display: block;
157
+ position: absolute;
158
+ top: calc((var(--layout-gap) + 8px) / 3);
159
+ left: 0;
160
+ right: 0;
161
+ height: 1px;
162
+ z-index: 1;
163
+ background: var(--block-border-color);
164
+ }
165
+ #finetune_lora_target_modules_add_box,
166
+ #finetune_lora_modules_to_save_add_box {
167
+ margin-top: -24px;
168
+ padding-top: 8px;
169
+ border-top-left-radius: 0;
170
+ border-top-right-radius: 0;
171
+ border-top: 0;
172
+ }
173
+ #finetune_lora_target_modules_add_box > * > .form,
174
+ #finetune_lora_modules_to_save_add_box > * > .form {
175
+ border: 0;
176
+ box-shadow: none;
177
+ }
178
+ #finetune_lora_target_modules_add,
179
+ #finetune_lora_modules_to_save_add {
180
+ padding: 0;
181
+ }
182
+ #finetune_lora_target_modules_add input,
183
+ #finetune_lora_modules_to_save_add input {
184
+ padding: 4px 8px;
185
+ }
186
+ #finetune_lora_target_modules_add_btn,
187
+ #finetune_lora_modules_to_save_add_btn {
188
+ min-width: 60px;
189
+ }
190
+
191
+ #finetune_save_total_limit,
192
+ #finetune_save_steps,
193
+ #finetune_logging_steps {
194
+ min-width: min(120px,100%) !important;
195
+ padding-top: 4px;
196
+ }
197
+ #finetune_save_total_limit span,
198
+ #finetune_save_steps span,
199
+ #finetune_logging_steps span {
200
+ font-size: 12px;
201
+ margin-bottom: 5px;
202
+ }
203
+ #finetune_save_total_limit input,
204
+ #finetune_save_steps input,
205
+ #finetune_logging_steps input {
206
+ padding: 4px 8px;
207
+ }
208
+
209
+ #finetune_advanced_options_checkboxes > * > * {
210
+ min-width: auto;
211
+ }
212
+
213
+ #finetune_log_and_save_options_group_container {
214
+ flex-grow: 0 !important;
215
+ }
216
+ #finetune_model_name_group {
217
+ flex-grow: 0 !important;
218
+ }
219
+
220
+ #finetune_eval_data_group {
221
+ flex-grow: 0 !important;
222
+ }
223
+
224
+ #finetune_additional_training_arguments_box > .form,
225
+ #finetune_additional_lora_config_box > .form {
226
+ border: 0;
227
+ background: transparent;
228
+ }
229
+ #finetune_additional_training_arguments_textbox_for_label_display,
230
+ #finetune_additional_lora_config_textbox_for_label_display {
231
+ padding: 0;
232
+ margin-bottom: -10px;
233
+ background: transparent;
234
+ }
235
+ #finetune_additional_training_arguments_textbox_for_label_display textarea,
236
+ #finetune_additional_lora_config_textbox_for_label_display textarea {
237
+ display: none;
238
+ }
239
+
240
+ /* in case if there's too many logs on the previous run and made the box too high */
241
+ #finetune_training_status:has(.wrap:not(.hide)) {
242
+ max-height: 160px;
243
+ height: 160px;
244
+ }
llama_lora/ui/main_page.py CHANGED
@@ -4,10 +4,11 @@ from ..config import Config
4
  from ..globals import Global
5
 
6
  from .inference_ui import inference_ui
7
- from .finetune_ui import finetune_ui
8
  from .tokenizer_ui import tokenizer_ui
9
 
10
  from .js_scripts import popperjs_core_code, tippy_js_code
 
11
 
12
 
13
  def main_page():
@@ -15,7 +16,7 @@ def main_page():
15
 
16
  with gr.Blocks(
17
  title=title,
18
- css=main_page_custom_css(),
19
  ) as main_page_blocks:
20
  with gr.Column(elem_id="main_page_content"):
21
  with gr.Row():
@@ -533,10 +534,6 @@ def main_page_custom_css():
533
  margin-top: -8px;
534
  }
535
 
536
- #finetune_dataset_text_load_sample_button {
537
- margin: -4px 12px 8px;
538
- }
539
-
540
  #inference_preview_prompt_container .label-wrap {
541
  user-select: none;
542
  }
@@ -565,23 +562,6 @@ def main_page_custom_css():
565
  opacity: 0.8;
566
  }
567
 
568
- #finetune_reload_selections_button {
569
- position: absolute;
570
- top: 0;
571
- right: 0;
572
- margin: 16px;
573
- margin-bottom: auto;
574
- height: 42px !important;
575
- min-width: 42px !important;
576
- width: 42px !important;
577
- z-index: 1;
578
- }
579
-
580
- #finetune_dataset_from_data_dir {
581
- border: 0;
582
- box-shadow: none;
583
- }
584
-
585
  @media screen and (min-width: 640px) {
586
  #inference_lora_model, #inference_lora_model_group,
587
  #finetune_template {
@@ -626,224 +606,6 @@ def main_page_custom_css():
626
  }
627
  }
628
 
629
- #finetune_ui_content > .tabs > .tab-nav::before {
630
- content: "Training Dataset:";
631
- display: flex;
632
- justify-content: center;
633
- align-items: center;
634
- padding-right: 12px;
635
- padding-left: 8px;
636
- }
637
-
638
- #finetune_template,
639
- #finetune_template + * {
640
- border: 0;
641
- box-shadow: none;
642
- }
643
-
644
- #finetune_dataset_text_input_group .form {
645
- border: 0;
646
- box-shadow: none;
647
- padding: 0;
648
- }
649
-
650
- #finetune_dataset_text_input_textbox > .wrap:last-of-type {
651
- margin-top: -20px;
652
- }
653
-
654
- #finetune_dataset_plain_text_separators_group * {
655
- font-size: 0.8rem;
656
- }
657
- #finetune_dataset_plain_text_separators_group textarea {
658
- height: auto !important;
659
- }
660
- #finetune_dataset_plain_text_separators_group > .form {
661
- gap: 0 !important;
662
- }
663
-
664
- #finetune_dataset_from_text_message p,
665
- #finetune_dataset_from_text_message + * p {
666
- font-size: 80%;
667
- }
668
- #finetune_dataset_from_text_message,
669
- #finetune_dataset_from_text_message *,
670
- #finetune_dataset_from_text_message + *,
671
- #finetune_dataset_from_text_message + * * {
672
- display: inline;
673
- }
674
-
675
-
676
- #finetune_dataset_from_data_dir_message,
677
- #finetune_dataset_from_data_dir_message * {
678
- min-height: 0 !important;
679
- }
680
- #finetune_dataset_from_data_dir_message {
681
- margin: -20px 24px 0;
682
- font-size: 0.8rem;
683
- }
684
-
685
- #finetune_dataset_from_text_message > .wrap > *:first-child,
686
- #finetune_dataset_from_data_dir_message > .wrap > *:first-child {
687
- display: none;
688
- }
689
- #finetune_dataset_from_data_dir_message > .wrap {
690
- top: -18px;
691
- }
692
- #finetune_dataset_from_text_message > .wrap svg,
693
- #finetune_dataset_from_data_dir_message > .wrap svg {
694
- margin: -32px -16px;
695
- }
696
-
697
- #finetune_continue_from_model_box {
698
- /* padding: 0; */
699
- }
700
- #finetune_continue_from_model_box .block {
701
- border: 0;
702
- box-shadow: none;
703
- padding: 0;
704
- }
705
- #finetune_continue_from_model_box > * {
706
- /* gap: 0; */
707
- }
708
- #finetune_continue_from_model_box button {
709
- margin-top: 16px;
710
- }
711
- #finetune_continue_from_model {
712
- flex-grow: 2;
713
- }
714
-
715
- .finetune_dataset_error_message {
716
- color: var(--error-text-color) !important;
717
- }
718
-
719
- #finetune_dataset_preview_info_message {
720
- align-items: flex-end;
721
- flex-direction: row;
722
- display: flex;
723
- margin-bottom: -4px;
724
- }
725
-
726
- #finetune_dataset_preview td {
727
- white-space: pre-wrap;
728
- }
729
-
730
- /*
731
- #finetune_dataset_preview {
732
- max-height: 100vh;
733
- overflow: auto;
734
- border: var(--block-border-width) solid var(--border-color-primary);
735
- border-radius: var(--radius-lg);
736
- }
737
- #finetune_dataset_preview .table-wrap {
738
- border: 0 !important;
739
- }
740
- */
741
-
742
- #finetune_max_seq_length {
743
- flex: 2;
744
- }
745
-
746
- #finetune_lora_target_modules_box,
747
- #finetune_lora_target_modules_box + #finetune_lora_modules_to_save_box {
748
- margin-top: calc((var(--layout-gap) + 8px) * -1);
749
- flex-grow: 0 !important;
750
- }
751
- #finetune_lora_target_modules_box > .form,
752
- #finetune_lora_target_modules_box + #finetune_lora_modules_to_save_box > .form {
753
- padding-top: calc((var(--layout-gap) + 8px) / 3);
754
- border-top: 0;
755
- border-top-left-radius: 0;
756
- border-top-right-radius: 0;
757
- background: var(--block-background-fill);
758
- position: relative;
759
- }
760
- #finetune_lora_target_modules_box > .form::before,
761
- #finetune_lora_target_modules_box + #finetune_lora_modules_to_save_box > .form::before {
762
- content: "";
763
- display: block;
764
- position: absolute;
765
- top: calc((var(--layout-gap) + 8px) / 3);
766
- left: 0;
767
- right: 0;
768
- height: 1px;
769
- z-index: 1;
770
- background: var(--block-border-color);
771
- }
772
- #finetune_lora_target_modules_add_box,
773
- #finetune_lora_modules_to_save_add_box {
774
- margin-top: -24px;
775
- padding-top: 8px;
776
- border-top-left-radius: 0;
777
- border-top-right-radius: 0;
778
- border-top: 0;
779
- }
780
- #finetune_lora_target_modules_add_box > * > .form,
781
- #finetune_lora_modules_to_save_add_box > * > .form {
782
- border: 0;
783
- box-shadow: none;
784
- }
785
- #finetune_lora_target_modules_add,
786
- #finetune_lora_modules_to_save_add {
787
- padding: 0;
788
- }
789
- #finetune_lora_target_modules_add input,
790
- #finetune_lora_modules_to_save_add input {
791
- padding: 4px 8px;
792
- }
793
- #finetune_lora_target_modules_add_btn,
794
- #finetune_lora_modules_to_save_add_btn {
795
- min-width: 60px;
796
- }
797
-
798
- #finetune_save_total_limit,
799
- #finetune_save_steps,
800
- #finetune_logging_steps {
801
- min-width: min(120px,100%) !important;
802
- padding-top: 4px;
803
- }
804
- #finetune_save_total_limit span,
805
- #finetune_save_steps span,
806
- #finetune_logging_steps span {
807
- font-size: 12px;
808
- margin-bottom: 5px;
809
- }
810
- #finetune_save_total_limit input,
811
- #finetune_save_steps input,
812
- #finetune_logging_steps input {
813
- padding: 4px 8px;
814
- }
815
-
816
- #finetune_advanced_options_checkboxes > * > * {
817
- min-width: auto;
818
- }
819
-
820
- #finetune_log_and_save_options_group_container {
821
- flex-grow: 0 !important;
822
- }
823
- #finetune_model_name_group {
824
- flex-grow: 0 !important;
825
- }
826
-
827
- #finetune_eval_data_group {
828
- flex-grow: 0 !important;
829
- }
830
-
831
- #finetune_additional_training_arguments_box > .form,
832
- #finetune_additional_lora_config_box > .form {
833
- border: 0;
834
- background: transparent;
835
- }
836
- #finetune_additional_training_arguments_textbox_for_label_display,
837
- #finetune_additional_lora_config_textbox_for_label_display {
838
- padding: 0;
839
- margin-bottom: -10px;
840
- background: transparent;
841
- }
842
- #finetune_additional_training_arguments_textbox_for_label_display textarea,
843
- #finetune_additional_lora_config_textbox_for_label_display textarea {
844
- display: none;
845
- }
846
-
847
  @media screen and (max-width: 392px) {
848
  #inference_lora_model, #inference_lora_model_group, #finetune_template {
849
  border-bottom-left-radius: 0;
@@ -869,12 +631,6 @@ def main_page_custom_css():
869
  overflow: hidden !important;
870
  }
871
 
872
- /* in case if there's too many logs on the previous run and made the box too high */
873
- #finetune_training_status:has(.wrap:not(.hide)) {
874
- max-height: 160px;
875
- height: 160px;
876
- }
877
-
878
  .foot_stop_timeoutable_btn {
879
  align-self: flex-end;
880
  border: 0 !important;
@@ -899,6 +655,9 @@ def main_page_custom_css():
899
  return css
900
 
901
 
 
 
 
902
  def pre_handle_change_base_model(selected_base_model_name):
903
  if Global.base_model_name != selected_base_model_name:
904
  return gr.Column.update(visible=False)
 
4
  from ..globals import Global
5
 
6
  from .inference_ui import inference_ui
7
+ from .finetune.finetune_ui import finetune_ui
8
  from .tokenizer_ui import tokenizer_ui
9
 
10
  from .js_scripts import popperjs_core_code, tippy_js_code
11
+ from .css_styles import get_css_styles, register_css_style
12
 
13
 
14
  def main_page():
 
16
 
17
  with gr.Blocks(
18
  title=title,
19
+ css=get_css_styles(),
20
  ) as main_page_blocks:
21
  with gr.Column(elem_id="main_page_content"):
22
  with gr.Row():
 
534
  margin-top: -8px;
535
  }
536
 
 
 
 
 
537
  #inference_preview_prompt_container .label-wrap {
538
  user-select: none;
539
  }
 
562
  opacity: 0.8;
563
  }
564
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
565
  @media screen and (min-width: 640px) {
566
  #inference_lora_model, #inference_lora_model_group,
567
  #finetune_template {
 
606
  }
607
  }
608
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
609
  @media screen and (max-width: 392px) {
610
  #inference_lora_model, #inference_lora_model_group, #finetune_template {
611
  border-bottom-left-radius: 0;
 
631
  overflow: hidden !important;
632
  }
633
 
 
 
 
 
 
 
634
  .foot_stop_timeoutable_btn {
635
  align-self: flex-end;
636
  border: 0 !important;
 
655
  return css
656
 
657
 
658
+ register_css_style('main', main_page_custom_css())
659
+
660
+
661
  def pre_handle_change_base_model(selected_base_model_name):
662
  if Global.base_model_name != selected_base_model_name:
663
  return gr.Column.update(visible=False)
llama_lora/utils/relative_read_file.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+
4
+ def relative_read_file(base_file, relative_path):
5
+ src_dir = os.path.dirname(os.path.abspath(base_file))
6
+ file_path = os.path.join(src_dir, relative_path)
7
+ with open(file_path, 'r') as f:
8
+ file_contents = f.read()
9
+ return file_contents