From 0bac80d9ebf03d91ed5b8f921be03debc3c65cee Mon Sep 17 00:00:00 2001 From: Sean Fitzgerald Date: Sat, 25 Mar 2023 13:08:45 -0700 Subject: [PATCH 1/8] Potential fix for issues/571 --- modules/text_generation.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/text_generation.py b/modules/text_generation.py index fd017e2..eb8f6ca 100644 --- a/modules/text_generation.py +++ b/modules/text_generation.py @@ -236,8 +236,6 @@ def generate_reply(question, max_new_tokens, do_sample, temperature, top_p, typi break yield formatted_outputs(reply, shared.model_name) - yield formatted_outputs(reply, shared.model_name) - # Stream the output naively for FlexGen since it doesn't support 'stopping_criteria' else: for i in range(max_new_tokens//8+1): From 8e2d94a5a1a8252131715d7dfe068fc8e49d9aaf Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Mon, 27 Mar 2023 12:21:19 -0300 Subject: [PATCH 2/8] Add saved promtps to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3685291..a9c47a5 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ repositories settings.json img_bot* img_me* +prompts/[0-9]* From 202e981d00755e45850e3f428e24dc9e8be75b0c Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Mon, 27 Mar 2023 12:30:57 -0300 Subject: [PATCH 3/8] Make Generate/Stop buttons smaller in notebook mode --- server.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server.py b/server.py index b789ab1..27525e4 100644 --- a/server.py +++ b/server.py @@ -417,8 +417,12 @@ def create_interface(): shared.gradio['html'] = gr.HTML() with gr.Row(): - shared.gradio['Generate'] = gr.Button('Generate') - shared.gradio['Stop'] = gr.Button('Stop') + with gr.Column(): + with gr.Row(): + shared.gradio['Generate'] = gr.Button('Generate') + shared.gradio['Stop'] = gr.Button('Stop') + with gr.Column(): + pass with gr.Column(scale=1): gr.Markdown("\n") From 572bafcd24099553cd432e4a695a20050386f8c9 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Mon, 27 Mar 2023 12:43:37 -0300 Subject: [PATCH 4/8] Less verbose message --- server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.py b/server.py index 27525e4..020093e 100644 --- a/server.py +++ b/server.py @@ -135,7 +135,7 @@ def save_prompt(text): fname = f"{datetime.now().strftime('%Y-%m-%d-%H:%M:%S')}.txt" with open(Path(f'prompts/{fname}'), 'w', encoding='utf-8') as f: f.write(text) - return f"Saved prompt to prompts/{fname}" + return f"Saved to prompts/{fname}" def load_prompt(fname): if fname in ['None', '']: From addb9777f9130f6cef773db68992bfac7cff8058 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Mon, 27 Mar 2023 12:59:07 -0300 Subject: [PATCH 5/8] Increase size of GALACTICA equations --- css/main.css | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/css/main.css b/css/main.css index 97879f0..3f04409 100644 --- a/css/main.css +++ b/css/main.css @@ -37,12 +37,6 @@ text-decoration: none !important; } -svg { - display: unset !important; - vertical-align: middle !important; - margin: 5px; -} - ol li p, ul li p { display: inline-block; } @@ -64,3 +58,8 @@ ol li p, ul li p { padding: 15px; padding: 15px; } + +span.math.inline { + font-size: 27px; + vertical-align: baseline !important; +} From af65c129008c7b84a933247867673575de07ae33 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Mon, 27 Mar 2023 13:23:59 -0300 Subject: [PATCH 6/8] Change Stop button behavior --- modules/callbacks.py | 2 +- modules/chat.py | 4 ---- modules/text_generation.py | 4 ++++ server.py | 9 +++++---- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/callbacks.py b/modules/callbacks.py index 8d30d61..d85f406 100644 --- a/modules/callbacks.py +++ b/modules/callbacks.py @@ -54,7 +54,7 @@ class Iteratorize: self.stop_now = False def _callback(val): - if self.stop_now: + if self.stop_now or shared.stop_everything: raise ValueError self.q.put(val) diff --git a/modules/chat.py b/modules/chat.py index 1a43cf3..cc3c45c 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -80,11 +80,7 @@ def extract_message_from_reply(reply, name1, name2, check): reply = fix_newlines(reply) return reply, next_character_found -def stop_everything_event(): - shared.stop_everything = True - def chatbot_wrapper(text, max_new_tokens, do_sample, temperature, top_p, typical_p, repetition_penalty, encoder_repetition_penalty, top_k, min_length, no_repeat_ngram_size, num_beams, penalty_alpha, length_penalty, early_stopping, seed, name1, name2, context, check, chat_prompt_size, chat_generation_attempts=1, regenerate=False): - shared.stop_everything = False just_started = True eos_token = '\n' if check else None name1_original = name1 diff --git a/modules/text_generation.py b/modules/text_generation.py index 9b2c233..477257c 100644 --- a/modules/text_generation.py +++ b/modules/text_generation.py @@ -99,9 +99,13 @@ def set_manual_seed(seed): if torch.cuda.is_available(): torch.cuda.manual_seed_all(seed) +def stop_everything_event(): + shared.stop_everything = True + def generate_reply(question, max_new_tokens, do_sample, temperature, top_p, typical_p, repetition_penalty, encoder_repetition_penalty, top_k, min_length, no_repeat_ngram_size, num_beams, penalty_alpha, length_penalty, early_stopping, seed, eos_token=None, stopping_strings=[]): clear_torch_cache() set_manual_seed(seed) + shared.stop_everything = False t0 = time.time() original_question = question diff --git a/server.py b/server.py index 020093e..9f90c79 100644 --- a/server.py +++ b/server.py @@ -16,7 +16,8 @@ import modules.ui as ui from modules.html_generator import generate_chat_html from modules.LoRA import add_lora_to_model from modules.models import load_model, load_soft_prompt -from modules.text_generation import clear_torch_cache, generate_reply +from modules.text_generation import (clear_torch_cache, generate_reply, + stop_everything_event) # Loading custom settings settings_file = None @@ -366,7 +367,7 @@ def create_interface(): gen_events.append(shared.gradio['textbox'].submit(eval(function_call), shared.input_params, shared.gradio['display'], show_progress=shared.args.no_stream)) gen_events.append(shared.gradio['Regenerate'].click(chat.regenerate_wrapper, shared.input_params, shared.gradio['display'], show_progress=shared.args.no_stream)) gen_events.append(shared.gradio['Impersonate'].click(chat.impersonate_wrapper, shared.input_params, shared.gradio['textbox'], show_progress=shared.args.no_stream)) - shared.gradio['Stop'].click(chat.stop_everything_event, [], [], cancels=gen_events, queue=False) + shared.gradio['Stop'].click(stop_everything_event, [], [], queue=False, cancels=gen_events if shared.args.no_stream else None) shared.gradio['Copy last reply'].click(chat.send_last_reply_to_input, [], shared.gradio['textbox'], show_progress=shared.args.no_stream) shared.gradio['Replace last reply'].click(chat.replace_last_reply, [shared.gradio['textbox'], shared.gradio['name1'], shared.gradio['name2']], shared.gradio['display'], show_progress=shared.args.no_stream) @@ -437,7 +438,7 @@ def create_interface(): output_params = [shared.gradio[k] for k in ['textbox', 'markdown', 'html']] gen_events.append(shared.gradio['Generate'].click(generate_reply, shared.input_params, output_params, show_progress=shared.args.no_stream, api_name='textgen')) gen_events.append(shared.gradio['textbox'].submit(generate_reply, shared.input_params, output_params, show_progress=shared.args.no_stream)) - shared.gradio['Stop'].click(None, None, None, cancels=gen_events) + shared.gradio['Stop'].click(stop_everything_event, [], [], queue=False, cancels=gen_events if shared.args.no_stream else None) shared.gradio['interface'].load(None, None, None, _js=f"() => {{{ui.main_js}}}") else: @@ -471,7 +472,7 @@ def create_interface(): gen_events.append(shared.gradio['Generate'].click(generate_reply, shared.input_params, output_params, show_progress=shared.args.no_stream, api_name='textgen')) gen_events.append(shared.gradio['textbox'].submit(generate_reply, shared.input_params, output_params, show_progress=shared.args.no_stream)) gen_events.append(shared.gradio['Continue'].click(generate_reply, [shared.gradio['output_textbox']] + shared.input_params[1:], output_params, show_progress=shared.args.no_stream)) - shared.gradio['Stop'].click(None, None, None, cancels=gen_events) + shared.gradio['Stop'].click(stop_everything_event, [], [], queue=False, cancels=gen_events if shared.args.no_stream else None) shared.gradio['interface'].load(None, None, None, _js=f"() => {{{ui.main_js}}}") with gr.Tab("Interface mode", elem_id="interface-mode"): From 268abd1cbabf00ca841efc85211428b3a7f54680 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Mon, 27 Mar 2023 13:52:12 -0300 Subject: [PATCH 7/8] Add some space in notebook mode --- server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.py b/server.py index 9f90c79..36083cc 100644 --- a/server.py +++ b/server.py @@ -426,7 +426,7 @@ def create_interface(): pass with gr.Column(scale=1): - gr.Markdown("\n") + gr.HTML('
') shared.gradio['max_new_tokens'] = gr.Slider(minimum=shared.settings['max_new_tokens_min'], maximum=shared.settings['max_new_tokens_max'], step=1, label='max_new_tokens', value=shared.settings['max_new_tokens']) create_prompt_menus() From 641e1a09a746f3c1172d0a60fb68067d27d903c0 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Mon, 27 Mar 2023 14:48:43 -0300 Subject: [PATCH 8/8] Don't flash when selecting a new prompt --- server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.py b/server.py index 36083cc..8b26a90 100644 --- a/server.py +++ b/server.py @@ -157,7 +157,7 @@ def create_prompt_menus(): shared.gradio['save_prompt'] = gr.Button('Save prompt') shared.gradio['status'] = gr.Markdown('Ready') - shared.gradio['prompt_menu'].change(load_prompt, [shared.gradio['prompt_menu']], [shared.gradio['textbox']], show_progress=True) + shared.gradio['prompt_menu'].change(load_prompt, [shared.gradio['prompt_menu']], [shared.gradio['textbox']], show_progress=False) shared.gradio['save_prompt'].click(save_prompt, [shared.gradio['textbox']], [shared.gradio['status']], show_progress=False) def create_settings_menus(default_preset):