#!/bin/bash

if [ $# -lt 4 ]; then
    echo "$0 <lang-string: en-de> <log_file> <exp_name> <preprocessed_data_path/> [init_model,init_model]"
    echo "  require 4 or 5 args, given $#"
    exit;
fi

lang_pair=$1
log_file=$2
exp_name=$3
data_path=$4
init_model=${5:-""}
echo ${init_model}
IFS="," read -r -a init_models <<< ${init_model}

echo "-----------------------------------------------"
echo "  Started `date`"
echo "-----------------------------------------------"

if [ ! -z ${init_model} ]; then
    echo "  Initializing "
    echo "    MT encoder from: ${init_models[0]}"
    echo "    MT decoder from: ${init_models[1]}"
    reload_model="--reload_model \"${init_model}\""
else
    echo "  Training MT from scratch"
fi

echo "  Log file  : ${log_file}"
echo "  Input data: ${data_path}"

epoch_size=10000
max_epoch=1000
bsize=8

dump_path=`dirname ${log_file}`/dumps/

accum_grad=1
gelu=True
emb_dim=1280
n_layers=16
n_heads=16
dropout=0.3
attn_dropout=0.0
optimizer="adam,lr=0.00001"


# queue-freegpu.pl is for BUT SGE cluster only
queue-freegpu.pl --config conf/queue.conf --gpu 1 --mem 25G ${log_file} \
    python train.py \
    --exp_name ${exp_name} \
    --data_path ${data_path} \
    --dump_path ${dump_path} \
    --lgs "${lang_pair}" \
    --clm_steps "" \
    --mlm_steps "" \
    --mt_steps "${lang_pair}" \
    --accumulate_gradients ${accum_grad} \
    --gelu_activation ${gelu} \
    --encoder_only false \
    --use_lang_emb false \
    --emb_dim ${emb_dim} \
    --n_layers ${n_layers} \
    --n_heads ${n_heads} \
    --dropout ${dropout} \
    --attention_dropout ${attn_dropout} \
    --epoch_size ${epoch_size} \
    --max_epoch ${max_epoch} \
    --batch_size ${bsize} \
    --optimizer ${optimizer} \
    --max_vocab 200000 \
    --eval_bleu true \
    ${reload_model}


echo "-----------------------------------------------"
echo "  Done    `date`"
echo "-----------------------------------------------"
