Spaces:
Runtime error
Runtime error
Update proton_code_llama_fine_tuning_using_qlora_inferencing.py
Browse files
proton_code_llama_fine_tuning_using_qlora_inferencing.py
CHANGED
|
@@ -105,19 +105,46 @@ def prepare_prompt(query):
|
|
| 105 |
prompt_prep = ''.join([priming_text,getExamples(query),'\n',decorator,'\n','Similar to the above examples, generate only one Proton UI for the following description:',query])
|
| 106 |
return prompt_prep
|
| 107 |
|
| 108 |
-
def
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
max_new_tokens=1000,do_sample=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
-
|
| 119 |
|
| 120 |
-
|
| 121 |
|
| 122 |
# output = generate('Create a choice type of Proton UI for choosing vegetables')
|
| 123 |
# print(output)
|
|
|
|
| 105 |
prompt_prep = ''.join([priming_text,getExamples(query),'\n',decorator,'\n','Similar to the above examples, generate only one Proton UI for the following description:',query])
|
| 106 |
return prompt_prep
|
| 107 |
|
| 108 |
+
def generate_text(query):
|
| 109 |
+
prompt_prep = prepare_prompt(query)
|
| 110 |
+
encodings = model_tokenizer(prompt_prep, return_tensors = 'pt').to(device)
|
| 111 |
+
|
| 112 |
+
# with torch.inference_mode():
|
| 113 |
+
outputs = model.generate(input_ids=encodings.input_ids,
|
| 114 |
+
attention_mask = encodings.attention_mask,
|
| 115 |
+
generation_config = generation_config,
|
| 116 |
max_new_tokens=1000,do_sample=True)
|
| 117 |
+
|
| 118 |
+
outputs = model_tokenizer.decode(outputs[0],skip_special_tokens=True,best_of=1)
|
| 119 |
+
outputs = outputs[outputs.find(query): ]
|
| 120 |
+
return re.match(r'(.*?\nDescription:.*?\nDescription:)', outputs, re.DOTALL).group(1)[:-12]
|
| 121 |
+
|
| 122 |
+
def alternatingly_agree(message, history):
|
| 123 |
+
output = generate_text(message)
|
| 124 |
+
return output
|
| 125 |
+
# gr.ChatInterface(alternatingly_agree).launch(inline=False,enable_queue=True)
|
| 126 |
+
|
| 127 |
+
gr.ChatInterface(
|
| 128 |
+
alternatingly_agree,
|
| 129 |
+
retry_btn=None,
|
| 130 |
+
undo_btn="Delete Previous",
|
| 131 |
+
clear_btn="Clear",
|
| 132 |
+
).launch(inline=False,
|
| 133 |
+
enable_queue=True,share=True)
|
| 134 |
+
|
| 135 |
+
# def generate(query):
|
| 136 |
+
# prompt_prep = prepare_prompt(query)
|
| 137 |
+
# encodings = model_tokenizer(prompt_prep, return_tensors = 'pt').to(device)
|
| 138 |
+
|
| 139 |
+
# with torch.inference_mode():
|
| 140 |
+
# outputs = model.generate(input_ids=encodings.input_ids,
|
| 141 |
+
# attention_mask = encodings.attention_mask,
|
| 142 |
+
# generation_config = generation_config,
|
| 143 |
+
# max_new_tokens=1000,do_sample=True)
|
| 144 |
|
| 145 |
+
# outputs = model_tokenizer.decode(outputs[0],skip_special_tokens=True,best_of=1)
|
| 146 |
|
| 147 |
+
# return outputs[outputs.find(query): ]#outputs.find('Explanation')
|
| 148 |
|
| 149 |
# output = generate('Create a choice type of Proton UI for choosing vegetables')
|
| 150 |
# print(output)
|