-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate_lora.sh
executable file
·72 lines (57 loc) · 2.39 KB
/
generate_lora.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
CONFIG="./config.sh"
[[ ! -f "${CONFIG}" ]] && echo "${CONFIG} not found: Create ${CONFIG} from config.example.sh with your configurations." && exit 1
# Import configurations and export for script.
set -a
source ${CONFIG}
set +a
[[ -z "$CONVERTED_DIR" ]] && echo "CONVERTED_DIR not set in config.sh" && exit 1
[[ -z "$VENV" ]] && echo "VENV not set in config.sh" && exit 1
MODEL_SIZE=<model size>
CONVERTED_LLAMA_MODEL=$CONVERTED_DIR/$MODEL_SIZE/state_dict.pth
TOKENIZER_PATH=$CONVERTED_DIR/tokenizer.model
MODEL_ID=<identifier for model>
CKPT_DIR=<directory with saved checkpoints>
CFG_PATH=$CKPT_DIR/config.json
CKPT_NUM=<checkpoint to evaluate>
CKPT_PATH=$CKPT_DIR/model-$CKPT_NUM.pt
source $VENV/bin/activate
DATA_DIR=<path to data dir>
OUTPUT_DIR=<path to store translations>
DATASETS=("flores" "wmt" "law" "medical" "tico" "chat_wmt")
declare -A DATASETS_LPS=(
["flores"]="de-en en-de fr-en en-fr nl-en en-nl pt-en en-pt ru-en en-ru zh-en en-zh"
["wmt"]="de-en en-de ru-en en-ru zh-en en-zh"
["law"]="de-en en-de"
["medical"]="de-en en-de"
["tico"]="en-fr en-pt"
["chat_wmt"]="en-de en-fr en-pt"
)
for DATASET in "${DATASETS[@]}"; do
DATASET_DIR=$DATA_DIR/$DATASET
LPS="${DATASETS_LPS[$DATASET]}"
for LP in $LPS; do
echo "Translating for LP $DATASET/$LP"
ZERO_SHOT_OUTPUT_DIR=$OUTPUT_DIR/$DATASET/$LP/$CKPT_NUM/zero_shot_instructions/
FEW_SHOT_OUTPUT_DIR=$OUTPUT_DIR/$DATASET/$LP/$CKPT_NUM/few_shot_instructions2/
mkdir -p $ZERO_SHOT_OUTPUT_DIR
python translation_llm/generate_lora.py \
--prompts_path $DATASET_DIR/$LP/zero_shot_instructions.txt \
--output_path $ZERO_SHOT_OUTPUT_DIR/translations.txt \
--tokenizer_path $TOKENIZER_PATH \
--tokenizer_path $TOKENIZER_PATH \
--pretrained_path $CONVERTED_LLAMA_MODEL \
--lora_cfg_path $CFG_PATH \
--lora_path $CKPT_PATH \
--max_new_tokens 200
mkdir -p $FEW_SHOT_OUTPUT_DIR
python translation_llm/generate_lora.py \
--prompts_path $DATASET_DIR/$LP/few_shot_instructions2.txt \
--output_path $FEW_SHOT_OUTPUT_DIR/translations.txt \
--tokenizer_path $TOKENIZER_PATH \
--pretrained_path $CONVERTED_LLAMA_MODEL \
--lora_cfg_path $CFG_PATH \
--lora_path $CKPT_PATH \
--max_new_tokens 200
done
done