finetune_inference_benchmark.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. # Copyright (c) 2019 NVIDIA CORPORATION. All rights reserved.
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. task=${1:-"squad"}
  15. #Edit to save logs & checkpoints in a different directory
  16. RESULTS_DIR=/results
  17. if [ ! -d "$RESULTS_DIR" ] ; then
  18. echo "Error! $RESULTS_DIR directory missing."
  19. exit -1
  20. fi
  21. echo "Results directory set as " $RESULTS_DIR
  22. LOGFILE="${RESULTS_DIR}/${task}_inference_benchmark_bert_${bert_model}.log"
  23. tmp_file="/tmp/${task}_inference_benchmark.log"
  24. if [ "$task" = "squad" ] ; then
  25. export SQUAD_DIR=data/download/squad/v1.1
  26. echo "Squad directory set as " $SQUAD_DIR
  27. echo "Inference performance benchmarking for BERT $bert_model from $BERT_DIR" >> $LOGFILE
  28. for bert_model in "base" "large"; do
  29. echo "Model Sequence-Length Batch-size Precision Throughput-Average(sent/sec) Latency-Average(ms) Latency-50%(ms) Latency-90%(ms) Latency-95%(ms) Latency-99%(ms) Latency-100%(ms)" >> $LOGFILE
  30. if [ "$bert_model" = "large" ] ; then
  31. export BERT_DIR=data/download/google_pretrained_weights/uncased_L-24_H-1024_A-16
  32. else
  33. export BERT_DIR=data/download/google_pretrained_weights/uncased_L-12_H-768_A-12
  34. fi
  35. echo "BERT directory set as " $BERT_DIR
  36. init_checkpoint="$BERT_DIR/bert_model.ckpt"
  37. for seq_len in 128 384; do
  38. for bs in 1 2 4 8; do
  39. for use_fp16 in "--amp" "--noamp"; do
  40. python run_squad.py \
  41. --vocab_file=$BERT_DIR/vocab.txt \
  42. --bert_config_file=$BERT_DIR/bert_config.json \
  43. --init_checkpoint=$init_checkpoint \
  44. --do_predict=True \
  45. --predict_file=$SQUAD_DIR/dev-v1.1.json \
  46. --predict_batch_size=$bs \
  47. --max_seq_length=$seq_len \
  48. --doc_stride=128 \
  49. --output_dir=${RESULTS_DIR} \
  50. "$use_fp16" \
  51. --use_xla --num_eval_iterations=1024 |& tee $tmp_file
  52. perf=`cat $tmp_file | grep -F 'INFO:tensorflow:Throughput Average (sentences/sec) =' | tail -1 | awk -F'= ' '{print $2}'`
  53. la=`cat $tmp_file | grep -F 'INFO:tensorflow:Latency Average (ms)' | awk -F'= ' '{print $2}'`
  54. l50=`cat $tmp_file | grep -F 'INFO:tensorflow:Latency Confidence Level 50 (ms)' | awk -F'= ' '{print $2}'`
  55. l90=`cat $tmp_file | grep -F 'INFO:tensorflow:Latency Confidence Level 90 (ms)' | awk -F'= ' '{print $2}'`
  56. l95=`cat $tmp_file | grep -F 'INFO:tensorflow:Latency Confidence Level 95 (ms)' | awk -F'= ' '{print $2}'`
  57. l99=`cat $tmp_file | grep -F 'INFO:tensorflow:Latency Confidence Level 99 (ms)' | awk -F'= ' '{print $2}'`
  58. l100=`cat $tmp_file | grep -F 'INFO:tensorflow:Latency Confidence Level 100 (ms)' | awk -F'= ' '{print $2}'`
  59. echo "$bert_model $seq_len $bs $use_fp16 $perf $la $l50 $l90 $l95 $l99 $l100" >> $LOGFILE
  60. done
  61. done
  62. done
  63. else
  64. echo "Benchmarking for " $task "currently not supported. Sorry!"
  65. fi