Spaces:
Runtime error
Runtime error
zetavg
commited on
Commit
·
fd15ecb
1
Parent(s):
fbc105f
support switching base models
Browse files- LLaMA_LoRA.ipynb +2 -1
- app.py +14 -1
- download_base_model.py +32 -0
- llama_lora/globals.py +2 -0
- llama_lora/models.py +22 -11
- llama_lora/ui/finetune_ui.py +1 -1
- llama_lora/ui/inference_ui.py +44 -6
- llama_lora/ui/main_page.py +147 -20
- lora_models/alpaca-lora-7b/info.json +6 -0
LLaMA_LoRA.ipynb
CHANGED
@@ -289,7 +289,8 @@
|
|
289 |
"\n",
|
290 |
"# Set Configs\n",
|
291 |
"from llama_lora.llama_lora.globals import Global\n",
|
292 |
-
"Global.default_base_model_name = base_model\n",
|
|
|
293 |
"data_dir_realpath = !realpath ./data\n",
|
294 |
"Global.data_dir = data_dir_realpath[0]\n",
|
295 |
"Global.load_8bit = True\n",
|
|
|
289 |
"\n",
|
290 |
"# Set Configs\n",
|
291 |
"from llama_lora.llama_lora.globals import Global\n",
|
292 |
+
"Global.default_base_model_name = Global.base_model_name = base_model\n",
|
293 |
+
"Global.base_model_choices = [base_model]\n",
|
294 |
"data_dir_realpath = !realpath ./data\n",
|
295 |
"Global.data_dir = data_dir_realpath[0]\n",
|
296 |
"Global.load_8bit = True\n",
|
app.py
CHANGED
@@ -14,6 +14,7 @@ from llama_lora.utils.data import init_data_dir
|
|
14 |
def main(
|
15 |
base_model: str = "",
|
16 |
data_dir: str = "",
|
|
|
17 |
# Allows to listen on all interfaces by providing '0.0.0.0'.
|
18 |
server_name: str = "127.0.0.1",
|
19 |
share: bool = False,
|
@@ -29,6 +30,9 @@ def main(
|
|
29 |
|
30 |
:param base_model: (required) The name of the default base model to use.
|
31 |
:param data_dir: (required) The path to the directory to store data.
|
|
|
|
|
|
|
32 |
:param server_name: Allows to listen on all interfaces by providing '0.0.0.0'.
|
33 |
:param share: Create a public Gradio URL.
|
34 |
|
@@ -46,7 +50,16 @@ def main(
|
|
46 |
data_dir
|
47 |
), "Please specify a --data_dir, e.g. --data_dir='./data'"
|
48 |
|
49 |
-
Global.default_base_model_name = base_model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
Global.data_dir = os.path.abspath(data_dir)
|
51 |
Global.load_8bit = load_8bit
|
52 |
|
|
|
14 |
def main(
|
15 |
base_model: str = "",
|
16 |
data_dir: str = "",
|
17 |
+
base_model_choices: str = "",
|
18 |
# Allows to listen on all interfaces by providing '0.0.0.0'.
|
19 |
server_name: str = "127.0.0.1",
|
20 |
share: bool = False,
|
|
|
30 |
|
31 |
:param base_model: (required) The name of the default base model to use.
|
32 |
:param data_dir: (required) The path to the directory to store data.
|
33 |
+
|
34 |
+
:param base_model_choices: Base model selections to display on the UI, seperated by ",". For example: 'decapoda-research/llama-7b-hf,nomic-ai/gpt4all-j'.
|
35 |
+
|
36 |
:param server_name: Allows to listen on all interfaces by providing '0.0.0.0'.
|
37 |
:param share: Create a public Gradio URL.
|
38 |
|
|
|
50 |
data_dir
|
51 |
), "Please specify a --data_dir, e.g. --data_dir='./data'"
|
52 |
|
53 |
+
Global.default_base_model_name = Global.base_model_name = base_model
|
54 |
+
|
55 |
+
if base_model_choices:
|
56 |
+
base_model_choices = base_model_choices.split(',')
|
57 |
+
base_model_choices = [name.strip() for name in base_model_choices]
|
58 |
+
Global.base_model_choices = base_model_choices
|
59 |
+
|
60 |
+
if base_model not in Global.base_model_choices:
|
61 |
+
Global.base_model_choices = [base_model] + Global.base_model_choices
|
62 |
+
|
63 |
Global.data_dir = os.path.abspath(data_dir)
|
64 |
Global.load_8bit = load_8bit
|
65 |
|
download_base_model.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import fire
|
2 |
+
|
3 |
+
from llama_lora.models import get_new_base_model, clear_cache
|
4 |
+
|
5 |
+
|
6 |
+
def main(
|
7 |
+
base_model_names: str = "",
|
8 |
+
):
|
9 |
+
'''
|
10 |
+
Download and cache base models form Hugging Face.
|
11 |
+
|
12 |
+
:param base_model_names: Names of the base model you want to download, seperated by ",". For example: 'decapoda-research/llama-7b-hf,nomic-ai/gpt4all-j'.
|
13 |
+
'''
|
14 |
+
|
15 |
+
assert (
|
16 |
+
base_model_names
|
17 |
+
), "Please specify --base_model_names, e.g. --base_model_names='decapoda-research/llama-7b-hf,nomic-ai/gpt4all-j'"
|
18 |
+
|
19 |
+
base_model_names = base_model_names.split(',')
|
20 |
+
base_model_names = [name.strip() for name in base_model_names]
|
21 |
+
|
22 |
+
print(f"Base models: {', '.join(base_model_names)}.")
|
23 |
+
|
24 |
+
for name in base_model_names:
|
25 |
+
print(f"Preparing {name}...")
|
26 |
+
get_new_base_model(name)
|
27 |
+
clear_cache()
|
28 |
+
|
29 |
+
print("Done.")
|
30 |
+
|
31 |
+
if __name__ == "__main__":
|
32 |
+
fire.Fire(main)
|
llama_lora/globals.py
CHANGED
@@ -17,6 +17,8 @@ class Global:
|
|
17 |
load_8bit: bool = False
|
18 |
|
19 |
default_base_model_name: str = ""
|
|
|
|
|
20 |
|
21 |
# Functions
|
22 |
train_fn: Any = train
|
|
|
17 |
load_8bit: bool = False
|
18 |
|
19 |
default_base_model_name: str = ""
|
20 |
+
base_model_name: str = ""
|
21 |
+
base_model_choices: List[str] = []
|
22 |
|
23 |
# Functions
|
24 |
train_fn: Any = train
|
llama_lora/models.py
CHANGED
@@ -2,9 +2,10 @@ import os
|
|
2 |
import sys
|
3 |
import gc
|
4 |
import json
|
|
|
5 |
|
6 |
import torch
|
7 |
-
from transformers import
|
8 |
from peft import PeftModel
|
9 |
|
10 |
from .globals import Global
|
@@ -29,7 +30,7 @@ def get_new_base_model(base_model_name):
|
|
29 |
device = get_device()
|
30 |
|
31 |
if device == "cuda":
|
32 |
-
model =
|
33 |
base_model_name,
|
34 |
load_in_8bit=Global.load_8bit,
|
35 |
torch_dtype=torch.float16,
|
@@ -38,20 +39,22 @@ def get_new_base_model(base_model_name):
|
|
38 |
device_map={'': 0},
|
39 |
)
|
40 |
elif device == "mps":
|
41 |
-
model =
|
42 |
base_model_name,
|
43 |
device_map={"": device},
|
44 |
torch_dtype=torch.float16,
|
45 |
)
|
46 |
else:
|
47 |
-
model =
|
48 |
base_model_name, device_map={"": device}, low_cpu_mem_usage=True
|
49 |
)
|
50 |
|
51 |
tokenizer = get_tokenizer(base_model_name)
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
55 |
|
56 |
return model
|
57 |
|
@@ -64,7 +67,14 @@ def get_tokenizer(base_model_name):
|
|
64 |
if loaded_tokenizer:
|
65 |
return loaded_tokenizer
|
66 |
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
Global.loaded_tokenizers.set(base_model_name, tokenizer)
|
69 |
|
70 |
return tokenizer
|
@@ -137,9 +147,10 @@ def get_model(
|
|
137 |
device_map={"": device},
|
138 |
)
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
143 |
|
144 |
if not Global.load_8bit:
|
145 |
model.half() # seems to fix bugs for some users.
|
|
|
2 |
import sys
|
3 |
import gc
|
4 |
import json
|
5 |
+
import re
|
6 |
|
7 |
import torch
|
8 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, LlamaTokenizer
|
9 |
from peft import PeftModel
|
10 |
|
11 |
from .globals import Global
|
|
|
30 |
device = get_device()
|
31 |
|
32 |
if device == "cuda":
|
33 |
+
model = AutoModelForCausalLM.from_pretrained(
|
34 |
base_model_name,
|
35 |
load_in_8bit=Global.load_8bit,
|
36 |
torch_dtype=torch.float16,
|
|
|
39 |
device_map={'': 0},
|
40 |
)
|
41 |
elif device == "mps":
|
42 |
+
model = AutoModelForCausalLM.from_pretrained(
|
43 |
base_model_name,
|
44 |
device_map={"": device},
|
45 |
torch_dtype=torch.float16,
|
46 |
)
|
47 |
else:
|
48 |
+
model = AutoModelForCausalLM.from_pretrained(
|
49 |
base_model_name, device_map={"": device}, low_cpu_mem_usage=True
|
50 |
)
|
51 |
|
52 |
tokenizer = get_tokenizer(base_model_name)
|
53 |
+
|
54 |
+
if re.match("[^/]+/llama", base_model_name):
|
55 |
+
model.config.pad_token_id = tokenizer.pad_token_id = 0
|
56 |
+
model.config.bos_token_id = tokenizer.bos_token_id = 1
|
57 |
+
model.config.eos_token_id = tokenizer.eos_token_id = 2
|
58 |
|
59 |
return model
|
60 |
|
|
|
67 |
if loaded_tokenizer:
|
68 |
return loaded_tokenizer
|
69 |
|
70 |
+
try:
|
71 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
|
72 |
+
except Exception as e:
|
73 |
+
if 'LLaMATokenizer' in str(e):
|
74 |
+
tokenizer = LlamaTokenizer.from_pretrained(base_model_name)
|
75 |
+
else:
|
76 |
+
raise e
|
77 |
+
|
78 |
Global.loaded_tokenizers.set(base_model_name, tokenizer)
|
79 |
|
80 |
return tokenizer
|
|
|
147 |
device_map={"": device},
|
148 |
)
|
149 |
|
150 |
+
if re.match("[^/]+/llama", base_model_name):
|
151 |
+
model.config.pad_token_id = get_tokenizer(base_model_name).pad_token_id = 0
|
152 |
+
model.config.bos_token_id = 1
|
153 |
+
model.config.eos_token_id = 2
|
154 |
|
155 |
if not Global.load_8bit:
|
156 |
model.half() # seems to fix bugs for some users.
|
llama_lora/ui/finetune_ui.py
CHANGED
@@ -299,7 +299,7 @@ def do_train(
|
|
299 |
progress=gr.Progress(track_tqdm=should_training_progress_track_tqdm),
|
300 |
):
|
301 |
try:
|
302 |
-
base_model_name = Global.
|
303 |
output_dir = os.path.join(Global.data_dir, "lora_models", model_name)
|
304 |
if os.path.exists(output_dir):
|
305 |
if (not os.path.isdir(output_dir)) or os.path.exists(os.path.join(output_dir, 'adapter_config.json')):
|
|
|
299 |
progress=gr.Progress(track_tqdm=should_training_progress_track_tqdm),
|
300 |
):
|
301 |
try:
|
302 |
+
base_model_name = Global.base_model_name
|
303 |
output_dir = os.path.join(Global.data_dir, "lora_models", model_name)
|
304 |
if os.path.exists(output_dir):
|
305 |
if (not os.path.isdir(output_dir)) or os.path.exists(os.path.join(output_dir, 'adapter_config.json')):
|
llama_lora/ui/inference_ui.py
CHANGED
@@ -22,7 +22,7 @@ inference_output_lines = 12
|
|
22 |
|
23 |
|
24 |
def prepare_inference(lora_model_name, progress=gr.Progress(track_tqdm=True)):
|
25 |
-
base_model_name = Global.
|
26 |
|
27 |
try:
|
28 |
get_tokenizer(base_model_name)
|
@@ -48,7 +48,7 @@ def do_inference(
|
|
48 |
show_raw=False,
|
49 |
progress=gr.Progress(track_tqdm=True),
|
50 |
):
|
51 |
-
base_model_name = Global.
|
52 |
|
53 |
try:
|
54 |
if Global.generation_force_stopped_at is not None:
|
@@ -257,7 +257,7 @@ def reload_selections(current_lora_model, current_prompt_template):
|
|
257 |
current_prompt_template = current_prompt_template or next(
|
258 |
iter(available_template_names_with_none), None)
|
259 |
|
260 |
-
default_lora_models = [
|
261 |
available_lora_models = default_lora_models + get_available_lora_model_names()
|
262 |
available_lora_models = available_lora_models + ["None"]
|
263 |
|
@@ -283,8 +283,12 @@ def handle_prompt_template_change(prompt_template, lora_model):
|
|
283 |
"", visible=False)
|
284 |
lora_mode_info = get_info_of_available_lora_model(lora_model)
|
285 |
if lora_mode_info and isinstance(lora_mode_info, dict):
|
|
|
286 |
model_prompt_template = lora_mode_info.get("prompt_template")
|
287 |
-
if
|
|
|
|
|
|
|
288 |
model_prompt_template_message_update = gr.Markdown.update(
|
289 |
f"This model was trained with prompt template `{model_prompt_template}`.", visible=True)
|
290 |
|
@@ -331,7 +335,7 @@ def inference_ui():
|
|
331 |
lora_model = gr.Dropdown(
|
332 |
label="LoRA Model",
|
333 |
elem_id="inference_lora_model",
|
334 |
-
value="
|
335 |
allow_custom_value=True,
|
336 |
)
|
337 |
prompt_template = gr.Dropdown(
|
@@ -461,6 +465,8 @@ def inference_ui():
|
|
461 |
interactive=False,
|
462 |
elem_id="inference_raw_output")
|
463 |
|
|
|
|
|
464 |
show_raw_change_event = show_raw.change(
|
465 |
fn=lambda show_raw: gr.Accordion.update(visible=show_raw),
|
466 |
inputs=[show_raw],
|
@@ -482,6 +488,14 @@ def inference_ui():
|
|
482 |
variable_0, variable_1, variable_2, variable_3, variable_4, variable_5, variable_6, variable_7])
|
483 |
things_that_might_timeout.append(prompt_template_change_event)
|
484 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
lora_model_change_event = lora_model.change(
|
486 |
fn=handle_lora_model_change,
|
487 |
inputs=[lora_model, prompt_template],
|
@@ -538,7 +552,7 @@ def inference_ui():
|
|
538 |
|
539 |
// Workaround default value not shown.
|
540 |
document.querySelector('#inference_lora_model input').value =
|
541 |
-
'
|
542 |
}, 100);
|
543 |
|
544 |
// Add tooltips
|
@@ -682,6 +696,30 @@ def inference_ui():
|
|
682 |
}, 500);
|
683 |
}, 0);
|
684 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
685 |
// Debounced updating the prompt preview.
|
686 |
setTimeout(function () {
|
687 |
function debounce(func, wait) {
|
|
|
22 |
|
23 |
|
24 |
def prepare_inference(lora_model_name, progress=gr.Progress(track_tqdm=True)):
|
25 |
+
base_model_name = Global.base_model_name
|
26 |
|
27 |
try:
|
28 |
get_tokenizer(base_model_name)
|
|
|
48 |
show_raw=False,
|
49 |
progress=gr.Progress(track_tqdm=True),
|
50 |
):
|
51 |
+
base_model_name = Global.base_model_name
|
52 |
|
53 |
try:
|
54 |
if Global.generation_force_stopped_at is not None:
|
|
|
257 |
current_prompt_template = current_prompt_template or next(
|
258 |
iter(available_template_names_with_none), None)
|
259 |
|
260 |
+
default_lora_models = []
|
261 |
available_lora_models = default_lora_models + get_available_lora_model_names()
|
262 |
available_lora_models = available_lora_models + ["None"]
|
263 |
|
|
|
283 |
"", visible=False)
|
284 |
lora_mode_info = get_info_of_available_lora_model(lora_model)
|
285 |
if lora_mode_info and isinstance(lora_mode_info, dict):
|
286 |
+
model_base_model = lora_mode_info.get("base_model")
|
287 |
model_prompt_template = lora_mode_info.get("prompt_template")
|
288 |
+
if model_base_model and model_base_model != Global.base_model_name:
|
289 |
+
model_prompt_template_message_update = gr.Markdown.update(
|
290 |
+
f"⚠️ This model was trained on top of base model `{model_base_model}`, it might not work properly with the selected base model `{Global.base_model_name}`.", visible=True)
|
291 |
+
elif model_prompt_template and model_prompt_template != prompt_template:
|
292 |
model_prompt_template_message_update = gr.Markdown.update(
|
293 |
f"This model was trained with prompt template `{model_prompt_template}`.", visible=True)
|
294 |
|
|
|
335 |
lora_model = gr.Dropdown(
|
336 |
label="LoRA Model",
|
337 |
elem_id="inference_lora_model",
|
338 |
+
value="None",
|
339 |
allow_custom_value=True,
|
340 |
)
|
341 |
prompt_template = gr.Dropdown(
|
|
|
465 |
interactive=False,
|
466 |
elem_id="inference_raw_output")
|
467 |
|
468 |
+
reload_selected_models_btn = gr.Button("", elem_id="inference_reload_selected_models_btn")
|
469 |
+
|
470 |
show_raw_change_event = show_raw.change(
|
471 |
fn=lambda show_raw: gr.Accordion.update(visible=show_raw),
|
472 |
inputs=[show_raw],
|
|
|
488 |
variable_0, variable_1, variable_2, variable_3, variable_4, variable_5, variable_6, variable_7])
|
489 |
things_that_might_timeout.append(prompt_template_change_event)
|
490 |
|
491 |
+
reload_selected_models_btn_event = reload_selected_models_btn.click(
|
492 |
+
fn=handle_prompt_template_change,
|
493 |
+
inputs=[prompt_template, lora_model],
|
494 |
+
outputs=[
|
495 |
+
model_prompt_template_message,
|
496 |
+
variable_0, variable_1, variable_2, variable_3, variable_4, variable_5, variable_6, variable_7])
|
497 |
+
things_that_might_timeout.append(reload_selected_models_btn_event)
|
498 |
+
|
499 |
lora_model_change_event = lora_model.change(
|
500 |
fn=handle_lora_model_change,
|
501 |
inputs=[lora_model, prompt_template],
|
|
|
552 |
|
553 |
// Workaround default value not shown.
|
554 |
document.querySelector('#inference_lora_model input').value =
|
555 |
+
'None';
|
556 |
}, 100);
|
557 |
|
558 |
// Add tooltips
|
|
|
696 |
}, 500);
|
697 |
}, 0);
|
698 |
|
699 |
+
// Reload model selection on possible base model change.
|
700 |
+
setTimeout(function () {
|
701 |
+
const elem = document.getElementById('main_page_tabs_container');
|
702 |
+
if (!elem) return;
|
703 |
+
|
704 |
+
let prevClassList = [];
|
705 |
+
|
706 |
+
new MutationObserver(function (mutationsList, observer) {
|
707 |
+
const currentPrevClassList = prevClassList;
|
708 |
+
const currentClassList = Array.from(elem.classList);
|
709 |
+
prevClassList = Array.from(elem.classList);
|
710 |
+
|
711 |
+
if (!currentPrevClassList.includes('hide')) return;
|
712 |
+
if (currentClassList.includes('hide')) return;
|
713 |
+
|
714 |
+
const inference_reload_selected_models_btn_elem = document.getElementById('inference_reload_selected_models_btn');
|
715 |
+
|
716 |
+
if (inference_reload_selected_models_btn_elem) inference_reload_selected_models_btn_elem.click();
|
717 |
+
}).observe(elem, {
|
718 |
+
attributes: true,
|
719 |
+
attributeFilter: ['class'],
|
720 |
+
});
|
721 |
+
}, 0);
|
722 |
+
|
723 |
// Debounced updating the prompt preview.
|
724 |
setTimeout(function () {
|
725 |
function debounce(func, wait) {
|
llama_lora/ui/main_page.py
CHANGED
@@ -17,25 +17,50 @@ def main_page():
|
|
17 |
css=main_page_custom_css(),
|
18 |
) as main_page_blocks:
|
19 |
with gr.Column(elem_id="main_page_content"):
|
20 |
-
gr.
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
main_page_blocks.load(_js=f"""
|
40 |
function () {{
|
41 |
{popperjs_core_code()}
|
@@ -61,6 +86,17 @@ def main_page():
|
|
61 |
});
|
62 |
handle_gradio_container_element_class_change();
|
63 |
}, 500);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
}
|
65 |
""")
|
66 |
|
@@ -127,12 +163,77 @@ def main_page_custom_css():
|
|
127 |
display: none;
|
128 |
}
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
#main_page_content > .tabs > .tab-nav * {
|
131 |
font-size: 1rem;
|
132 |
font-weight: 700;
|
133 |
/* text-transform: uppercase; */
|
134 |
}
|
135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
#inference_lora_model_group {
|
137 |
border-radius: var(--block-radius);
|
138 |
background: var(--block-background-fill);
|
@@ -147,7 +248,8 @@ def main_page_custom_css():
|
|
147 |
position: absolute;
|
148 |
bottom: 8px;
|
149 |
left: 20px;
|
150 |
-
z-index:
|
|
|
151 |
font-size: 12px;
|
152 |
opacity: 0.7;
|
153 |
}
|
@@ -515,3 +617,28 @@ def main_page_custom_css():
|
|
515 |
.tippy-box[data-animation=scale-subtle][data-placement^=top]{transform-origin:bottom}.tippy-box[data-animation=scale-subtle][data-placement^=bottom]{transform-origin:top}.tippy-box[data-animation=scale-subtle][data-placement^=left]{transform-origin:right}.tippy-box[data-animation=scale-subtle][data-placement^=right]{transform-origin:left}.tippy-box[data-animation=scale-subtle][data-state=hidden]{transform:scale(.8);opacity:0}
|
516 |
"""
|
517 |
return css
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
css=main_page_custom_css(),
|
18 |
) as main_page_blocks:
|
19 |
with gr.Column(elem_id="main_page_content"):
|
20 |
+
with gr.Row():
|
21 |
+
gr.Markdown(
|
22 |
+
f"""
|
23 |
+
<h1 class="app_title_text">{title}</h1> <wbr />
|
24 |
+
<h2 class="app_subtitle_text">{Global.ui_subtitle}</h2>
|
25 |
+
""",
|
26 |
+
elem_id="page_title",
|
27 |
+
)
|
28 |
+
global_base_model_select = gr.Dropdown(
|
29 |
+
label="Base Model",
|
30 |
+
elem_id="global_base_model_select",
|
31 |
+
choices=Global.base_model_choices,
|
32 |
+
value=lambda: Global.base_model_name,
|
33 |
+
allow_custom_value=True,
|
34 |
+
)
|
35 |
+
# global_base_model_select_loading_status = gr.Markdown("", elem_id="global_base_model_select_loading_status")
|
36 |
+
|
37 |
+
with gr.Column(elem_id="main_page_tabs_container") as main_page_tabs_container:
|
38 |
+
with gr.Tab("Inference"):
|
39 |
+
inference_ui()
|
40 |
+
with gr.Tab("Fine-tuning"):
|
41 |
+
finetune_ui()
|
42 |
+
with gr.Tab("Tokenizer"):
|
43 |
+
tokenizer_ui()
|
44 |
+
please_select_a_base_model_message = gr.Markdown("Please select a base model.", visible=False)
|
45 |
+
current_base_model_hint = gr.Markdown(lambda: Global.base_model_name, elem_id="current_base_model_hint")
|
46 |
+
foot_info = gr.Markdown(get_foot_info)
|
47 |
+
|
48 |
+
global_base_model_select.change(
|
49 |
+
fn=pre_handle_change_base_model,
|
50 |
+
inputs=[],
|
51 |
+
outputs=[main_page_tabs_container]
|
52 |
+
).then(
|
53 |
+
fn=handle_change_base_model,
|
54 |
+
inputs=[global_base_model_select],
|
55 |
+
outputs=[
|
56 |
+
main_page_tabs_container,
|
57 |
+
please_select_a_base_model_message,
|
58 |
+
current_base_model_hint,
|
59 |
+
# global_base_model_select_loading_status,
|
60 |
+
foot_info
|
61 |
+
]
|
62 |
+
)
|
63 |
+
|
64 |
main_page_blocks.load(_js=f"""
|
65 |
function () {{
|
66 |
{popperjs_core_code()}
|
|
|
86 |
});
|
87 |
handle_gradio_container_element_class_change();
|
88 |
}, 500);
|
89 |
+
""" + """
|
90 |
+
setTimeout(function () {
|
91 |
+
// Workaround default value not shown.
|
92 |
+
const current_base_model_hint_elem = document.querySelector('#current_base_model_hint > p');
|
93 |
+
if (!current_base_model_hint_elem) return;
|
94 |
+
|
95 |
+
const base_model_name = current_base_model_hint_elem.innerText;
|
96 |
+
document.querySelector('#global_base_model_select input').value = base_model_name;
|
97 |
+
document.querySelector('#global_base_model_select').classList.add('show');
|
98 |
+
}, 3200);
|
99 |
+
""" + """
|
100 |
}
|
101 |
""")
|
102 |
|
|
|
163 |
display: none;
|
164 |
}
|
165 |
|
166 |
+
#page_title {
|
167 |
+
flex-grow: 3;
|
168 |
+
}
|
169 |
+
#global_base_model_select {
|
170 |
+
position: relative;
|
171 |
+
align-self: center;
|
172 |
+
min-width: 250px;
|
173 |
+
padding: 2px 2px;
|
174 |
+
border: 0;
|
175 |
+
box-shadow: none;
|
176 |
+
opacity: 0;
|
177 |
+
pointer-events: none;
|
178 |
+
}
|
179 |
+
#global_base_model_select.show {
|
180 |
+
opacity: 1;
|
181 |
+
pointer-events: auto;
|
182 |
+
}
|
183 |
+
#global_base_model_select label .wrap-inner {
|
184 |
+
padding: 2px 8px;
|
185 |
+
}
|
186 |
+
#global_base_model_select label span {
|
187 |
+
margin-bottom: 2px;
|
188 |
+
font-size: 80%;
|
189 |
+
position: absolute;
|
190 |
+
top: -14px;
|
191 |
+
left: 8px;
|
192 |
+
opacity: 0;
|
193 |
+
}
|
194 |
+
#global_base_model_select:hover label span {
|
195 |
+
opacity: 1;
|
196 |
+
}
|
197 |
+
|
198 |
+
#global_base_model_select_loading_status {
|
199 |
+
position: absolute;
|
200 |
+
pointer-events: none;
|
201 |
+
top: 0;
|
202 |
+
left: 0;
|
203 |
+
right: 0;
|
204 |
+
bottom: 0;
|
205 |
+
}
|
206 |
+
#global_base_model_select_loading_status > .wrap:not(.hide) {
|
207 |
+
z-index: 9999;
|
208 |
+
position: absolute;
|
209 |
+
top: 112px !important;
|
210 |
+
bottom: 0 !important;
|
211 |
+
max-height: none;
|
212 |
+
background: var(--background-fill-primary);
|
213 |
+
opacity: 0.8;
|
214 |
+
}
|
215 |
+
|
216 |
+
#current_base_model_hint {
|
217 |
+
display: none;
|
218 |
+
}
|
219 |
+
|
220 |
#main_page_content > .tabs > .tab-nav * {
|
221 |
font-size: 1rem;
|
222 |
font-weight: 700;
|
223 |
/* text-transform: uppercase; */
|
224 |
}
|
225 |
|
226 |
+
#inference_reload_selected_models_btn {
|
227 |
+
position: absolute;
|
228 |
+
top: 0;
|
229 |
+
left: 0;
|
230 |
+
width: 0;
|
231 |
+
height: 0;
|
232 |
+
padding: 0;
|
233 |
+
opacity: 0;
|
234 |
+
pointer-events: none;
|
235 |
+
}
|
236 |
+
|
237 |
#inference_lora_model_group {
|
238 |
border-radius: var(--block-radius);
|
239 |
background: var(--block-background-fill);
|
|
|
248 |
position: absolute;
|
249 |
bottom: 8px;
|
250 |
left: 20px;
|
251 |
+
z-index: 61;
|
252 |
+
width: 999px;
|
253 |
font-size: 12px;
|
254 |
opacity: 0.7;
|
255 |
}
|
|
|
617 |
.tippy-box[data-animation=scale-subtle][data-placement^=top]{transform-origin:bottom}.tippy-box[data-animation=scale-subtle][data-placement^=bottom]{transform-origin:top}.tippy-box[data-animation=scale-subtle][data-placement^=left]{transform-origin:right}.tippy-box[data-animation=scale-subtle][data-placement^=right]{transform-origin:left}.tippy-box[data-animation=scale-subtle][data-state=hidden]{transform:scale(.8);opacity:0}
|
618 |
"""
|
619 |
return css
|
620 |
+
|
621 |
+
|
622 |
+
def pre_handle_change_base_model():
|
623 |
+
return gr.Column.update(visible=False)
|
624 |
+
|
625 |
+
|
626 |
+
def handle_change_base_model(selected_base_model_name):
|
627 |
+
Global.base_model_name = selected_base_model_name
|
628 |
+
|
629 |
+
if Global.base_model_name:
|
630 |
+
return gr.Column.update(visible=True), gr.Markdown.update(visible=False), Global.base_model_name, get_foot_info()
|
631 |
+
|
632 |
+
return gr.Column.update(visible=False), gr.Markdown.update(visible=True), Global.base_model_name, get_foot_info()
|
633 |
+
|
634 |
+
|
635 |
+
def get_foot_info():
|
636 |
+
info = []
|
637 |
+
if Global.version:
|
638 |
+
info.append(f"LLaMA-LoRA Tuner `{Global.version}`")
|
639 |
+
info.append(f"Base model: `{Global.base_model_name}`")
|
640 |
+
if Global.ui_show_sys_info:
|
641 |
+
info.append(f"Data dir: `{Global.data_dir}`")
|
642 |
+
return f"""\
|
643 |
+
<small>{" · ".join(info)}</small>
|
644 |
+
"""
|
lora_models/alpaca-lora-7b/info.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"hf_model_name": "tloen/alpaca-lora-7b",
|
3 |
+
"load_from_hf": true,
|
4 |
+
"base_model": "decapoda-research/llama-7b-hf",
|
5 |
+
"prompt_template": "alpaca"
|
6 |
+
}
|