@@ -1565,42 +1565,27 @@ def predict():
1565
1565
1566
1566
def benchmark (predictor , predictor_args , model_args ):
1567
1567
# 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 )]
1570
1570
1571
1571
batch_benchmark_texts = batchfy_text (benchmark_texts , predictor_args .batch_size )
1572
1572
print ("***********Start Benchmark**********" )
1573
1573
1574
- warmup_time = 2
1575
- test_time = 10
1574
+ warmup_time = 10
1575
+ test_time = 100
1576
1576
1577
1577
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 )
1592
1581
1593
1582
print ("***********Start Speed Test**********" )
1594
1583
start = time .perf_counter ()
1595
1584
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 ])
1604
1589
end = time .perf_counter ()
1605
1590
print ("Avg Elapse time is: " , (end - start ) / test_time )
1606
1591
print ("Output tokens is: " , output_tokens )
0 commit comments