Spaces:
Sleeping
Sleeping
Update app.py
Browse filesEdited phi-4-reasoning base space to adapt to VeriThoughts.
app.py
CHANGED
@@ -4,26 +4,26 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStream
|
|
4 |
import torch
|
5 |
from threading import Thread
|
6 |
|
7 |
-
|
8 |
|
9 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
10 |
|
11 |
-
|
12 |
-
|
13 |
|
14 |
@spaces.GPU(duration=60)
|
15 |
def generate_response(user_message, max_tokens, temperature, top_k, top_p, repetition_penalty, history_state):
|
16 |
if not user_message.strip():
|
17 |
return history_state, history_state
|
18 |
|
19 |
-
#
|
20 |
-
model =
|
21 |
-
tokenizer =
|
22 |
start_tag = "<|im_start|>"
|
23 |
sep_tag = "<|im_sep|>"
|
24 |
end_tag = "<|im_end|>"
|
25 |
|
26 |
-
# Recommended prompt settings by
|
27 |
system_message = "Your role as an assistant involves thoroughly exploring questions through a systematic thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. Please structure your response into two main sections: Thought and Solution using the specified format: <think> {Thought section} </think> {Solution section}. In the Thought section, detail your reasoning process in steps. Each step should include detailed considerations such as analysing questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The Solution section should be logical, accurate, and concise and detail necessary steps needed to reach the conclusion. Now, try to solve the following question through the above guidelines:"
|
28 |
prompt = f"{start_tag}system{sep_tag}{system_message}{end_tag}"
|
29 |
for message in history_state:
|
@@ -70,22 +70,20 @@ def generate_response(user_message, max_tokens, temperature, top_k, top_p, repet
|
|
70 |
yield new_history, new_history
|
71 |
|
72 |
example_messages = {
|
73 |
-
"
|
74 |
"Logic puzzle": "Four people (Alex, Blake, Casey, and Dana) each have a different favorite color (red, blue, green, yellow) and a different favorite fruit (apple, banana, cherry, date). Given the following clues: 1) The person who likes red doesn't like dates. 2) Alex likes yellow. 3) The person who likes blue likes cherries. 4) Blake doesn't like apples or bananas. 5) Casey doesn't like yellow or green. Who likes what color and what fruit?",
|
75 |
-
"Physics problem": "A ball is thrown upward with an initial velocity of 15 m/s from a height of 2 meters above the ground. Assuming the acceleration due to gravity is 9.8 m/s², determine: 1) The maximum height the ball reaches. 2) The total time the ball is in the air before hitting the ground. 3) The velocity with which the ball hits the ground."
|
76 |
}
|
77 |
|
78 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
79 |
gr.Markdown(
|
80 |
"""
|
81 |
-
#
|
82 |
-
Welcome to
|
83 |
|
84 |
The model will provide responses with two sections:
|
85 |
1. **<think>**: A detailed step-by-step reasoning process showing its work
|
86 |
2. **Solution**: A concise, accurate final answer based on the reasoning
|
87 |
|
88 |
-
Try the example problems below to see how the model breaks down complex reasoning problems.
|
89 |
"""
|
90 |
)
|
91 |
|
@@ -142,7 +140,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
142 |
with gr.Row():
|
143 |
example1_button = gr.Button("Math reasoning")
|
144 |
example2_button = gr.Button("Logic puzzle")
|
145 |
-
example3_button = gr.Button("Physics problem")
|
146 |
|
147 |
submit_button.click(
|
148 |
fn=generate_response,
|
@@ -170,10 +167,5 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
170 |
inputs=None,
|
171 |
outputs=user_input
|
172 |
)
|
173 |
-
example3_button.click(
|
174 |
-
fn=lambda: gr.update(value=example_messages["Physics problem"]),
|
175 |
-
inputs=None,
|
176 |
-
outputs=user_input
|
177 |
-
)
|
178 |
|
179 |
demo.launch(ssr_mode=False)
|
|
|
4 |
import torch
|
5 |
from threading import Thread
|
6 |
|
7 |
+
veri_model_path = "nyu-dice-lab/VeriThoughts-Reasoning-7B"
|
8 |
|
9 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
10 |
|
11 |
+
veri_model = AutoModelForCausalLM.from_pretrained(veri_model_path, device_map="auto", torch_dtype="auto")
|
12 |
+
veri_tokenizer = AutoTokenizer.from_pretrained(veri_model_path)
|
13 |
|
14 |
@spaces.GPU(duration=60)
|
15 |
def generate_response(user_message, max_tokens, temperature, top_k, top_p, repetition_penalty, history_state):
|
16 |
if not user_message.strip():
|
17 |
return history_state, history_state
|
18 |
|
19 |
+
# model settings
|
20 |
+
model = veri_model
|
21 |
+
tokenizer = veri_tokenizer
|
22 |
start_tag = "<|im_start|>"
|
23 |
sep_tag = "<|im_sep|>"
|
24 |
end_tag = "<|im_end|>"
|
25 |
|
26 |
+
# Recommended prompt settings by Qwen
|
27 |
system_message = "Your role as an assistant involves thoroughly exploring questions through a systematic thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. Please structure your response into two main sections: Thought and Solution using the specified format: <think> {Thought section} </think> {Solution section}. In the Thought section, detail your reasoning process in steps. Each step should include detailed considerations such as analysing questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The Solution section should be logical, accurate, and concise and detail necessary steps needed to reach the conclusion. Now, try to solve the following question through the above guidelines:"
|
28 |
prompt = f"{start_tag}system{sep_tag}{system_message}{end_tag}"
|
29 |
for message in history_state:
|
|
|
70 |
yield new_history, new_history
|
71 |
|
72 |
example_messages = {
|
73 |
+
"Verilog example": "Design a 4-bit adder.",
|
74 |
"Logic puzzle": "Four people (Alex, Blake, Casey, and Dana) each have a different favorite color (red, blue, green, yellow) and a different favorite fruit (apple, banana, cherry, date). Given the following clues: 1) The person who likes red doesn't like dates. 2) Alex likes yellow. 3) The person who likes blue likes cherries. 4) Blake doesn't like apples or bananas. 5) Casey doesn't like yellow or green. Who likes what color and what fruit?",
|
|
|
75 |
}
|
76 |
|
77 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
78 |
gr.Markdown(
|
79 |
"""
|
80 |
+
# VeriThoughts-7B Chatbot
|
81 |
+
Welcome to VeriThoughts-7B! This is a reasoning model for Verilog code generation.
|
82 |
|
83 |
The model will provide responses with two sections:
|
84 |
1. **<think>**: A detailed step-by-step reasoning process showing its work
|
85 |
2. **Solution**: A concise, accurate final answer based on the reasoning
|
86 |
|
|
|
87 |
"""
|
88 |
)
|
89 |
|
|
|
140 |
with gr.Row():
|
141 |
example1_button = gr.Button("Math reasoning")
|
142 |
example2_button = gr.Button("Logic puzzle")
|
|
|
143 |
|
144 |
submit_button.click(
|
145 |
fn=generate_response,
|
|
|
167 |
inputs=None,
|
168 |
outputs=user_input
|
169 |
)
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
demo.launch(ssr_mode=False)
|