From 20b969b412b43958eb1b9ba378d2b86ae0494146 Mon Sep 17 00:00:00 2001 From: Ashish <1856117+ashishdatta@users.noreply.github.com> Date: Fri, 26 Jan 2024 15:11:38 -0700 Subject: [PATCH] Replace time.time() with time.perf_counter() as it is more suited for benchmarking (#380) --- llms/mlx_lm/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llms/mlx_lm/utils.py b/llms/mlx_lm/utils.py index 44f3abd4..98ec7980 100644 --- a/llms/mlx_lm/utils.py +++ b/llms/mlx_lm/utils.py @@ -149,7 +149,7 @@ def generate( prompt = mx.array(tokenizer.encode(prompt)) - tic = time.time() + tic = time.perf_counter() tokens = [] skip = 0 REPLACEMENT_CHAR = "\ufffd" @@ -158,8 +158,8 @@ def generate( if token == tokenizer.eos_token_id: break if n == 0: - prompt_time = time.time() - tic - tic = time.time() + prompt_time = time.perf_counter() - tic + tic = time.perf_counter() tokens.append(token.item()) if verbose: @@ -175,7 +175,7 @@ def generate( if verbose: print(tokens[skip:], flush=True) - gen_time = time.time() - tic + gen_time = time.perf_counter() - tic print("=" * 10) if len(tokens) == 0: print("No tokens generated for this prompt")