From 18ec381863e355afa83beb5bffe05ae534c24d57 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Sun, 25 Apr 2021 08:58:16 +0000 Subject: [PATCH] support std log for ocr --- python/examples/pipeline/ocr/benchmark.py | 15 ++++-- python/examples/pipeline/ocr/benchmark.sh | 53 +++++++------------ .../ocr/benchmark_config.yaml.template | 32 +++++++++++ python/examples/pipeline/ocr/eval_top.sh | 9 ++++ 4 files changed, 70 insertions(+), 39 deletions(-) create mode 100644 python/examples/pipeline/ocr/benchmark_config.yaml.template create mode 100644 python/examples/pipeline/ocr/eval_top.sh diff --git a/python/examples/pipeline/ocr/benchmark.py b/python/examples/pipeline/ocr/benchmark.py index af1caae4..c6763c86 100644 --- a/python/examples/pipeline/ocr/benchmark.py +++ b/python/examples/pipeline/ocr/benchmark.py @@ -24,16 +24,19 @@ def parse_benchmark(filein, fileout): with open(fileout, "w") as fout: yaml.dump(res, fout, default_flow_style=False) -def gen_yml(device): +def gen_yml(device, gpu_id): fin = open("config.yml", "r") config = yaml.load(fin) fin.close() config["dag"]["tracer"] = {"interval_s": 10} if device == "gpu": config["op"]["det"]["local_service_conf"]["device_type"] = 1 - config["op"]["det"]["local_service_conf"]["devices"] = "2" + config["op"]["det"]["local_service_conf"]["devices"] = gpu_id config["op"]["rec"]["local_service_conf"]["device_type"] = 1 - config["op"]["rec"]["local_service_conf"]["devices"] = "2" + config["op"]["rec"]["local_service_conf"]["devices"] = gpu_id + else: + config["op"]["rec"]["local_service_conf"]["device_type"] = 0 + config["op"]["det"]["local_service_conf"]["device_type"] = 0 with open("config2.yml", "w") as fout: yaml.dump(config, fout, default_flow_style=False) @@ -85,7 +88,11 @@ if __name__ == "__main__": mode = sys.argv[2] # brpc/ local predictor thread = int(sys.argv[3]) device = sys.argv[4] - gen_yml(device) + if device == "gpu": + gpu_id = sys.argv[5] + gen_yml(device, gpu_id) + else: + gen_yml(device, "0") elif sys.argv[1] == "run": mode = sys.argv[2] # http/ rpc thread = int(sys.argv[3]) diff --git a/python/examples/pipeline/ocr/benchmark.sh b/python/examples/pipeline/ocr/benchmark.sh index d789b94b..4c9b64fd 100644 --- a/python/examples/pipeline/ocr/benchmark.sh +++ b/python/examples/pipeline/ocr/benchmark.sh @@ -1,59 +1,42 @@ export FLAGS_profile_pipeline=1 alias python3="python3.7" modelname="ocr" +use_gpu=0 +gpu_id="0" +benchmark_config_filename="benchmark_config.yaml" + # HTTP ps -ef | grep web_service | awk '{print $2}' | xargs kill -9 sleep 3 -python3 benchmark.py yaml local_predictor 1 gpu +if [ $use_gpu -eq 1 ]; then + python3 benchmark.py yaml local_predictor 1 gpu $gpu_id +else + python3 benchmark.py yaml local_predictor 1 cpu +fi rm -rf profile_log_$modelname -for thread_num in 1 8 16 +for thread_num in 1 do for batch_size in 1 do - echo "----Bert thread num: $thread_num batch size: $batch_size mode:http ----" >>profile_log_$modelname + echo "#----OCR thread num: $thread_num batch size: $batch_size mode:http use_gpu: $use_gpu----" >>profile_log_$modelname rm -rf PipelineServingLogs rm -rf cpu_utilization.py python3 web_service.py >web.log 2>&1 & sleep 3 - nvidia-smi --id=2 --query-compute-apps=used_memory --format=csv -lms 100 > gpu_use.log 2>&1 & - nvidia-smi --id=2 --query-gpu=utilization.gpu --format=csv -lms 100 > gpu_utilization.log 2>&1 & + nvidia-smi --id=${gpu_id} --query-compute-apps=used_memory --format=csv -lms 100 > gpu_use.log 2>&1 & + nvidia-smi --id=${gpu_id} --query-gpu=utilization.gpu --format=csv -lms 100 > gpu_utilization.log 2>&1 & echo "import psutil\ncpu_utilization=psutil.cpu_percent(1,False)\nprint('CPU_UTILIZATION:', cpu_utilization)\n" > cpu_utilization.py python3 benchmark.py run http $thread_num $batch_size python3 cpu_utilization.py >>profile_log_$modelname + python3 -m paddle_serving_server_gpu.profiler >>profile_log_$modelname ps -ef | grep web_service | awk '{print $2}' | xargs kill -9 + ps -ef | grep nvidia-smi | awk '{print $2}' | xargs kill -9 python3 benchmark.py dump benchmark.log benchmark.tmp mv benchmark.tmp benchmark.log - awk 'BEGIN {max = 0} {if(NR>1){if ($modelname > max) max=$modelname}} END {print "MAX_GPU_MEMORY:", max}' gpu_use.log >> profile_log_$modelname - awk 'BEGIN {max = 0} {if(NR>1){if ($modelname > max) max=$modelname}} END {print "GPU_UTILIZATION:", max}' gpu_utilization.log >> profile_log_$modelname + awk 'BEGIN {max = 0} {if(NR>1){if ($modelname > max) max=$modelname}} END {print "GPU_MEM:", max}' gpu_use.log >> profile_log_$modelname + awk 'BEGIN {max = 0} {if(NR>1){if ($modelname > max) max=$modelname}} END {print "GPU_UTIL:", max}' gpu_utilization.log >> profile_log_$modelname cat benchmark.log >> profile_log_$modelname + python3 -m paddle_serving_server_gpu.parse_profile --benchmark_cfg $benchmark_config_filename --benchmark_log profile_log_$modelname #rm -rf gpu_use.log gpu_utilization.log done done -# RPC -ps -ef | grep web_service | awk '{print $2}' | xargs kill -9 -sleep 3 -python3 benchmark.py yaml local_predictor 1 gpu - -for thread_num in 1 8 16 -do - for batch_size in 1 - do - echo "----Bert thread num: $thread_num batch size: $batch_size mode:rpc ----" >>profile_log_$modelname - rm -rf PipelineServingLogs - rm -rf cpu_utilization.py - python3 web_service.py >web.log 2>&1 & - sleep 3 - nvidia-smi --id=2 --query-compute-apps=used_memory --format=csv -lms 100 > gpu_use.log 2>&1 & - nvidia-smi --id=2 --query-gpu=utilization.gpu --format=csv -lms 100 > gpu_utilization.log 2>&1 & - echo "import psutil\ncpu_utilization=psutil.cpu_percent(1,False)\nprint('CPU_UTILIZATION:', cpu_utilization)\n" > cpu_utilization.py - python3 benchmark.py run rpc $thread_num $batch_size - python3 cpu_utilization.py >>profile_log_$modelname - ps -ef | grep web_service | awk '{print $2}' | xargs kill -9 - python3 benchmark.py dump benchmark.log benchmark.tmp - mv benchmark.tmp benchmark.log - awk 'BEGIN {max = 0} {if(NR>1){if ($modelname > max) max=$modelname}} END {print "MAX_GPU_MEMORY:", max}' gpu_use.log >> profile_log_$modelname - awk 'BEGIN {max = 0} {if(NR>1){if ($modelname > max) max=$modelname}} END {print "GPU_UTILIZATION:", max}' gpu_utilization.log >> profile_log_$modelname - #rm -rf gpu_use.log gpu_utilization.log - cat benchmark.log >> profile_log_$modelname - done -done diff --git a/python/examples/pipeline/ocr/benchmark_config.yaml.template b/python/examples/pipeline/ocr/benchmark_config.yaml.template new file mode 100644 index 00000000..ad8ecab6 --- /dev/null +++ b/python/examples/pipeline/ocr/benchmark_config.yaml.template @@ -0,0 +1,32 @@ + +cuda_version: "10.1" +cudnn_version: "7.6" +trt_version: "6.0" +python_version: "3.7" +gcc_version: "8.2" +paddle_version: "2.0.1" + +cpu: "Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz X12" +gpu: "T4" +xpu: "None" +api: "" +owner: "yingxiaoting" + +model_name: "ocr" +model_type: "static" +model_source: "PaddleOCR" +model_url: "" + +batch_size: 1 +num_of_samples: 1000 +input_shape: "3,32,X" + +runtime_device: "cpu" +ir_optim: true +enable_memory_optim: true +enable_tensorrt: false +precision: "fp32" +enable_mkldnn: false +cpu_math_library_num_threads: "" + + diff --git a/python/examples/pipeline/ocr/eval_top.sh b/python/examples/pipeline/ocr/eval_top.sh new file mode 100644 index 00000000..76a01425 --- /dev/null +++ b/python/examples/pipeline/ocr/eval_top.sh @@ -0,0 +1,9 @@ +sed -e "s/imagenet/${modelname}/g" benchmark_config.yaml.template >benchmark_config.yaml +sh benchmark.sh +mv std_benchmark.log std_benchmark.log.cpu +sed -e "s/use_gpu=0/use_gpu=1/g" benchmark.sh>benchmark_gpu.sh +sed -e "s/imagenet/${modelname}/g" -e "s/runtime_device: \"cpu\"/runtime_device: \"gpu\"/g" benchmark_config.yaml.template >benchmark_config.yaml +sh benchmark_gpu.sh +mv std_benchmark.log std_benchmark.log.gpu +cp std_benchmark.log.cpu /paddle/Cls/tools/serving_log/${modelname}.log.cpu +cp std_benchmark.log.gpu /paddle/Cls/tools/serving_log/${modelname}.log.gpu -- GitLab