llm.timer /home/runner/work/llm-pytorch/llm-pytorch/llm/timer.py Performance timer. Timer ¶ Timer(synchronize: bool = False) Performance timer. Parameters: synchronize (bool, default: False ) – Synchronize CUDA workers before and after the timer. Source code in llm/timer.py 17 18 19 20def __init__(self, synchronize: bool = False) -> None: self._synchronize = synchronize self._history: list[float] = [] self._start_time = time.time() start() ¶ start() -> None Start the timer. Source code in llm/timer.py 22 23 24 25 26def start(self) -> None: """Start the timer.""" if torch.cuda.is_available() and self._synchronize: torch.cuda.synchronize() self._start_time = time.time() stop() ¶ stop() -> float Stop the timer and return the elapsed time. Source code in llm/timer.py 28 29 30 31 32 33 34 35def stop(self) -> float: """Stop the timer and return the elapsed time.""" if torch.cuda.is_available() and self._synchronize: torch.cuda.synchronize() elapsed = time.time() - self._start_time self._history.append(elapsed) return elapsed lap() ¶ lap() -> float Log a lap of the timer. Source code in llm/timer.py 37 38 39 40 41def lap(self) -> float: """Log a lap of the timer.""" lap_time = self.stop() self.start() return lap_time get_history() ¶ get_history() -> list[float] Get the history of all lap times. Source code in llm/timer.py 43 44 45def get_history(self) -> list[float]: """Get the history of all lap times.""" return self._history get_history_sum() ¶ get_history_sum() -> float Get the sum of all lap times. Source code in llm/timer.py 47 48 49def get_history_sum(self) -> float: """Get the sum of all lap times.""" return sum(self._history) get_history_mean() ¶ get_history_mean() -> float Get the mean of all lap times. Source code in llm/timer.py 51 52 53def get_history_mean(self) -> float: """Get the mean of all lap times.""" return sum(self._history) / len(self._history)