tarrog commited on
Commit
72eeeba
·
verified ·
1 Parent(s): 3a785f9

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -137,8 +137,18 @@ class StopOnEvent(StoppingCriteria):
137
 
138
  def gpu_duration(message, history, system_prompt=GENERAL, thinking="none", max_new_tokens=512,
139
  temperature=1.0, top_p=0.95, *args, **kwargs) -> int:
140
- """Initial bounded reservation; tune after measuring live requests."""
141
- return min(120, 30 + int(max(64, min(2048, int(max_new_tokens)))) // 25)
 
 
 
 
 
 
 
 
 
 
142
 
143
 
144
  @spaces.GPU(duration=gpu_duration)
@@ -168,7 +178,7 @@ def chat(message: str, history: list, system_prompt: str = GENERAL, thinking: st
168
  stop = threading.Event()
169
  streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=False, timeout=5)
170
  outcome = {}
171
- budget = gpu_duration(message, history, system_prompt, thinking, max_new_tokens, temperature, top_p) - 8
172
  started = time.perf_counter()
173
 
174
  def generate():
@@ -278,7 +288,7 @@ with gr.Blocks(title="Spark 한국어 대화 실험실") as demo:
278
  with gr.Column(scale=3):
279
  chatbot = gr.Chatbot(height=470, show_label=False, placeholder="예시를 고르거나 메시지를 입력하세요.")
280
  with gr.Row():
281
- message = gr.Textbox(placeholder="한국어로 말을 걸어보세요", show_label=False, lines=2, scale=6)
282
  send = gr.Button("보내기", variant="primary", scale=1)
283
  with gr.Row():
284
  stop_button = gr.Button("중지")
 
137
 
138
  def gpu_duration(message, history, system_prompt=GENERAL, thinking="none", max_new_tokens=512,
139
  temperature=1.0, top_p=0.95, *args, **kwargs) -> int:
140
+ """Budget from live ~32 tokens/s plus a margin for input processing.
141
+
142
+ The 2026-10-26 smoke tests took 1.22, 1.90 and 7.94 seconds. The linear
143
+ output allowance adds ~40% to the longest test's rate; long inputs get
144
+ an extra prefill margin. This estimates a reservation, not a speed promise.
145
+ """
146
+ from math import ceil
147
+
148
+ limit = max(64, min(2048, int(max_new_tokens)))
149
+ batch, _ = build_inputs(plain_text(message).strip(), history, system_prompt, thinking)
150
+ input_tokens = int(batch["input_ids"].shape[-1])
151
+ return min(120, max(15, ceil(5 + limit * 0.045 + input_tokens * 0.003)))
152
 
153
 
154
  @spaces.GPU(duration=gpu_duration)
 
178
  stop = threading.Event()
179
  streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=False, timeout=5)
180
  outcome = {}
181
+ budget = gpu_duration(message, history, system_prompt, thinking, max_new_tokens, temperature, top_p) - 5
182
  started = time.perf_counter()
183
 
184
  def generate():
 
288
  with gr.Column(scale=3):
289
  chatbot = gr.Chatbot(height=470, show_label=False, placeholder="예시를 고르거나 메시지를 입력하세요.")
290
  with gr.Row():
291
+ message = gr.Textbox(label="메시지", placeholder="한국어로 말을 걸어보세요", show_label=False, lines=2, scale=6)
292
  send = gr.Button("보내기", variant="primary", scale=1)
293
  with gr.Row():
294
  stop_button = gr.Button("중지")