Spaces:
Running on Zero
Running on Zero
ukung commited on
Commit ·
4878828
1
Parent(s): 38f5fa5
fix: jangan paksa thinking & tampilkan raw output saat thinking off
Browse files
app.py
CHANGED
|
@@ -284,9 +284,9 @@ def run_inference_raw(user_prompt, max_tokens, temperature, top_k, top_p, rep_pe
|
|
| 284 |
model = model_manager.model
|
| 285 |
thinking = model_manager.thinking
|
| 286 |
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
inputs = tokenizer([user_prompt], return_tensors="pt")
|
| 291 |
|
| 292 |
if use_cuda:
|
|
@@ -343,19 +343,24 @@ def run_inference_raw(user_prompt, max_tokens, temperature, top_k, top_p, rep_pe
|
|
| 343 |
|
| 344 |
if thinking:
|
| 345 |
start_tok, end_tok, think_label, answer_label = thinking
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
|
| 360 |
device_label = "CUDA" if use_cuda else "CPU"
|
| 361 |
yield base_display + display_text, f"Speed: {tps:.2f} tokens/sec ({device_label})"
|
|
|
|
| 284 |
model = model_manager.model
|
| 285 |
thinking = model_manager.thinking
|
| 286 |
|
| 287 |
+
# NOTE: Jangan paksa thinking dengan append start-token. Kalau
|
| 288 |
+
# enable_thinking=False sudah dipakai di format_prompt (Chat mode),
|
| 289 |
+
# append ini justru membatalkannya dan memaksa model berpikir.
|
| 290 |
inputs = tokenizer([user_prompt], return_tensors="pt")
|
| 291 |
|
| 292 |
if use_cuda:
|
|
|
|
| 343 |
|
| 344 |
if thinking:
|
| 345 |
start_tok, end_tok, think_label, answer_label = thinking
|
| 346 |
+
# Hanya bungkus sebagai thinking kalau output BENAR-BENAR
|
| 347 |
+
# mengandung token thinking. Kalau thinking dimatikan
|
| 348 |
+
# (enable_thinking=False), output adalah teks biasa (mis. JSON)
|
| 349 |
+
# dan harus ditampilkan apa adanya tanpa prefix "> " / "*...*".
|
| 350 |
+
if start_tok in generated_text or end_tok in generated_text:
|
| 351 |
+
clean = generated_text.replace("<s>", "").replace("</s>", "")
|
| 352 |
+
clean = clean.replace(start_tok, "").replace(end_tok, "")
|
| 353 |
+
clean = clean.replace("<|begin_of_solution|>", "").replace("<|end_of_solution|>", "")
|
| 354 |
+
if end_tok in generated_text:
|
| 355 |
+
parts = generated_text.split(end_tok, 1)
|
| 356 |
+
think_raw = parts[0].replace(start_tok, "").strip()
|
| 357 |
+
answer_raw = parts[1].replace("<|begin_of_solution|>", "").replace("<|end_of_solution|>", "").strip()
|
| 358 |
+
think_block = "\n".join("> " + line for line in think_raw.splitlines()) if think_raw else "> _thinking..._"
|
| 359 |
+
display_text = f"{think_block}\n\n**{answer_raw}**"
|
| 360 |
+
else:
|
| 361 |
+
think_raw = clean.strip()
|
| 362 |
+
think_block = "\n".join("> " + line for line in think_raw.splitlines()) if think_raw else "> _thinking..._"
|
| 363 |
+
display_text = f"{think_block}\n\n*...*"
|
| 364 |
|
| 365 |
device_label = "CUDA" if use_cuda else "CPU"
|
| 366 |
yield base_display + display_text, f"Speed: {tps:.2f} tokens/sec ({device_label})"
|