#!/usr/bin/env bash
# README commands on OPT-1.3B: Wanda at 50% unstructured and 2:4 sparsity, and the magnitude baseline at 50%
# unstructured. WikiText-2 perplexity is read from the log file each run writes.
set -o pipefail
ROW=/var/tmp/kv-repro/037-locuslab-wanda
export HOME=$ROW/data/home
run() {
  method=$1 type=$2 tag=$3
  echo "KVERITAS_PHASE name=$tag"
  out=$ROW/data/run-$tag
  rm -rf "$out"
  python main_opt.py --model facebook/opt-1.3b --prune_method $method --sparsity_ratio 0.5 \
    --sparsity_type $type --save "$out" 2>&1 | grep -E "perplexity|sparsity" || exit 1
  ppl=$(awk 'NR==2 {print $3}' "$out"/log_$method.txt)
  sp=$(awk 'NR==2 {print $2}' "$out"/log_$method.txt)
  echo "KVERITAS_METRIC name=${tag}_actual_sparsity value=$sp"
  echo "KVERITAS_METRIC name=${tag}_wikitext2_ppl value=$ppl"
  echo "KVERITAS_CLAIM metric=${tag}_wikitext2_ppl value=$ppl"
}
run wanda unstructured wanda_unstructured_50
run wanda 2:4 wanda_2of4
run magnitude unstructured magnitude_unstructured_50
