[Speculative decoding] Add periodic log with time spent in proposal/scoring/verification (#6963)

This commit is contained in:
Cade Daniel
2024-08-05 08:46:44 +00:00
committed by GitHub
parent c0d8f1636c
commit 82a1b1a82b
5 changed files with 125 additions and 35 deletions
+15
View File
@@ -1,3 +1,4 @@
import time
from contextlib import contextmanager
from typing import Dict, List, Optional, Tuple
@@ -214,3 +215,17 @@ def nvtx_range(msg, *args, **kwargs):
yield
finally:
torch.cuda.nvtx.range_pop()
class Timer:
"""Basic timer context manager for measuring CPU time.
"""
def __enter__(self):
self.start_time = time.time()
return self
def __exit__(self, exc_type, exc_value, traceback):
self.end_time = time.time()
self.elapsed_time_s = self.end_time - self.start_time
self.elapsed_time_ms = self.elapsed_time_s * 1000