forked from libeineu/fairseq_mmt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
train_mmt.sh
160 lines (146 loc) · 4.45 KB
/
train_mmt.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#Your program starts here
set -e
device=2
# task=multi30k-en2zh
task=m30k_test3am-en2zh
# task=msctd_ambig1-en2zh
# task=3am-en2zh
image_feat=vit_base_patch16_384
mask_data=mask0
tag=$image_feat/$mask_data
if [ $task == 'multi30k-en2de' ]; then
src_lang=en
tgt_lang=de
if [ $mask_data == "mask0" ]; then
data_dir=multi30k.en-de
elif [ $mask_data == "mask1" ]; then
data_dir=multi30k.en-de.mask1
elif [ $mask_data == "mask2" ]; then
data_dir=multi30k.en-de.mask2
elif [ $mask_data == "mask3" ]; then
data_dir=multi30k.en-de.mask3
elif [ $mask_data == "mask4" ]; then
data_dir=multi30k.en-de.mask4
elif [ $mask_data == "maskc" ]; then
data_dir=multi30k.en-de.maskc
elif [ $mask_data == "maskp" ]; then
data_dir=multi30k.en-de.maskp
fi
elif [ $task == 'multi30k-en2fr' ]; then
src_lang=en
tgt_lang=fr
if [ $mask_data == "mask0" ]; then
data_dir=multi30k.en-fr
elif [ $mask_data == "mask1" ]; then
data_dir=multi30k.en-fr.mask1
elif [ $mask_data == "mask2" ]; then
data_dir=multi30k.en-fr.mask2
elif [ $mask_data == "mask3" ]; then
data_dir=multi30k.en-fr.mask3
elif [ $mask_data == "mask4" ]; then
data_dir=multi30k.en-fr.mask4
elif [ $mask_data == "maskc" ]; then
data_dir=multi30k.en-fr.maskc
elif [ $mask_data == "maskp" ]; then
data_dir=multi30k.en-fr.maskp
fi
elif [ $task == 'multi30k-en2zh' ]; then
src_lang=en
tgt_lang=zh
if [ $mask_data == "mask0" ]; then
data_dir=multi30k.en-zh
elif [ $mask_data == "mask1" ]; then
data_dir=multi30k.en-zh.mask1
elif [ $mask_data == "mask2" ]; then
data_dir=multi30k.en-zh.mask2
elif [ $mask_data == "mask3" ]; then
data_dir=multi30k.en-zh.mask3
elif [ $mask_data == "mask4" ]; then
data_dir=multi30k.en-zh.mask4
elif [ $mask_data == "maskc" ]; then
data_dir=multi30k.en-zh.maskc
elif [ $mask_data == "maskp" ]; then
data_dir=multi30k.en-zh.maskp
fi
elif [ $task == 'flickr30k-en2zh' ]; then
src_lang=en
tgt_lang=zh
if [ $mask_data == "mask0" ]; then
data_dir=flickr30k.en-zh
fi
elif [ $task == 'm30k_test3am-en2zh' ]; then
src_lang=en
tgt_lang=zh
data_dir=m30k_test3am.en-zh
image_feat_root=data/m30k_test3am
elif [ $task == 'msctd_ambig1-en2zh' ]; then
src_lang=en
tgt_lang=zh
data_dir=msctd_ambig1.en-zh
elif [ $task == '3am-en2zh' ]; then
src_lang=en
tgt_lang=zh
data_dir=3am.en-zh
fi
criterion=label_smoothed_cross_entropy
fp16=1 #0
lr=0.0075
warmup=8000
max_tokens=4096
update_freq=1
keep_last_epochs=10
patience=10
max_update=32000
dropout=0.3
arch=image_multimodal_transformer_SA_top
# arch=image_multimodal_transformer_SA_top_base
SA_attention_dropout=0.1
SA_image_dropout=0.1
save_dir=checkpoints/$task/$arch
if [ ! -d $save_dir ]; then
mkdir -p $save_dir
fi
if [ $image_feat == "vit_tiny_patch16_384" ]; then
image_feat_path=$image_feat_root/$image_feat
image_feat_dim=192
elif [ $image_feat == "vit_small_patch16_384" ]; then
image_feat_path=$image_feat_root/$image_feat
image_feat_dim=384
elif [ $image_feat == "vit_base_patch16_384" ]; then
image_feat_path=$image_feat_root/$image_feat
image_feat_dim=768
elif [ $image_feat == "vit_large_patch16_384" ]; then
image_feat_path=$image_feat_root/$image_feat
image_feat_dim=1024
fi
# multi-feature
#image_feat_path=data/vit_large_patch16_384 data/vit_tiny_patch16_384
#image_feat_dim=1024 192
cp ${BASH_SOURCE[0]} $save_dir/train.sh
gpu_num=`echo "$device" | awk '{split($0,arr,",");print length(arr)}'`
cmd="fairseq-train data-bin/$data_dir
--save-dir $save_dir
--distributed-world-size $gpu_num -s $src_lang -t $tgt_lang
--arch $arch
--dropout $dropout
--criterion $criterion --label-smoothing 0.1
--task image_mmt --image-feat-path $image_feat_path --image-feat-dim $image_feat_dim
--optimizer adam --adam-betas '(0.9, 0.98)'
--lr $lr --min-lr 1e-09 --lr-scheduler inverse_sqrt --warmup-init-lr 1e-07 --warmup-updates $warmup
--max-tokens $max_tokens --update-freq $update_freq --max-update $max_update
--find-unused-parameters
--patience $patience
--keep-last-epochs $keep_last_epochs"
if [ $fp16 -eq 1 ]; then
cmd=${cmd}" --fp16 "
fi
if [ -n "$SA_image_dropout" ]; then
cmd=${cmd}" --SA-image-dropout "${SA_image_dropout}
fi
if [ -n "$SA_attention_dropout" ]; then
cmd=${cmd}" --SA-attention-dropout "${SA_attention_dropout}
fi
export CUDA_VISIBLE_DEVICES=$device
cmd="nohup "${cmd}" > $save_dir/train.log 2>&1 &"
eval $cmd
# tail -f $save_dir/train.log