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