Skip to content

Commit 214dc68

Browse files
committed
Several QoL changes related to LoRA
1 parent 0cecfc6 commit 214dc68

File tree

3 files changed

+48
-34
lines changed

3 files changed

+48
-34
lines changed

modules/shared.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
'^(gpt4chan|gpt-4chan|4chan)': '-----\n--- 865467536\nInput text\n--- 865467537\n',
5454
'(rosey|chip|joi)_.*_instruct.*': 'User: \n',
5555
'oasst-*': '<|prompter|>Write a story about future of AI development<|endoftext|><|assistant|>'
56+
},
57+
'lora_prompts': {
58+
'default': 'Common sense questions and answers\n\nQuestion: \nFactual answer:',
59+
'alpaca-lora-7b': "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n### Instruction:\nWrite a Python script that generates text using the transformers library.\n### Response:\n"
5660
}
5761
}
5862

@@ -68,6 +72,7 @@ def str2bool(v):
6872

6973
parser = argparse.ArgumentParser(formatter_class=lambda prog: argparse.HelpFormatter(prog,max_help_position=54))
7074
parser.add_argument('--model', type=str, help='Name of the model to load by default.')
75+
parser.add_argument('--lora', type=str, help='Name of the LoRA to apply to the model by default.')
7176
parser.add_argument('--notebook', action='store_true', help='Launch the web UI in notebook mode, where the output is written to the same text box as the input.')
7277
parser.add_argument('--chat', action='store_true', help='Launch the web UI in chat mode.')
7378
parser.add_argument('--cai-chat', action='store_true', help='Launch the web UI in chat mode with a style similar to Character.AI\'s. If the file img_bot.png or img_bot.jpg exists in the same folder as server.py, this image will be used as the bot\'s profile picture. Similarly, img_me.png or img_me.jpg will be used as your profile picture.')

server.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,16 @@ def set_interface_arguments(interface_mode, extensions, cmd_active):
225225
print()
226226
shared.model_name = available_models[i]
227227
shared.model, shared.tokenizer = load_model(shared.model_name)
228+
if shared.args.lora:
229+
shared.lora_name = shared.args.lora
230+
print(f"Adding the LoRA {shared.lora_name} to the model...")
231+
add_lora_to_model(shared.lora_name)
228232

229233
# Default UI settings
230234
default_preset = shared.settings['presets'][next((k for k in shared.settings['presets'] if re.match(k.lower(), shared.model_name.lower())), 'default')]
231-
default_text = shared.settings['prompts'][next((k for k in shared.settings['prompts'] if re.match(k.lower(), shared.model_name.lower())), 'default')]
235+
default_text = shared.settings['lora_prompts'][next((k for k in shared.settings['lora_prompts'] if re.match(k.lower(), shared.lora_name.lower())), 'default')]
236+
if default_text == '':
237+
default_text = shared.settings['prompts'][next((k for k in shared.settings['prompts'] if re.match(k.lower(), shared.model_name.lower())), 'default')]
232238
title ='Text generation web UI'
233239
description = '\n\n# Text generation lab\nGenerate text using Large Language Models.\n'
234240
suffix = '_pygmalion' if 'pygmalion' in shared.model_name.lower() else ''

settings-template.json

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
11
{
2-
"max_new_tokens": 200,
3-
"max_new_tokens_min": 1,
4-
"max_new_tokens_max": 2000,
5-
"name1": "Person 1",
6-
"name2": "Person 2",
7-
"context": "This is a conversation between two people.",
8-
"stop_at_newline": true,
9-
"chat_prompt_size": 2048,
10-
"chat_prompt_size_min": 0,
11-
"chat_prompt_size_max": 2048,
12-
"chat_generation_attempts": 1,
13-
"chat_generation_attempts_min": 1,
14-
"chat_generation_attempts_max": 5,
15-
"name1_pygmalion": "You",
16-
"name2_pygmalion": "Kawaii",
17-
"context_pygmalion": "Kawaii's persona: Kawaii is a cheerful person who loves to make others smile. She is an optimist who loves to spread happiness and positivity wherever she goes.\n<START>",
18-
"stop_at_newline_pygmalion": false,
19-
"default_extensions": [],
20-
"chat_default_extensions": [
21-
"gallery"
22-
],
23-
"presets": {
24-
"default": "NovelAI-Sphinx Moth",
25-
"pygmalion-*": "Pygmalion",
26-
"RWKV-*": "Naive",
27-
"(rosey|chip|joi)_.*_instruct.*": "Instruct Joi (Contrastive Search)"
28-
},
29-
"prompts": {
30-
"default": "Common sense questions and answers\n\nQuestion: \nFactual answer:",
31-
"^(gpt4chan|gpt-4chan|4chan)": "-----\n--- 865467536\nInput text\n--- 865467537\n",
32-
"(rosey|chip|joi)_.*_instruct.*": "User: \n",
33-
"oasst-*": "<|prompter|>Write a story about future of AI development<|endoftext|><|assistant|>"
34-
}
2+
"max_new_tokens": 200,
3+
"max_new_tokens_min": 1,
4+
"max_new_tokens_max": 2000,
5+
"name1": "Person 1",
6+
"name2": "Person 2",
7+
"context": "This is a conversation between two people.",
8+
"stop_at_newline": true,
9+
"chat_prompt_size": 2048,
10+
"chat_prompt_size_min": 0,
11+
"chat_prompt_size_max": 2048,
12+
"chat_generation_attempts": 1,
13+
"chat_generation_attempts_min": 1,
14+
"chat_generation_attempts_max": 5,
15+
"name1_pygmalion": "You",
16+
"name2_pygmalion": "Kawaii",
17+
"context_pygmalion": "Kawaii's persona: Kawaii is a cheerful person who loves to make others smile. She is an optimist who loves to spread happiness and positivity wherever she goes.\n<START>",
18+
"stop_at_newline_pygmalion": false,
19+
"default_extensions": [],
20+
"chat_default_extensions": [
21+
"gallery"
22+
],
23+
"presets": {
24+
"default": "NovelAI-Sphinx Moth",
25+
"pygmalion-*": "Pygmalion",
26+
"RWKV-*": "Naive"
27+
},
28+
"prompts": {
29+
"default": "Common sense questions and answers\n\nQuestion: \nFactual answer:",
30+
"^(gpt4chan|gpt-4chan|4chan)": "-----\n--- 865467536\nInput text\n--- 865467537\n",
31+
"(rosey|chip|joi)_.*_instruct.*": "User: \n",
32+
"oasst-*": "<|prompter|>Write a story about future of AI development<|endoftext|><|assistant|>"
33+
},
34+
"lora_prompts": {
35+
"default": "Common sense questions and answers\n\nQuestion: \nFactual answer:",
36+
"alpaca-lora-7b": "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n### Instruction:\nWrite a Python script that generates text using the transformers library.\n### Response:\n"
37+
}
3538
}

0 commit comments

Comments
 (0)