mirror of
https://github.com/ml-explore/mlx-examples.git
synced 2025-07-04 15:56:16 +08:00
Replace time.time() with time.perf_counter() as it is more suited for benchmarking (#380)
This commit is contained in:
parent
5aa652d3c2
commit
20b969b412
@ -149,7 +149,7 @@ def generate(
|
|||||||
|
|
||||||
prompt = mx.array(tokenizer.encode(prompt))
|
prompt = mx.array(tokenizer.encode(prompt))
|
||||||
|
|
||||||
tic = time.time()
|
tic = time.perf_counter()
|
||||||
tokens = []
|
tokens = []
|
||||||
skip = 0
|
skip = 0
|
||||||
REPLACEMENT_CHAR = "\ufffd"
|
REPLACEMENT_CHAR = "\ufffd"
|
||||||
@ -158,8 +158,8 @@ def generate(
|
|||||||
if token == tokenizer.eos_token_id:
|
if token == tokenizer.eos_token_id:
|
||||||
break
|
break
|
||||||
if n == 0:
|
if n == 0:
|
||||||
prompt_time = time.time() - tic
|
prompt_time = time.perf_counter() - tic
|
||||||
tic = time.time()
|
tic = time.perf_counter()
|
||||||
tokens.append(token.item())
|
tokens.append(token.item())
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
@ -175,7 +175,7 @@ def generate(
|
|||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print(tokens[skip:], flush=True)
|
print(tokens[skip:], flush=True)
|
||||||
gen_time = time.time() - tic
|
gen_time = time.perf_counter() - tic
|
||||||
print("=" * 10)
|
print("=" * 10)
|
||||||
if len(tokens) == 0:
|
if len(tokens) == 0:
|
||||||
print("No tokens generated for this prompt")
|
print("No tokens generated for this prompt")
|
||||||
|
Loading…
Reference in New Issue
Block a user