-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove.mk
375 lines (283 loc) · 12.8 KB
/
remove.mk
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# -*-makefile-*-
#
#--------------------------------------------------------------------
# make remove MODEL=modelname
# make remove BENCHMARK=testset
# make remove MODEL=modelname BENCHMARK=testset
#
# make remove BENCHMARK=testset LANGPAIR=langpair
# make remove MODEL=modelname BENCHMARK=testset LANGPAIR=langpair
#
# make remove-devsets ......BROKEN!
# make cleanup
#--------------------------------------------------------------------
SPACE := $(empty) $(empty)
REPOHOME ?= ../
SCORE_HOME ?= ${REPOHOME}scores
MODEL_HOME ?= ${REPOHOME}models
##------------------------------------------------------------------
## if MODEL or USER/MODELNAME is set: get language pairs supported by the model
##------------------------------------------------------------------
ifneq (${MODELNAME},)
ifneq (${USER},)
MODELS := ${USER}/${MODELNAME}
MODEL := ${USER}/${MODELNAME}
endif
endif
ifneq (${MODEL},)
LANGPAIRS := $(sort $(shell cut -f1 ${MODEL_HOME}/${MODEL}.scores.txt | sort -u))
BENCHMARKS := $(sort $(shell cut -f2 ${MODEL_HOME}/${MODEL}.scores.txt | sort -u))
MODELS := ${MODEL}
endif
##------------------------------------------------------------------
## if LANGPAIR is set: use only that language pair
##------------------------------------------------------------------
ifneq (${LANGPAIR},)
LANGPAIRS := ${LANGPAIR}
endif
##------------------------------------------------------------------
## if LANGPAIRS is not set but BENCHMARK is:
## --> get all language pairs supported by that benchmark
##------------------------------------------------------------------
ifeq (${LANGPAIRS},)
ifneq (${BENCHMARK},)
LANGPAIRS := $(sort $(shell grep '^${BENCHMARK} ' ${TESTSETS_TO_LANGPAIR} | cut -f2))
endif
endif
##------------------------------------------------------------------
## if MODELS is not set: get all models that support the language pairs we are interested in
##------------------------------------------------------------------
ifeq (${MODELS},)
MODELS := $(sort $(foreach langpair,$(LANGPAIRS),$(shell cat $(SCORE_HOME)/${langpair}/model-list.txt)))
endif
EVAL_ZIPFILES := $(sort $(foreach model,$(MODELS),${MODEL_HOME}/$(model).zip))
##------------------------------------------------------------------
## if BENCHMARK is set:
## - get all score files that are affected
## - get all evaluation files of all models that are affected
## - create a pattern for removing files from the zip files
##
## if BENCHMARK is not set:
## - do the same but for all possible benchmarks
##------------------------------------------------------------------
ifneq (${BENCHMARK},)
SCORE_FILE_DIRS := $(sort $(foreach langpair,$(LANGPAIRS),$(wildcard ${SCORE_HOME}/$(langpair)/${BENCHMARK})))
SCORE_FILES := $(sort $(foreach langpair,$(LANGPAIRS),$(wildcard ${SCORE_HOME}/$(langpair)/${BENCHMARK}/*.txt)))
EVAL_FILES := $(sort \
$(foreach model,${MODELS},\
$(foreach langpair,$(LANGPAIRS),\
${MODEL_HOME}/${model}/${BENCHMARK}.${langpair}.eval)))
EVALOUT_FILES := $(sort \
$(foreach model,${MODELS},\
$(foreach langpair,$(LANGPAIRS),\
${MODEL_HOME}/${model}.zip/${BENCHMARK}.${langpair}.*)))
else
SCORE_FILES := $(foreach langpair,$(LANGPAIRS),$(wildcard ${SCORE_HOME}/$(langpair)/*/*.txt))
EVAL_FILES := $(sort \
$(foreach model,${MODELS},\
$(foreach langpair,$(LANGPAIRS),\
$(wildcard ${MODEL_HOME}/${model}/*.${langpair}.eval))))
EVALOUT_FILES := $(sort \
$(foreach model,${MODELS},\
$(foreach langpair,$(LANGPAIRS),\
${MODEL_HOME}/${model}.zip/*.${langpair}.*)))
endif
TRANSLATION_FILES := $(patsubst %.eval,%.output,${EVAL_FILES})
EVAL_LOGFILES := $(patsubst %.eval,%.evalfiles.zip,${EVAL_FILES})
EVALALL_FILES := $(subst .zip/,.eval.zip/,${EVALOUT_FILES})
EVALLOG_FILES := $(subst .zip/,.log.zip/,${EVALOUT_FILES})
MODELSCORE_FILES := $(sort $(foreach model,$(MODELS),$(wildcard ${MODEL_HOME}/$(model).*.txt)))
MODELLIST_FILES := $(sort $(foreach langpair,$(LANGPAIRS),$(wildcard ${SCORE_HOME}/$(langpair)/model-list.txt)))
## backup files before removing benchmarks
## also used as targets to actually remove them from the original files
TRANSLATION_FILES_REMOVE := $(patsubst %,%.remove,${TRANSLATION_FILES})
EVAL_LOGFILES_REMOVE := $(patsubst %,%.remove,${EVAL_LOGFILES})
EVAL_FILES_REMOVE := $(patsubst %,%.remove,${EVAL_FILES})
SCORE_FILE_DIRS_REMOVE := $(patsubst %,%.remove-dir,${SCORE_FILE_DIRS})
SCORE_FILES_REMOVE := $(patsubst %.txt,%.remove,${SCORE_FILES})
MODELSCORE_FILES_REMOVE := $(patsubst %.txt,%.remove,${MODELSCORE_FILES})
MODELLIST_FILES_REMOVE := $(patsubst %.txt,%.remove,${MODELLIST_FILES})
MODELLIST_FILES_UPDATE := $(patsubst %.txt,%.update,${MODELLIST_FILES})
TOPSCORE_FILES_REMOVE := $(patsubst %.txt,%.remove,${TOPSCORE_FILES})
AVGSCORE_FILES_REMOVE := $(patsubst %.txt,%.remove,${AVGSCORE_FILES})
##-----------------------------------------------------------------------------
## remove recipe (depending on given command-line arguments)
##-----------------------------------------------------------------------------
.PHONY: remove
remove:
ifeq (${MODEL},${MODELS})
ifneq (${BENCHMARK},)
ifneq (${LANGPAIR},)
${MAKE} remove-langpair-benchmark-from-model
else
${MAKE} remove-benchmark-from-model
endif
else
${MAKE} remove-model
endif
else ifneq (${BENCHMARK},)
ifneq (${LANGPAIR},)
${MAKE} remove-langpair-benchmark
else
${MAKE} remove-benchmark
endif
endif
##-----------------------------------------------------------------------------
## remove rows from all sqlite score databases
## that match the DELETE_CONDITION
##-----------------------------------------------------------------------------
remove-from-db:
ifneq (${DELETE_CONDITION},)
@for d in $(patsubst %.db,%,${SCORE_DBS}); do \
if [ -e $$d.db ]; then \
echo "echo \"delete from scores where ${DELETE_CONDITION}\" | sqlite3 $$d.db"; \
echo "delete from scores where ${DELETE_CONDITION}" | sqlite3 $$d.db; \
date +%F > $$d.date; \
fi \
done
endif
remove-model-from-db:
@${MAKE} DELETE_CONDITION="model='${MODEL}'" remove-from-db
remove-benchmark-from-db:
@${MAKE} DELETE_CONDITION="testset='${BENCHMARK}'" remove-from-db
remove-langpair-benchmark-from-db:
@${MAKE} DELETE_CONDITION="langpair='${LANGPAIR}' and testset='${BENCHMARK}'" remove-from-db
remove-benchmark-from-model-from-db:
@${MAKE} DELETE_CONDITION="model='${MODEL}' and testset='${BENCHMARK}'" remove-from-db
remove-langpair-benchmark-from-model-from-db:
@${MAKE} DELETE_CONDITION="model='${MODEL}' and langpair='${LANGPAIR}' and testset='${BENCHMARK}'" remove-from-db
##-----------------------------------------------------------------------------
## remove all info about a specific model
##-----------------------------------------------------------------------------
.PHONY: remove-model
remove-model: remove-model-from-db
ifneq (${MODEL},)
${MAKE} REMOVE_PATTERN='<TAB>${MODEL}<EOS>' remove-from-scores
${MAKE} REMOVE_PATTERN='${MODEL}<EOS>' remove-from-model-lists
${MAKE} update-model-lists
rm -f ${MODEL_HOME}/${MODEL}.*
endif
##-----------------------------------------------------------------------------
## remove one or more benchmarks from the leaderboards and score files
## TODO: need to also do something with the evaluation files in the zip archives
##-----------------------------------------------------------------------------
.PHONY: remove-langpair-benchmark-from-model
remove-langpair-benchmark-from-model: remove-langpair-benchmark-from-model-from-db
${MAKE} REMOVE_PATTERN='${LANGPAIR}<TAB>${BENCHMARK}<TAB>' remove-from-model-scores
${MAKE} REMOVE_PATTERN='<TAB>${MODEL}<EOS>' remove-from-scores
${MAKE} REMOVE_PATTERN='${MODEL}<EOS>' remove-from-model-lists
${MAKE} remove-translation-files remove-eval-files
${MAKE} update-zip-files
${MAKE} update-model-lists
.PHONY: remove-benchmark-from-model
remove-benchmark-from-model: remove-benchmark-from-model-from-db
${MAKE} REMOVE_PATTERN='<TAB>${BENCHMARK}<TAB>' remove-from-model-scores
${MAKE} REMOVE_PATTERN='<TAB>${MODEL}<EOS>' remove-from-scores
${MAKE} REMOVE_PATTERN='${MODEL}<EOS>' remove-from-model-lists
${MAKE} remove-translation-files remove-eval-files
${MAKE} update-zip-files
${MAKE} update-model-lists
.PHONY: remove-langpair-benchmark
remove-langpair-benchmark: remove-langpair-benchmark-from-db ${SCORE_FILE_DIRS_REMOVE}
${MAKE} REMOVE_PATTERN='${LANGPAIR}<TAB>${BENCHMARK}<TAB>' remove-from-model-scores
${MAKE} remove-translation-files remove-eval-files
${MAKE} update-zip-files
${MAKE} update-model-lists
${MAKE} -C ${REPOHOME} scores/langpairs.txt scores/benchmarks.txt
.PHONY: remove-benchmark
remove-benchmark: remove-benchmark-from-db ${SCORE_FILE_DIRS_REMOVE}
${MAKE} REMOVE_PATTERN='<TAB>${BENCHMARK}<TAB>' remove-from-model-scores
${MAKE} remove-translation-files remove-eval-files
${MAKE} update-zip-files
${MAKE} update-model-lists
${MAKE} -C ${REPOHOME} scores/langpairs.txt scores/benchmarks.txt
.PHONY: ${SCORE_FILE_DIRS_REMOVE}
${SCORE_FILE_DIRS_REMOVE}: %.remove-dir: %
mv $< $@
rm -fr $@
## remove files from zip archives
.PHONY: update-zip-files
update-zip-files: ${EVALOUT_FILES} ${EVALLOG_FILES} ${EVALALL_FILES}
${EVALOUT_FILES} ${EVALLOG_FILES} ${EVALALL_FILES}:
-zip -d $(patsubst %/,%,$(dir $@)) $(notdir $@)
.PHONY: remove-from-scores remove-from-model-scores remove-from-model-lists
remove-from-scores: ${SCORE_FILES_REMOVE}
remove-from-model-scores: ${MODELSCORE_FILES_REMOVE}
remove-from-model-lists: ${MODELLIST_FILES_REMOVE}
remove-translation-files: ${TRANSLATION_FILES_REMOVE}
remove-eval-files: ${EVAL_FILES_REMOVE} ${EVAL_LOGFILES_REMOVE}
## replace special tokens (TAB and end-of-string) with the actual character/regex to be matched
REMOVE_PATTERN_UNESCAPED := $(subst <EOS>,$$,$(subst <TAB>, ,${REMOVE_PATTERN}))
.PHONY: ${SCORE_FILES_REMOVE} ${MODELLIST_FILES_REMOVE} ${MODELSCORE_FILES_REMOVE}
${SCORE_FILES_REMOVE} ${MODELLIST_FILES_REMOVE} ${MODELSCORE_FILES_REMOVE}: %.remove: %.txt
ifneq (${REMOVE_PATTERN_UNESCAPED},)
cp $< $<.backup
egrep -v '${REMOVE_PATTERN_UNESCAPED}' < $<.backup > $< || exit 0
endif
.PHONY: ${TRANSLATION_FILES_REMOVE} ${EVAL_FILES_REMOVE} ${EVAL_LOGFILES_REMOVE}
${TRANSLATION_FILES_REMOVE} ${EVAL_LOGFILES_REMOVE} ${EVAL_FILES_REMOVE}:
rm -f $(@:.remove=)
update-model-lists: ${MODELLIST_FILES_UPDATE}
.PHONY: ${MODELLIST_FILES_UPDATE}
${MODELLIST_FILES_UPDATE}: %.update: %.txt
touch $<
${MAKE} -C ${REPOHOME} LANGPAIR=$(notdir $(patsubst %/,%,$(dir $@))) all-topavg-scores
##-------------------------------------------------
## cleanup
##-------------------------------------------------
.PHONY: cleanup
cleanup:
find ${MODEL_HOME} -name '*.backup' -delete
find ${SCORE_HOME} -name '*.txt' -empty -delete
find ${MODEL_HOME} -name '*.txt' -empty -delete
find ${SCORE_HOME}/ -name '*.remove-dir' -exec rm -fr {} \;
## print the files that will be affected by a remove command
print-affected-files:
@echo "langpair: ${LANGPAIR}"
@echo "langpairs: ${LANGPAIRS}"
@echo "model: ${MODEL}"
@echo "models: ${MODELS}"
@echo "------------score-file-dirs:-------------"
@echo "${SCORE_FILE_DIRS}" | tr ' ' "\n"
@echo "------------score-files------------------"
@echo "${SCORE_FILES}" | tr ' ' "\n"
@echo "------------model-files------------------"
@echo "${MODELSCORE_FILES}" | tr ' ' "\n"
@echo "------------eval-file-zips---------------"
@echo "${EVAL_ZIPFILES}" | tr ' ' "\n"
@echo "------------eval-files-------------------"
@echo "${EVAL_FILES}" | tr ' ' "\n"
@echo "------------translation-files-------------------"
@echo "${TRANSLATION_FILES}" | tr ' ' "\n"
@echo "------------eval-out-files-------------------"
@echo "${EVALOUT_FILES}" | tr ' ' "\n"
@echo "------------eval-log-files-------------------"
@echo "${EVALLOG_FILES}" | tr ' ' "\n"
@echo "------------eval-all-files-------------------"
@echo "${EVALALL_FILES}" | tr ' ' "\n"
@echo "------------model-list-files-------------"
@echo "${MODELLIST_FILES}" | tr ' ' "\n"
##-----------------------------------------------------------------------------
## special recipe: remove dev-sets from the leaderboard
##-----------------------------------------------------------------------------
DEVSETS := $(sort $(shell cut -f1 ${SCORE_HOME}/benchmarks.txt | grep dev | grep -v devtest))
print-devset-names:
@echo ${DEVSETS}
remove-devsets:
${MAKE} devset-scoredirs.txt
${MAKE} remove-all-devset-scores
rm -f devset-scoredirs.txt
devset-scoredirs.txt:
rm -f $@
for d in ${DEVSETS}; do \
find ../scores -type d -name $$d >> $@; \
done
ifneq ($(wildcard devset-scoredirs.txt),)
DEVSET_BENCHMARKS := $(sort $(shell cat devset-scoredirs.txt | cut -f3,4 -d/))
DEVSET_BENCHMARKS_REMOVE_TARGET := $(patsubst %,%.removedevset,$(DEVSET_BENCHMARKS))
endif
remove-all-devset-scores: ${DEVSET_BENCHMARKS_REMOVE_TARGET}
%.removedevset:
${MAKE} LANGPAIR=$(firstword $(subst /, ,$(@:.removedevset=))) \
BENCHMARK=$(lastword $(subst /, ,$(@:.removedevset=))) \
remove