Minor bug fix (soft prompt was being loaded twice)

This commit is contained in:
oobabooga 2023-02-13 23:34:04 -03:00
parent 56bbc996a4
commit 8b3bb512ef

View File

@ -146,7 +146,7 @@ def load_model(model_name):
if args.disk: if args.disk:
params.append(f"offload_folder='{args.disk_cache_dir or 'cache'}'") params.append(f"offload_folder='{args.disk_cache_dir or 'cache'}'")
command = f"{command}(Path(f'models/{model_name}'), {','.join(set(params))})" command = f"{command}(Path(f'models/{model_name}'), {', '.join(set(params))})"
model = eval(command) model = eval(command)
# Loading the tokenizer # Loading the tokenizer
@ -186,8 +186,6 @@ def upload_soft_prompt(file):
with open(Path(f'softprompts/{name}.zip'), 'wb') as f: with open(Path(f'softprompts/{name}.zip'), 'wb') as f:
f.write(file) f.write(file)
load_soft_prompt(name)
return name return name
def load_model_wrapper(selected_model): def load_model_wrapper(selected_model):
@ -343,7 +341,7 @@ def generate_reply(question, tokens, do_sample, max_new_tokens, temperature, top
if args.no_stream: if args.no_stream:
t0 = time.time() t0 = time.time()
with torch.no_grad(): with torch.no_grad():
output = eval(f"model.generate({','.join(generate_params)}){cuda}")[0] output = eval(f"model.generate({', '.join(generate_params)}){cuda}")[0]
if soft_prompt: if soft_prompt:
output = torch.cat((input_ids[0], output[filler_input_ids.shape[1]:])) output = torch.cat((input_ids[0], output[filler_input_ids.shape[1]:]))
@ -360,7 +358,7 @@ def generate_reply(question, tokens, do_sample, max_new_tokens, temperature, top
yield formatted_outputs(original_question, model_name) yield formatted_outputs(original_question, model_name)
for i in tqdm(range(tokens//8+1)): for i in tqdm(range(tokens//8+1)):
with torch.no_grad(): with torch.no_grad():
output = eval(f"model.generate({','.join(generate_params)}){cuda}")[0] output = eval(f"model.generate({', '.join(generate_params)}){cuda}")[0]
if soft_prompt: if soft_prompt:
output = torch.cat((input_ids[0], output[filler_input_ids.shape[1]:])) output = torch.cat((input_ids[0], output[filler_input_ids.shape[1]:]))
@ -476,7 +474,7 @@ def create_settings_menus():
softprompts_menu = gr.Dropdown(choices=available_softprompts, value="None", label='Soft prompt') softprompts_menu = gr.Dropdown(choices=available_softprompts, value="None", label='Soft prompt')
create_refresh_button(softprompts_menu, lambda : None, lambda : {"choices": get_available_softprompts()}, "refresh-button") create_refresh_button(softprompts_menu, lambda : None, lambda : {"choices": get_available_softprompts()}, "refresh-button")
gr.Markdown('Upload a soft prompt:') gr.Markdown('Upload a soft prompt (.zip format):')
with gr.Row(): with gr.Row():
upload_softprompt = gr.File(type='binary') upload_softprompt = gr.File(type='binary')