#!/usr/bin/bash

model=llama-2-7b
model_path="/home/jiabao/2024-Projects/DecodeUnlearn/trained_models2/finetune-hp/mistral/checkpoint-441"
data=harry
num_layers=(8)

splits=(xxx)
remember=tofu-llama-2
BASEDIR=model_weights/
OUTDIRNAME="eval_hf-ours-harry-0515/noqa"

# export CUDA_VISIBLE_DEVICES=1,4,5
export CUDA_VISIBLE_DEVICES=3,0

TTTS=(
	""
)

for TTT in "${TTTS[@]}"; do
	# TARGETDIRS=($(find $TTT -mindepth 1 -maxdepth 1 -type d))

	TARGETDIRS=(
		# "trained_models2/hf-ours-Lora-toxic/hf_forget_train-None/Lorar_32-lr_0.0005-layer_8/data.batch_size_8|gradient_accumulation_steps_2|model_train.weight_decay_0.01|data_toxic|model_train.model_name_llama-2|model_train_remember_uniform|data_mode_forget_more_retain"
		"trained_models2/hf-ours-Lora-copyright/hf_forget_train-None/Lorar_32-lr_0.001-layer_8/data.batch_size_8|gradient_accumulation_steps_2|model_train.weight_decay_0.01|data_harry|model_train.model_name_llama-2|data_mode_forget_retain|model_train_remember_uniform"
	)

	for TARGETDIR in "${TARGETDIRS[@]}"; do
		for num_layer in "${num_layers[@]}"; do
			for split in "${splits[@]}"; do
				rawcheckpoints=($(find $TARGETDIR -type d -name "checkpoint-[0-9]*"))
				checkpoints=($(printf "%s\n" "${rawcheckpoints[@]}" | awk -F'-' '{print $NF, $0}' | sort -rn | cut -d' ' -f2-))

				# checkpoints=(
				# 	"trained_models2/hf-ours-Lora-copyright/hf_forget_train-None/Lorar_32-lr_0.001-layer_8/data.batch_size_8|gradient_accumulation_steps_2|model_train.weight_decay_0.01|data_harry|model_train.model_name_llama-2|data_mode_forget_retain|model_train_remember_uniform/2024-05-15_23-09-27/logs/harry-ours-hf/split_None|loss_remember_uniformdata_forget_retain|lr_0.001|lora_32|assist_False_2024-05-15T23-09-27/checkpoint-75"
				# )

				# weights=(-0.5 -0.6)
				weights=(-0.3 -0.4)
				#! checkpoint parallel
				#! weight parallel
				for ((i=0; i<${#checkpoints[@]}; i+=1)); do
					checkpoint="${checkpoints[$i]}"
					echo $checkpoint
					for index in "${!weights[@]}"; do
						weight="${weights[$index]}"
						python scripts/eval_copyright.py \
							BASEDIR=${BASEDIR} \
							data=${data} \
							model=${model} \
							model.model_path=${model_path} \
							remember=${remember} \
							remember.num_layer=${num_layer} \
							remember.weight=${weight} \
							remember.save_path="${checkpoint}" \
							remember.is_lora=True \
							OUTDIRNAME=$OUTDIRNAME \
							gpu=gpu$((index)) \
							remember.top_logit_filter=1e-2 &
					done
					echo "waiting"
					wait 
					# break
				done
			done
		done
	done

done