-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathharness
More file actions
executable file
·243 lines (219 loc) · 5.63 KB
/
harness
File metadata and controls
executable file
·243 lines (219 loc) · 5.63 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/bin/bash
#@meta {author: 'Paul Landes'}
#@meta {desc: "automate tests", date: "2025-02-08"}
PROG=$(basename $0)
DRYRUN=0
USAGE="\
usage: $PROG fewshot <mimic|synthetic|mimthetic> [model] [lm|lmsdohcui]
$PROG train <mimic|synthetic|mimthetic> [model] [lm|lmsdohcui]
$PROG test <mimic|synthetic|mimthetic> [model] [lm|lmsdohcui]
$PROG binary[cv|abl]
$PROG multilabelabl <mimic|synthetic|mimthetic>
$PROG <models|testall>
$PROG prod
$PROG -h/--help
"
# log message
function log() {
msg=$1 ; shift
echo "$PROG: $msg"
}
# log message with separator
function prhead() {
echo "--------------------${1}:"
}
# fail out of the program with an error message
function bail() {
msg=$1 ; shift
usage=$1 ; shift
echo "$PROG: error: $msg" > /dev/stderr
if [ ! -z "$usage" ] ; then
printf "$USAGE" > /dev/stderr
fi
exit 1
}
# make sure the last command ran was successful and fail otherwise
function assert_success() {
ret=$1 ; shift
if [ $ret -ne 0 ] ; then
bail "last command failed"
fi
}
function map_model() {
model=$1 ; shift
case $model in
llamsm|"")
model_id=""
;;
llamlg)
model_id="meta-llama/Llama-3.3-70B-Instruct"
;;
medllama)
# MedLlama
model_id="ProbeMedicalYonseiMAILab/medllama3-v20"
;;
openbio)
# OpenBioLLM
model_id="aaditya/Llama3-OpenBioLLM-70B"
;;
*)
bail "unknown model: '${model}'"
;;
esac
}
# translate command-line arguments into environment variables
function parse_args() {
action=$1 ; shift
dataset=$1 ; shift
model=$1 ; shift
feattype=$1 ; shift
confname=$1 ; shift
override=
map_model $model
[ -z "$feattype" ] && feattype="lm"
[ -z "$action" ] && bail "missing action" 1
[ -z "$dataset" ] && bail "missing dataset parameter" 1
[ "$dataset" != "mimic" -a "$dataset" != "synthetic" -a "$dataset" != "mimthetic" ] && bail "unknown dataset: $dataset"
[ "$feattype" != "lm" -a "$feattype" != "lmsdohcui" ] && bail "unknown feature type: ${feattype}"
[ -z "$confname" ] && confname='model'
if [ ! -z "$model_id" ] ; then
override="lmtask_trainer_default.source_model=${model_id}"
override="${override},lmtask_llama_instruct_resource.model_id=${model_id}"
fi
override="--override=${override}${override:+,}sdoh_default.label=${dataset}"
override="${override},sdoh_lm_default.feature_hint_type=${feattype}"
args="-c etc/${confname}.conf $override"
}
# run the harness script
function run_py_harness() {
cmd="./harness.py $args"
# remove config cache (needed when using --override)
rm -f data/app-config.dat
echo ${cmd} $@
if [ $DRYRUN -eq 0 ] ; then
${cmd} $@
fi
assert_success $?
}
# actions
function fewshot() {
prhead "predicting with fewshot learning on dataset ${dataset}"
run_py_harness fewshot --clear
}
function train() {
prhead "training on dataset ${dataset}"
run_py_harness trainlm
}
function test() {
prhead "prediction on test dataset ${dataset}"
run_py_harness testlm --clear
}
# create a script to run all tests
function test_all() {
cmd="./${PROG}"
datasets="mimic synthetic mimthetic"
models="llamsm llamlg medllama openbio"
feattypes="lm lmsdohcui"
printf "#!/bin/bash\n\n# train models\n"
for dataset in $datasets ; do
for model in $models ; do
for feattype in $feattypes ; do
printf "$cmd train $dataset $model $feattype\n"
done
done
done
printf "\n# inference models\n"
for testtype in fewshot test ; do
for dataset in $datasets ; do
for model in $models ; do
for feattype in $feattypes ; do
printf "$cmd $testtype $dataset $model $feattype\n"
done
done
done
done
}
function run_abl() {
model=$1 ; shift
dataset=$1 ; shift
prhead "running ${model} ablation on ${dataset}"
echo src/bin/run-ablation.py ${model} -d ${dataset}
src/bin/run-ablation.py ${model} -d ${dataset}
}
function binary_ablation() {
action=$1 ; shift
dataset=$1 ; shift
# binary only makes sense on the mimic dataset (has non-sdohs)
run_abl binary ${dataset}
}
function multilabel_ablation() {
action=$1 ; shift
dataset=$1 ; shift
run_abl multilabel ${dataset}
}
function run_binary() {
conf=$1 ; shift
if [ ! -d ${HOME}/.cache/zensols/deepnlp ] ; then
override="${override}${override:+,}batch_stash.workers=1"
fi
if [ ! -z "$override" ] ; then
args="--override '${override}'"
fi
run_py_harness -c etc/${conf}.conf $@
}
function binary() {
prhead "train and test the binary classifier"
run_binary binary traintest -p
}
function binarycv() {
prhead "cross validate the binary classifier"
run_binary crossfold-binary cvalrun --repeats 50
}
function prod() {
prhead "create the multi-label classifier production version model"
args="-c etc/multilabel-prod.conf"
run_py_harness trainprod -p
prhead "create the binary classifier production version model"
args="-c etc/binary-prod.conf"
run_py_harness trainprod -p
}
# run one of the actions (subcommand)
function ce_main() {
action=$1
case $action in
fewshot|train|test)
parse_args $@
$action $@
;;
binary|binarycv)
$action $@
;;
multilabelabl)
parse_args $@
multilabel_ablation $@
;;
binaryabl)
parse_args $@
binary_ablation $@
;;
prod)
prod $@
;;
models)
printf "llamsm\nllamlg\nmedllama\nopenbio\n"
;;
testall)
test_all $@
;;
-h|"")
printf "$USAGE" > /dev/stderr
exit 1
;;
*)
parse_args $action mimic
shift
run_py_harness $@ $action
;;
esac
}
ce_main $@