Spaces:
Running
Running
Allen Park
commited on
Commit
·
60ffe71
1
Parent(s):
b5e9a85
add device=cuda; initialize tokenizer and model outside of function call; add inputs to device
Browse files
app.py
CHANGED
@@ -3,6 +3,11 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
3 |
import gradio as gr
|
4 |
import spaces
|
5 |
|
|
|
|
|
|
|
|
|
|
|
6 |
PROMPT = """
|
7 |
Given the following QUESTION, DOCUMENT and ANSWER you must analyze the provided answer and determine whether it is faithful to the contents of the DOCUMENT. The ANSWER must not offer new information beyond the context provided in the DOCUMENT. The ANSWER also must not contradict information provided in the DOCUMENT. Output your final verdict by strictly following this format: "PASS" if the answer is faithful to the DOCUMENT and "FAIL" if the answer is not faithful to the DOCUMENT. Show your reasoning.
|
8 |
|
@@ -23,13 +28,10 @@ ANSWER:
|
|
23 |
Your output should be in JSON FORMAT with the keys "REASONING" and "SCORE":
|
24 |
{{"REASONING": <your reasoning as bullet points>, "SCORE": <your final score>}}
|
25 |
"""
|
26 |
-
|
27 |
-
|
28 |
def model_call(question, document, answer):
|
29 |
NEW_FORMAT = PROMPT.format(question=question, document=document, answer=answer)
|
30 |
-
|
31 |
-
model = AutoModelForCausalLM.from_pretrained("PatronusAI/Llama-3-Patronus-Lynx-8B-Instruct", torch_dtype=torch.float16, device_map="auto")
|
32 |
-
inputs = tokenizer(NEW_FORMAT, return_tensors="pt")
|
33 |
model.generate(inputs.input_ids)
|
34 |
generated_text = tokenizer.decode(inputs.input_ids[0])
|
35 |
print(generated_text)
|
|
|
3 |
import gradio as gr
|
4 |
import spaces
|
5 |
|
6 |
+
device = "cuda" # for GPU usage or "cpu" for CPU usage
|
7 |
+
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained("PatronusAI/Llama-3-Patronus-Lynx-8B-Instruct")
|
9 |
+
model = AutoModelForCausalLM.from_pretrained("PatronusAI/Llama-3-Patronus-Lynx-8B-Instruct", torch_dtype=torch.float16, device_map="auto")
|
10 |
+
|
11 |
PROMPT = """
|
12 |
Given the following QUESTION, DOCUMENT and ANSWER you must analyze the provided answer and determine whether it is faithful to the contents of the DOCUMENT. The ANSWER must not offer new information beyond the context provided in the DOCUMENT. The ANSWER also must not contradict information provided in the DOCUMENT. Output your final verdict by strictly following this format: "PASS" if the answer is faithful to the DOCUMENT and "FAIL" if the answer is not faithful to the DOCUMENT. Show your reasoning.
|
13 |
|
|
|
28 |
Your output should be in JSON FORMAT with the keys "REASONING" and "SCORE":
|
29 |
{{"REASONING": <your reasoning as bullet points>, "SCORE": <your final score>}}
|
30 |
"""
|
31 |
+
@spaces.GPU()
|
|
|
32 |
def model_call(question, document, answer):
|
33 |
NEW_FORMAT = PROMPT.format(question=question, document=document, answer=answer)
|
34 |
+
inputs = tokenizer(NEW_FORMAT, return_tensors="pt").to(device)
|
|
|
|
|
35 |
model.generate(inputs.input_ids)
|
36 |
generated_text = tokenizer.decode(inputs.input_ids[0])
|
37 |
print(generated_text)
|