Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from lmdeploy.serve.gradio.turbomind_coupled import *
|
2 |
+
from lmdeploy.messages import TurbomindEngineConfig
|
3 |
+
|
4 |
+
backend_config = TurbomindEngineConfig(max_batch_size=1, cache_max_entry_count=0.05, model_format='awq')
|
5 |
+
model_path = 'internlm/internlm2-chat-20b-4bits'
|
6 |
+
|
7 |
+
InterFace.async_engine = AsyncEngine(
|
8 |
+
model_path=model_path,
|
9 |
+
backend='turbomind',
|
10 |
+
backend_config=backend_config,
|
11 |
+
tp=1)
|
12 |
+
|
13 |
+
with gr.Blocks(css=CSS, theme=THEME) as demo:
|
14 |
+
state_chatbot = gr.State([])
|
15 |
+
state_session_id = gr.State(0)
|
16 |
+
|
17 |
+
with gr.Column(elem_id='container'):
|
18 |
+
gr.Markdown('## LMDeploy Playground')
|
19 |
+
|
20 |
+
chatbot = gr.Chatbot(
|
21 |
+
elem_id='chatbot',
|
22 |
+
label=InterFace.async_engine.engine.model_name)
|
23 |
+
instruction_txtbox = gr.Textbox(
|
24 |
+
placeholder='Please input the instruction',
|
25 |
+
label='Instruction')
|
26 |
+
with gr.Row():
|
27 |
+
cancel_btn = gr.Button(value='Cancel', interactive=False)
|
28 |
+
reset_btn = gr.Button(value='Reset')
|
29 |
+
with gr.Row():
|
30 |
+
request_output_len = gr.Slider(1,
|
31 |
+
2048,
|
32 |
+
value=512,
|
33 |
+
step=1,
|
34 |
+
label='Maximum new tokens')
|
35 |
+
top_p = gr.Slider(0.01, 1, value=0.8, step=0.01, label='Top_p')
|
36 |
+
temperature = gr.Slider(0.01,
|
37 |
+
1.5,
|
38 |
+
value=0.7,
|
39 |
+
step=0.01,
|
40 |
+
label='Temperature')
|
41 |
+
|
42 |
+
send_event = instruction_txtbox.submit(chat_stream_local, [
|
43 |
+
instruction_txtbox, state_chatbot, cancel_btn, reset_btn,
|
44 |
+
state_session_id, top_p, temperature, request_output_len
|
45 |
+
], [state_chatbot, chatbot, cancel_btn, reset_btn])
|
46 |
+
instruction_txtbox.submit(
|
47 |
+
lambda: gr.Textbox.update(value=''),
|
48 |
+
[],
|
49 |
+
[instruction_txtbox],
|
50 |
+
)
|
51 |
+
cancel_btn.click(
|
52 |
+
cancel_local_func,
|
53 |
+
[state_chatbot, cancel_btn, reset_btn, state_session_id],
|
54 |
+
[state_chatbot, cancel_btn, reset_btn],
|
55 |
+
cancels=[send_event])
|
56 |
+
|
57 |
+
reset_btn.click(reset_local_func,
|
58 |
+
[instruction_txtbox, state_chatbot, state_session_id],
|
59 |
+
[state_chatbot, chatbot, instruction_txtbox],
|
60 |
+
cancels=[send_event])
|
61 |
+
|
62 |
+
def init():
|
63 |
+
with InterFace.lock:
|
64 |
+
InterFace.global_session_id += 1
|
65 |
+
new_session_id = InterFace.global_session_id
|
66 |
+
return new_session_id
|
67 |
+
|
68 |
+
demo.load(init, inputs=None, outputs=[state_session_id])
|
69 |
+
|
70 |
+
demo.queue(concurrency_count=InterFace.async_engine.instance_num,
|
71 |
+
max_size=100).launch()
|