Skip to content

Commit 4a9c766

Browse files
revert benchmark codes (PaddlePaddle#7871)
1 parent 2ac42ca commit 4a9c766

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

llm/predictor.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,42 +1565,27 @@ def predict():
15651565

15661566
def benchmark(predictor, predictor_args, model_args):
15671567
# Just construct a simple benchmark input. We pad input to the src_length.
1568-
test_texts = "who are you"
1569-
benchmark_texts = [test_texts + "<pad>" * (predictor_args.src_length) for _ in range(predictor_args.batch_size)]
1568+
test_texts = "hello world, how are you?"
1569+
benchmark_texts = [test_texts + "<pad>" * predictor_args.src_length for _ in range(predictor_args.batch_size)]
15701570

15711571
batch_benchmark_texts = batchfy_text(benchmark_texts, predictor_args.batch_size)
15721572
print("***********Start Benchmark**********")
15731573

1574-
warmup_time = 2
1575-
test_time = 10
1574+
warmup_time = 10
1575+
test_time = 100
15761576

15771577
print("***********Start Warmup**********")
1578-
for i in range(warmup_time):
1579-
print("warm up ", i)
1580-
for _, batch_source_text in enumerate(batch_benchmark_texts):
1581-
predictor.predict(batch_source_text)
1582-
1583-
from paddle import profiler
1584-
1585-
# 创建性能分析器相关的代码
1586-
def my_on_trace_ready(prof): # 定义回调函数,性能分析器结束采集数据时会被调用
1587-
callback = profiler.export_chrome_tracing("./profiler_demo") # 创建导出性能数据到profiler_demo文件夹的回调函数
1588-
callback(prof) # 执行该导出函数
1589-
prof.summary(sorted_by=profiler.SortedKeys.GPUTotal) # 打印表单,按GPUTotal排序表单项
1590-
1591-
p = profiler.Profiler(scheduler=[3, 4], on_trace_ready=my_on_trace_ready, timer_only=False) # 初始化Profiler对象
1578+
for _ in range(warmup_time):
1579+
for bs, batch_source_text in enumerate(batch_benchmark_texts):
1580+
outputs = predictor.predict(batch_source_text)
15921581

15931582
print("***********Start Speed Test**********")
15941583
start = time.perf_counter()
15951584
output_tokens = 0
1596-
p.start()
1597-
for i in range(test_time):
1598-
print("test ", i)
1599-
for _, batch_source_text in enumerate(batch_benchmark_texts):
1600-
predictor.predict(batch_source_text)
1601-
output_tokens += predictor_args.max_length * predictor_args.batch_size
1602-
p.step()
1603-
p.stop()
1585+
for _ in range(test_time):
1586+
for bs, batch_source_text in enumerate(batch_benchmark_texts):
1587+
outputs = predictor.predict(batch_source_text)
1588+
output_tokens += sum([len(output) for output in outputs])
16041589
end = time.perf_counter()
16051590
print("Avg Elapse time is: ", (end - start) / test_time)
16061591
print("Output tokens is: ", output_tokens)

0 commit comments

Comments
 (0)