add try catch hopes could get some info from gradio
Browse files
app.py
CHANGED
|
@@ -95,34 +95,42 @@ def main(
|
|
| 95 |
max_new_tokens=256,
|
| 96 |
**kwargs,
|
| 97 |
):
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
)
|
| 113 |
-
with torch.no_grad():
|
| 114 |
-
f.write("3.before model.generate(..).")
|
| 115 |
-
generation_output = model.generate(
|
| 116 |
-
input_ids=input_ids,
|
| 117 |
-
generation_config=generation_config,
|
| 118 |
-
return_dict_in_generate=True,
|
| 119 |
-
output_scores=True,
|
| 120 |
-
max_new_tokens=max_new_tokens,
|
| 121 |
)
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
return prompter.get_response(output),DebugInfo
|
| 127 |
|
| 128 |
gr.Interface(
|
|
@@ -186,4 +194,9 @@ def main(
|
|
| 186 |
|
| 187 |
|
| 188 |
if __name__ == "__main__":
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
max_new_tokens=256,
|
| 96 |
**kwargs,
|
| 97 |
):
|
| 98 |
+
import traceback
|
| 99 |
+
try:
|
| 100 |
+
DebugInfo.append("1.Enter in evaluate.")#TBD
|
| 101 |
+
f.write("1.Enter in evaluate.")
|
| 102 |
+
#f.close()
|
| 103 |
|
| 104 |
+
prompt = prompter.generate_prompt(instruction, input)
|
| 105 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 106 |
+
input_ids = inputs["input_ids"].to(device)
|
| 107 |
+
f.write("2.after input_ids.")
|
| 108 |
+
generation_config = GenerationConfig(
|
| 109 |
+
temperature=temperature,
|
| 110 |
+
top_p=top_p,
|
| 111 |
+
top_k=top_k,
|
| 112 |
+
num_beams=num_beams,
|
| 113 |
+
**kwargs,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
)
|
| 115 |
+
with torch.no_grad():
|
| 116 |
+
f.write("3.before model.generate(..).")
|
| 117 |
+
generation_output = model.generate(
|
| 118 |
+
input_ids=input_ids,
|
| 119 |
+
generation_config=generation_config,
|
| 120 |
+
return_dict_in_generate=True,
|
| 121 |
+
output_scores=True,
|
| 122 |
+
max_new_tokens=max_new_tokens,
|
| 123 |
+
)
|
| 124 |
+
s = generation_output.sequences[0]
|
| 125 |
+
output = tokenizer.decode(s)
|
| 126 |
+
DebugInfo.append("2.Generate out decode completed.")#TBD
|
| 127 |
+
f.write("4.Generate out decode completed.")
|
| 128 |
+
except error:
|
| 129 |
+
traceback.print_exc()
|
| 130 |
+
|
| 131 |
+
finally:
|
| 132 |
+
f.close()
|
| 133 |
+
|
| 134 |
return prompter.get_response(output),DebugInfo
|
| 135 |
|
| 136 |
gr.Interface(
|
|
|
|
| 194 |
|
| 195 |
|
| 196 |
if __name__ == "__main__":
|
| 197 |
+
import traceback
|
| 198 |
+
try:
|
| 199 |
+
fire.Fire(main)
|
| 200 |
+
except error:
|
| 201 |
+
traceback.print_exc()
|
| 202 |
+
|