Reduce max new tokens range
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import datetime
|
2 |
import os
|
3 |
-
import re
|
4 |
import random
|
|
|
5 |
from io import StringIO
|
6 |
|
7 |
import gradio as gr
|
@@ -25,8 +25,8 @@ model_names = list(model2endpoint.keys())
|
|
25 |
|
26 |
|
27 |
def randomize_seed_generator():
|
28 |
-
|
29 |
-
|
30 |
|
31 |
|
32 |
def save_inputs_and_outputs(now, inputs, outputs, generate_kwargs, model):
|
@@ -107,9 +107,9 @@ def generate(
|
|
107 |
|
108 |
if not RETRY_FLAG:
|
109 |
history.append(user_message)
|
110 |
-
seed=42
|
111 |
else:
|
112 |
-
seed=randomize_seed_generator()
|
113 |
|
114 |
past_messages = []
|
115 |
for data in chatbot:
|
@@ -221,28 +221,28 @@ def process_example(args):
|
|
221 |
|
222 |
# Regenerate response
|
223 |
def retry_last_answer(
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
if chat and history:
|
237 |
-
# Removing the previous conversation from chat
|
238 |
chat.pop(-1)
|
239 |
-
# Removing bot response from the history
|
240 |
history.pop(-1)
|
241 |
-
# Setting up a flag to capture a retry
|
242 |
RETRY_FLAG = True
|
243 |
# Getting last message from user
|
244 |
user_message = history[-1]
|
245 |
-
|
246 |
yield from generate(
|
247 |
RETRY_FLAG,
|
248 |
selected_model,
|
@@ -255,7 +255,8 @@ def retry_last_answer(
|
|
255 |
top_p,
|
256 |
max_new_tokens,
|
257 |
repetition_penalty,
|
258 |
-
do_save
|
|
|
259 |
|
260 |
|
261 |
title = """<h1 align="center">⭐ StarChat Playground 💬</h1>"""
|
@@ -321,7 +322,7 @@ with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
|
|
321 |
send_button = gr.Button("Send", elem_id="send-btn", visible=True)
|
322 |
|
323 |
regenerate_button = gr.Button("Regenerate", elem_id="retry-btn", visible=True)
|
324 |
-
|
325 |
delete_turn_button = gr.Button("Delete last turn", elem_id="delete-btn", visible=True)
|
326 |
|
327 |
clear_chat_button = gr.Button("Clear chat", elem_id="clear-btn", visible=True)
|
@@ -356,9 +357,9 @@ with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
|
|
356 |
)
|
357 |
max_new_tokens = gr.Slider(
|
358 |
label="Max new tokens",
|
359 |
-
value=
|
360 |
minimum=0,
|
361 |
-
maximum=
|
362 |
step=4,
|
363 |
interactive=True,
|
364 |
info="The maximum numbers of new tokens",
|
@@ -387,7 +388,7 @@ with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
|
|
387 |
|
388 |
history = gr.State([])
|
389 |
RETRY_FLAG = gr.Checkbox(value=False, visible=False)
|
390 |
-
|
391 |
# To clear out "message" input textbox and use this to regenerate message
|
392 |
last_user_message = gr.State("")
|
393 |
|
@@ -430,8 +431,8 @@ with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
|
|
430 |
)
|
431 |
|
432 |
regenerate_button.click(
|
433 |
-
retry_last_answer,
|
434 |
-
inputs
|
435 |
selected_model,
|
436 |
system_message,
|
437 |
user_message,
|
@@ -444,9 +445,9 @@ with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
|
|
444 |
repetition_penalty,
|
445 |
do_save,
|
446 |
],
|
447 |
-
outputs
|
448 |
)
|
449 |
-
|
450 |
delete_turn_button.click(delete_last_turn, [chatbot, history], [chatbot, history])
|
451 |
clear_chat_button.click(clear_chat, outputs=[chatbot, history])
|
452 |
selected_model.change(clear_chat, outputs=[chatbot, history])
|
|
|
1 |
import datetime
|
2 |
import os
|
|
|
3 |
import random
|
4 |
+
import re
|
5 |
from io import StringIO
|
6 |
|
7 |
import gradio as gr
|
|
|
25 |
|
26 |
|
27 |
def randomize_seed_generator():
|
28 |
+
seed = random.randint(0, 1000000)
|
29 |
+
return seed
|
30 |
|
31 |
|
32 |
def save_inputs_and_outputs(now, inputs, outputs, generate_kwargs, model):
|
|
|
107 |
|
108 |
if not RETRY_FLAG:
|
109 |
history.append(user_message)
|
110 |
+
seed = 42
|
111 |
else:
|
112 |
+
seed = randomize_seed_generator()
|
113 |
|
114 |
past_messages = []
|
115 |
for data in chatbot:
|
|
|
221 |
|
222 |
# Regenerate response
|
223 |
def retry_last_answer(
|
224 |
+
selected_model,
|
225 |
+
system_message,
|
226 |
+
user_message,
|
227 |
+
chat,
|
228 |
+
history,
|
229 |
+
temperature,
|
230 |
+
top_k,
|
231 |
+
top_p,
|
232 |
+
max_new_tokens,
|
233 |
+
repetition_penalty,
|
234 |
+
do_save,
|
235 |
+
):
|
236 |
if chat and history:
|
237 |
+
# Removing the previous conversation from chat
|
238 |
chat.pop(-1)
|
239 |
+
# Removing bot response from the history
|
240 |
history.pop(-1)
|
241 |
+
# Setting up a flag to capture a retry
|
242 |
RETRY_FLAG = True
|
243 |
# Getting last message from user
|
244 |
user_message = history[-1]
|
245 |
+
|
246 |
yield from generate(
|
247 |
RETRY_FLAG,
|
248 |
selected_model,
|
|
|
255 |
top_p,
|
256 |
max_new_tokens,
|
257 |
repetition_penalty,
|
258 |
+
do_save,
|
259 |
+
)
|
260 |
|
261 |
|
262 |
title = """<h1 align="center">⭐ StarChat Playground 💬</h1>"""
|
|
|
322 |
send_button = gr.Button("Send", elem_id="send-btn", visible=True)
|
323 |
|
324 |
regenerate_button = gr.Button("Regenerate", elem_id="retry-btn", visible=True)
|
325 |
+
|
326 |
delete_turn_button = gr.Button("Delete last turn", elem_id="delete-btn", visible=True)
|
327 |
|
328 |
clear_chat_button = gr.Button("Clear chat", elem_id="clear-btn", visible=True)
|
|
|
357 |
)
|
358 |
max_new_tokens = gr.Slider(
|
359 |
label="Max new tokens",
|
360 |
+
value=512,
|
361 |
minimum=0,
|
362 |
+
maximum=1024,
|
363 |
step=4,
|
364 |
interactive=True,
|
365 |
info="The maximum numbers of new tokens",
|
|
|
388 |
|
389 |
history = gr.State([])
|
390 |
RETRY_FLAG = gr.Checkbox(value=False, visible=False)
|
391 |
+
|
392 |
# To clear out "message" input textbox and use this to regenerate message
|
393 |
last_user_message = gr.State("")
|
394 |
|
|
|
431 |
)
|
432 |
|
433 |
regenerate_button.click(
|
434 |
+
retry_last_answer,
|
435 |
+
inputs=[
|
436 |
selected_model,
|
437 |
system_message,
|
438 |
user_message,
|
|
|
445 |
repetition_penalty,
|
446 |
do_save,
|
447 |
],
|
448 |
+
outputs=[chatbot, history, last_user_message, user_message],
|
449 |
)
|
450 |
+
|
451 |
delete_turn_button.click(delete_last_turn, [chatbot, history], [chatbot, history])
|
452 |
clear_chat_button.click(clear_chat, outputs=[chatbot, history])
|
453 |
selected_model.change(clear_chat, outputs=[chatbot, history])
|