Handle missing streamed token metrics

This commit is contained in:
2026-05-10 02:40:00 +08:00
parent 307e2eb0e8
commit bdb08f6edc
3 changed files with 33 additions and 2 deletions

View File

@@ -310,7 +310,7 @@ def stream_chat_completion(
return StreamMetrics(
ttft_ms=ttft_ms,
tpot_ms=tpot_ms,
completion_tokens=used_tokens if used_tokens > 0 else None,
completion_tokens=used_tokens if used_tokens is not None and used_tokens > 0 else None,
completion_tokens_source=completion_tokens_source,
streamed_chunk_count=chunk_token_count,
)

View File

@@ -8,6 +8,7 @@ import statistics
import subprocess
import threading
import time
import traceback
from concurrent.futures import FIRST_COMPLETED, Future, ThreadPoolExecutor, wait
from dataclasses import dataclass
from pathlib import Path
@@ -596,6 +597,7 @@ def run_trial(trial_spec_path: Path) -> dict[str, Any]:
"best_request_count": None,
"failure_stage": failure_stage,
"failure_reason": str(exc),
"failure_traceback": traceback.format_exc(),
"probes": probe_history,
}
StudyStore.write_json(Path(trial.result_path), result)