#!/bin/bash

usage="$(basename "$0") [-m <fine-tuned-model-path>]
      Argument -m takes the relative path of fine-tuned model from ${SAVED_MODELS_PROMPT}.
      Example: -m 250-dpd/experiment-20221003T172424/epoch-08"

while getopts :m: flag
do
    case "${flag}" in
      m) model_path=${OPTARG};;
      :) printf "missing argument for -%s\n" "$OPTARG" >&2; echo "$usage" >&2; exit 1;;
    esac
done

# check for mandatory/required -m argument
# mandatory arguments
if [ ! "$model_path" ]; then
  echo "arguments -m must be provided"
  echo "$usage" >&2; exit 1
fi

# Check whether the required environment vars are set
if [ -z "${SAVED_MODELS_PROMPT}" ]; then
  echo "Must set SAVED_MODELS_PROMPT in environment, run set_env.sh first!";
  exit 1
fi

# Check whether the required environment vars are set
if [ -z "${OUTPUTS_DIR_PROMPT}" ]; then
  echo "Must set OUTPUTS_DIR_PROMPT in environment, run set_env.sh first!";
  exit 1
fi

# check if the training data file exists
TEST_DATA_FILE=../data/prompt-learning/test/test.soloist.json
if [ ! -f "${TEST_DATA_FILE}" ]; then
  echo "Test/Valid Data file does not exist!"
  exit 1
fi

FINE_TUNED_MODEL_PATH=${SAVED_MODELS_PROMPT}/${model_path}
if [ ! -d "${FINE_TUNED_MODEL_PATH}" ]; then
  echo "Invalid fine-tuned model path - ${model_path}"
fi


OUTPUTS_DIR=${OUTPUTS_DIR_PROMPT}/${model_path}
# create the dirs if not exist
mkdir -p "${OUTPUTS_DIR}"

python prompt_decode.py \
--output_dir="${OUTPUTS_DIR}" \
--tuned_model_path="${FINE_TUNED_MODEL_PATH}" \
--test_data_file="${TEST_DATA_FILE}"