|
6 | 6 | import re |
7 | 7 | from typing import Optional, Tuple, List |
8 | 8 | import os |
| 9 | +import time |
9 | 10 | from tempfile import NamedTemporaryFile |
10 | 11 | import numpy as np |
11 | 12 | from PIL import Image |
@@ -596,13 +597,25 @@ def generate( |
596 | 597 | troubleshooting_lines.append(f"[INFO] Sampling: top_k={top_k}, top_p={top_p}") |
597 | 598 | troubleshooting_lines.append("[INFO] Generating...") |
598 | 599 |
|
| 600 | + start_time = time.time() |
599 | 601 | # Generate response |
600 | 602 | response = model.respond(chat, config=gen_config) |
601 | 603 | response_text = str(response) |
602 | 604 |
|
603 | 605 | troubleshooting_lines.append("[INFO] Generation complete") |
604 | 606 | troubleshooting_lines.append(f"[INFO] Raw response length: {len(response_text)} chars") |
605 | 607 |
|
| 608 | + # Extract inference statistics |
| 609 | + tokens_per_sec = getattr(response.stats, 'tokens_per_second', 0.0) |
| 610 | + input_tokens = getattr(response.stats, 'prompt_tokens_count', 0) |
| 611 | + output_tokens = getattr(response.stats, 'predicted_tokens_count', 0) |
| 612 | + elapsed = time.time() - start_time |
| 613 | + |
| 614 | + troubleshooting_lines.append(f"[INFO] Tokens per second: {tokens_per_sec:.2f}") |
| 615 | + troubleshooting_lines.append(f"[INFO] Input tokens: {input_tokens}") |
| 616 | + troubleshooting_lines.append(f"[INFO] Output tokens: {output_tokens}") |
| 617 | + troubleshooting_lines.append(f"[INFO] Total time: {elapsed:.2f}s") |
| 618 | + |
606 | 619 | # Extract reasoning based on mode |
607 | 620 | final_response = response_text |
608 | 621 | reasoning = "" |
|
0 commit comments