xref: /aosp_15_r20/external/pytorch/benchmarks/inference/runner.sh (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1#!/bin/bash
2
3if [ $# -ne 1 ]; then
4  echo "Usage: $0 {experiment_name}"
5  exit 1
6fi
7
8experiment_name="$1"
9benchmark_script="server.py"
10checkpoint_file="resnet18-f37072fd.pth"
11downloaded_checkpoint=false
12num_iters=10
13
14batch_size_values=(1 32 64 128 256)
15compile_values=(true false)
16
17if [ -f $checkpoint_file ]; then
18  echo "Checkpoint exists."
19else
20  downloaded_checkpoint=true
21  echo "Downloading checkpoint..."
22  wget https://download.pytorch.org/models/resnet18-f37072fd.pth
23fi
24
25for batch_size in "${batch_size_values[@]}"; do
26  for compile in "${compile_values[@]}"; do
27    echo "Running benchmark for batch size ${batch_size} and compile=${compile}..."
28    output_file="output_${batch_size}_${compile}.csv"
29    if [ -e "./results/$output_file" ]; then
30      rm "./results/$output_file"
31    fi
32    for i in $(seq 1 $num_iters); do
33      if [ "$compile" = true ]; then
34        python -W ignore "$benchmark_script" --batch_size "$batch_size" --output_file "$output_file" --compile
35      else
36        python -W ignore "$benchmark_script" --batch_size "$batch_size" --output_file "$output_file" --no-compile
37      fi
38    done
39    python process_metrics.py --csv "$output_file" --name "$experiment_name"
40    rm "./results/$output_file"
41  done
42done
43
44if [ "$downloaded_checkpoint" = true ]; then
45  echo "Cleaning up checkpoint..."
46  rm "$checkpoint_file"
47else
48  echo "No cleanup needed"
49fi
50