Skip to content

Commit

Permalink
Fix benchmark (PaddlePaddle#451)
Browse files Browse the repository at this point in the history
* fix benchmark

* add fomm and stylegan benchmark
  • Loading branch information
lzzyzlbb authored Oct 29, 2021
1 parent 5fd051d commit 32132fa
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
51 changes: 51 additions & 0 deletions benchmark/analysis_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# encoding=utf-8 vi:ts=4:sw=4:expandtab:ft=python

import re
import sys
import json

def analyze(model_name, log_file, res_log_file):
time_pat = re.compile(r"ips: (.*) images/s")

logs = open(log_file).readlines()
logs = ";".join(logs)
time_res = time_pat.findall(logs)

fail_flag = 0
run_mode = ""
gpu_num = 0
ips = 0

if time_res == []:
fail_flag = 1
else:
gpu_num = log_file.split('_')[-1]
run_mode = "sp" if gpu_num == 1 else "mp"

skip_num = 4
total_time = 0
for i in range(skip_num, len(time_res)):
total_time += float(time_res[i])
ips = total_time / (len(time_res) - skip_num)

info = {"log_file": log_file, "model_name": model_name, "mission_name": "图像生成",
"direction_id": 0, "run_mode": run_mode, "index": 1, "gpu_num": gpu_num,
"FINAL_RESULT": ips, "JOB_FAIL_FLAG": fail_flag, "UNIT": "images/s"}
json_info = json.dumps(info)
with open(res_log_file, "w") as of:
of.write(json_info)

if __name__ == "__main__":
if len(sys.argv) != 4:
print("Usage:" + sys.argv[0] + " model_name path/to/log/file path/to/res/log/file")
sys.exit()

model_name = sys.argv[1]
log_file = sys.argv[2]
res_log_file = sys.argv[3]

analyze(model_name, log_file, res_log_file)


9 changes: 9 additions & 0 deletions benchmark/run_benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ function _set_params(){
arr=(${device})
num_gpu_devices=${#arr[*]}
log_file=${run_log_path}/${model_name}_${run_mode}_bs${batch_size}_${fp_item}_${num_gpu_devices}
res_log_file=${run_log_path}/${model_name}_${run_mode}_bs${batch_size}_${fp_item}_${num_gpu_devices}_speed
}

function _analysis_log(){
python benchmark/analysis_log.py ${model_name} ${log_file} ${res_log_file}
}

function _train(){
echo "Train on ${num_gpu_devices} GPUs"
echo "current CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES, gpus=$num_gpu_devices, batch_size=$batch_size"
Expand Down Expand Up @@ -49,6 +55,9 @@ function _train(){
rm ${log_file}
cp mylog/workerlog.0 ${log_file}
fi

_analysis_log

}

_set_params $@
Expand Down

0 comments on commit 32132fa

Please sign in to comment.