Repository navigation
Expand file tree
/
Copy pathplot_eval_progress.py
More file actions
1785 lines (1681 loc) · 55.5 KB
/
Copy pathplot_eval_progress.py
File metadata and controls
1785 lines (1681 loc) · 55.5 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
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
"""Plot model evaluation performance across training checkpoints.
Reads one or more ``results.csv`` files produced by ``oellm-eval collect``
(columns: model_name, task, n_shot, performance, metric_name) and produces a
line plot per benchmark family showing how each model's score evolved across
intermediate checkpoints. Tasks that report several evaluation metrics are
reduced to the one metric declared for their family in ``FAMILIES``. For
multilingual benchmarks, scores are macro-averaged across languages by default;
per-language and single-language views are also supported.
The consolidated macro-average plot combines the per-family scores into one line per model:
``--summary zscore`` (default) per-family z-score normalization, or ``--summary naive`` plain mean of the
raw family scores. In naive mode, families whose task scores extend beyond
the 0-1 range (e.g. BLEU or chrf++ reported on a 0-100 scale) are first
rescaled to 0-1 (a BLEU of 21 counts as 0.21); this rescaling affects only
the naive macro-average plot, all other plots keep the raw scores.
Designed to run inside the shared LAIF ROCm container. The benchmark family <-> language
mapping is embedded (parsed from oellm-eval's ``task-groups.yaml``) so the
script is self-contained with no extra bind mounts.
Saves the source scores as a single `eval_results.csv` file in the current directory.
Example usage (inside container, working bind):
singularity exec \
--bind /scratch/project_465002891:/scratch/project_465002891 \
/scratch/project_465002530/containers/laif-rocm-6.4.4-pytorch-2.9.1-te-2.4.0-fa-2.8.0-triton-3.2.0.sif \
python plot_eval_progress.py \
--input results.csv \
--output_dir plots/ \
--origin_checkpoint /scratch/project_465002891/prelude-mid/hf_models/baby_9b_dense_before-annealing/checkpoints/iter_0953312 \
--supergroup multilingual
"""
from __future__ import annotations
import argparse
import csv
import re
import sys
from pathlib import Path
from typing import Dict, List, Optional, Tuple
import matplotlib
matplotlib.use("Agg") # non-interactive backend; safe inside a container
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
# --------------------------------------------------------------------------- #
# Benchmark family <-> language mapping.
#
# Each entry: family_key -> dict(families=[...], template=<str with {lang}>,
# langs=[...], n_shot=int, or a list of shot variants for a task evaluated
# at several shot counts (rendered '0/10' in plot titles). A family_key groups
# tasks that share a benchmark;
# directional benchmarks (flores200, opensubtitles) are split into per-direction
# family_keys. ``template`` is the lm_eval/lighteval task name with ``{lang}``
# as the language placeholder; expanding it over ``langs`` yields the concrete
# task names. Tasks absent from any family are treated as their own
# single-language family (lang=None).
#
# Generated from oellm-eval resources/task-groups.yaml (oellm_eval-0.1.0).
# --------------------------------------------------------------------------- #
FAMILIES: Dict[str, dict] = {
"sib200": {
"template": "sib200_{lang}",
"langs": [
"bul_Cyrl",
"hrv_Latn",
"ces_Latn",
"dan_Latn",
"nld_Latn",
"eng_Latn",
"est_Latn",
"fin_Latn",
"fra_Latn",
"deu_Latn",
"ell_Grek",
"hun_Latn",
"gle_Latn",
"ita_Latn",
"lvs_Latn",
"lit_Latn",
"mlt_Latn",
"pol_Latn",
"por_Latn",
"ron_Latn",
"slk_Latn",
"slv_Latn",
"spa_Latn",
"swe_Latn",
"cat_Latn",
"eus_Latn",
"glg_Latn",
"bos_Latn",
"kat_Geor",
"mkd_Cyrl",
"als_Latn",
"srp_Cyrl",
"tur_Latn",
"ukr_Cyrl",
"isl_Latn",
"nob_Latn",
],
"n_shot": 0,
"metric": "acc",
},
"belebele": {
"template": "belebele_{lang}",
"langs": [
"bul_Cyrl",
"hrv_Latn",
"ces_Latn",
"dan_Latn",
"nld_Latn",
"eng_Latn",
"est_Latn",
"fin_Latn",
"fra_Latn",
"deu_Latn",
"ell_Grek",
"hun_Latn",
"ita_Latn",
"lvs_Latn",
"lit_Latn",
"mlt_Latn",
"pol_Latn",
"por_Latn",
"ron_Latn",
"slk_Latn",
"slv_Latn",
"spa_Latn",
"swe_Latn",
"nob_Latn",
],
"n_shot": 5,
"metric": "acc",
},
"xcsqa": {
"template": "xcsqa_{lang}",
"langs": [
"deu_Latn",
"eng_Latn",
"spa_Latn",
"fra_Latn",
"ita_Latn",
"nld_Latn",
"pol_Latn",
"por_Latn",
],
"n_shot": 0,
"metric": "acc_norm",
},
"global_mmlu_full": {
"template": "global_mmlu_full_{lang}",
"langs": [
"cs",
"de",
"el",
"en",
"es",
"fr",
"it",
"lt",
"nl",
"pl",
"pt",
"ro",
"sr",
"sv",
"tr",
"uk",
],
"n_shot": 5,
"metric": "acc",
},
"global_mgsm": {
"template": "global_mgsm_{lang}",
"langs": ["de", "fr", "es", "el", "cs", "hu", "en", "ca", "eu", "gl", "sr"],
"n_shot": 0,
"metric": "exact_match",
},
"mgsm_native_cot": {
"template": "mgsm_native_cot_{lang}",
"langs": ["en", "de", "es", "fr"],
"n_shot": 5,
"metric": "exact_match",
},
"multiblimp": {
"template": "multiblimp_{lang}",
"langs": [
"bul",
"ces",
"dan",
"nld",
"eng",
"est",
"fin",
"fra",
"deu",
"ell",
"hun",
"gle",
"ita",
"lav",
"lit",
"pol",
"por",
"ron",
"slk",
"slv",
"spa",
"swe",
"cat",
"eus",
"glg",
"kat",
"mkd",
"sqi",
"hbs",
"tur",
"ukr",
"isl",
],
"n_shot": 0,
"metric": "acc_norm",
},
"arc_challenge_mt": {
"template": "arc_challenge_mt_{lang}",
"langs": [
"bg",
"cs",
"da",
"nl",
"et",
"fi",
"fr",
"de",
"el",
"hu",
"it",
"lv",
"lt",
"pl",
"pt",
"ro",
"sk",
"sl",
"es",
"sv",
"nb",
"is",
],
"n_shot": 0,
"metric": "acc_norm",
},
"hellaswag": {
"template": "hellaswag_{lang}",
"langs": [
"da",
"nl",
"fr",
"de",
"hu",
"it",
"pt",
"ro",
"sk",
"es",
"sv",
"hr",
"ca",
"eu",
"sr",
"uk",
],
"n_shot": 0,
"metric": "acc_norm",
},
"xcopa": {
"template": "xcopa:{lang}",
"langs": ["et", "it", "tr"],
"n_shot": 0,
"metric": "acc",
},
"global_piqa_completions": {
"template": "global_piqa_completions_{lang}",
"langs": [
"als_latn",
"bos_latn",
"bul_cyrl",
"cat_latn",
"ces_latn",
"deu_latn",
"ekk_latn",
"ell_grek",
"eng_latn",
"fin_latn",
"fra_latn_fran",
"glg_latn",
"hrv_latn",
"hun_latn",
"isl_latn",
"ita_latn",
"kat_geor",
"lit_latn",
"mkd_cyrl",
"nld_latn",
"nno_latn",
"nob_latn",
"pol_latn",
"por_latn_port",
"ron_latn",
"slk_latn",
"slv_latn",
"spa_latn_spai",
"srp_cyrl",
"swe_latn",
"tur_latn",
"ukr_cyrl",
],
"n_shot": 0,
"metric": "acc_norm",
},
"global_piqa_prompted": {
"template": "global_piqa_prompted_{lang}",
"langs": [
"als_latn",
"bos_latn",
"bul_cyrl",
"cat_latn",
"ces_latn",
"deu_latn",
"ekk_latn",
"ell_grek",
"eng_latn",
"fin_latn",
"fra_latn_fran",
"glg_latn",
"hrv_latn",
"hun_latn",
"isl_latn",
"ita_latn",
"kat_geor",
"lit_latn",
"mkd_cyrl",
"nld_latn",
"nno_latn",
"nob_latn",
"pol_latn",
"por_latn_port",
"ron_latn",
"slk_latn",
"slv_latn",
"spa_latn_spai",
"srp_cyrl",
"swe_latn",
"tur_latn",
"ukr_cyrl",
],
"n_shot": 0,
"metric": "exact_match",
},
"include_base_44": {
"template": "include_base_44_{lang}",
"langs": [
"albanian",
"basque",
"bulgarian",
"croatian",
"dutch",
"estonian",
"finnish",
"french",
"georgian",
"german",
"greek",
"hungarian",
"italian",
"lithuanian",
"north_macedonian",
"polish",
"portuguese",
"serbian",
"spanish",
"turkish",
"ukrainian",
],
"n_shot": 0,
"metric": "acc",
},
# --- directional benchmarks: one family per direction ------------------ #
"flores200_x_to_en": {
"template": "flores200:{lang}-eng_Latn",
"langs": [
"bul_Cyrl",
"hrv_Latn",
"ces_Latn",
"dan_Latn",
"nld_Latn",
"est_Latn",
"fin_Latn",
"fra_Latn",
"deu_Latn",
"ell_Grek",
"hun_Latn",
"gle_Latn",
"ita_Latn",
"lvs_Latn",
"lit_Latn",
"mlt_Latn",
"pol_Latn",
"por_Latn",
"ron_Latn",
"slk_Latn",
"slv_Latn",
"spa_Latn",
"swe_Latn",
"cat_Latn",
"eus_Latn",
"glg_Latn",
"bos_Latn",
"kat_Geor",
"mkd_Cyrl",
"als_Latn",
"srp_Cyrl",
"tur_Latn",
"ukr_Cyrl",
"isl_Latn",
"nob_Latn",
],
"n_shot": 0,
"metric": "chrf++",
"direction": "X\u2192en",
},
"flores200_en_to_x": {
"template": "flores200:eng_Latn-{lang}",
"langs": [
"bul_Cyrl",
"hrv_Latn",
"ces_Latn",
"dan_Latn",
"nld_Latn",
"est_Latn",
"fin_Latn",
"fra_Latn",
"deu_Latn",
"ell_Grek",
"hun_Latn",
"gle_Latn",
"ita_Latn",
"lvs_Latn",
"lit_Latn",
"mlt_Latn",
"pol_Latn",
"por_Latn",
"ron_Latn",
"slk_Latn",
"slv_Latn",
"spa_Latn",
"swe_Latn",
"cat_Latn",
"eus_Latn",
"glg_Latn",
"bos_Latn",
"kat_Geor",
"mkd_Cyrl",
"als_Latn",
"srp_Cyrl",
"tur_Latn",
"ukr_Cyrl",
"isl_Latn",
"nob_Latn",
],
"n_shot": 0,
"metric": "chrf++",
"direction": "en\u2192X",
},
"opensubtitles_x_to_en": {
"template": "opensubtitles_multi40_{lang}_to_en",
"langs": [
"bg",
"hr",
"cs",
"da",
"nl",
"et",
"fi",
"fr",
"de",
"el",
"hu",
"it",
"lv",
"lt",
"pl",
"pt",
"ro",
"sk",
"sl",
"es",
"sv",
"sr",
"tr",
"uk",
"no",
],
"n_shot": 0,
"metric": "bleu",
"direction": "X\u2192en",
},
"opensubtitles_en_to_x": {
"template": "opensubtitles_multi40_en_to_{lang}",
"langs": [
"bg",
"hr",
"cs",
"da",
"nl",
"et",
"fi",
"fr",
"de",
"el",
"hu",
"it",
"lv",
"lt",
"pl",
"pt",
"ro",
"sk",
"sl",
"es",
"sv",
"sr",
"tr",
"uk",
"no",
],
"n_shot": 0,
"metric": "bleu",
"direction": "en\u2192X",
},
"polymath": {
"template": "polymath_{lang}_{tier}",
"langs": ["de", "en", "es", "fr", "it", "pt"],
"n_shot": 0,
"metric": "exact_match",
"tiers": ["low", "medium", "high", "top"],
},
# --- dclm-core-22: single-task (English) benchmarks, one family per
# task (group-prefixed key, lang=None). n_shot per task-groups.yaml
# (hellaswag is evaluated at both 0 and 10 shots — the variants
# average into one family and its plot label shows n_shot=0/10);
# metric per task_metrics, omitted where undeclared (jeopardy) so the
# y-label falls back to the metric observed in the data. ------------- #
"dclm_core_22_agieval_lsat_ar": {
"template": "agieval_lsat_ar",
"langs": [None],
"n_shot": 3,
"metric": "acc",
},
"dclm_core_22_arc_easy": {
"template": "arc_easy",
"langs": [None],
"n_shot": 10,
"metric": "acc_norm",
},
"dclm_core_22_arc_challenge": {
"template": "arc_challenge",
"langs": [None],
"n_shot": 10,
"metric": "acc_norm",
},
"dclm_core_22_boolq": {
"template": "boolq",
"langs": [None],
"n_shot": 10,
"metric": "acc",
},
"dclm_core_22_commonsense_qa": {
"template": "commonsense_qa",
"langs": [None],
"n_shot": 10,
"metric": "acc",
},
"dclm_core_22_copa": {
"template": "copa",
"langs": [None],
"n_shot": 0,
"metric": "acc",
},
"dclm_core_22_hellaswag": {
"template": "hellaswag",
"langs": [None],
"n_shot": [0, 10],
"metric": "acc_norm",
},
"dclm_core_22_openbookqa": {
"template": "openbookqa",
"langs": [None],
"n_shot": 0,
"metric": "acc_norm",
},
"dclm_core_22_piqa": {
"template": "piqa",
"langs": [None],
"n_shot": 10,
"metric": "acc_norm",
},
"dclm_core_22_bigbench_language_identification_multiple_choice": {
"template": "bigbench_language_identification_multiple_choice",
"langs": [None],
"n_shot": 10,
"metric": "acc",
},
"dclm_core_22_winogrande": {
"template": "winogrande",
"langs": [None],
"n_shot": 0,
"metric": "acc",
},
"dclm_core_22_wsc273": {
"template": "wsc273",
"langs": [None],
"n_shot": 0,
"metric": "acc",
},
"dclm_core_22_lambada_openai": {
"template": "lambada_openai",
"langs": [None],
"n_shot": 0,
"metric": "acc",
},
"dclm_core_22_bigbench_qa_wikidata_generate_until": {
"template": "bigbench_qa_wikidata_generate_until",
"langs": [None],
"n_shot": 10,
"metric": "exact_match",
},
"dclm_core_22_bigbench_dyck_languages_generate_until": {
"template": "bigbench_dyck_languages_generate_until",
"langs": [None],
"n_shot": 10,
"metric": "exact_match",
},
"dclm_core_22_bigbench_operators_generate_until": {
"template": "bigbench_operators_generate_until",
"langs": [None],
"n_shot": 10,
"metric": "exact_match",
},
"dclm_core_22_bigbench_repeat_copy_logic_generate_until": {
"template": "bigbench_repeat_copy_logic_generate_until",
"langs": [None],
"n_shot": 10,
"metric": "exact_match",
},
"dclm_core_22_bigbench_cs_algorithms_generate_until": {
"template": "bigbench_cs_algorithms_generate_until",
"langs": [None],
"n_shot": 10,
"metric": "exact_match",
},
"dclm_core_22_coqa": {
"template": "coqa",
"langs": [None],
"n_shot": 0,
"metric": "f1",
},
"dclm_core_22_squadv2": {
"template": "squadv2",
"langs": [None],
"n_shot": 10,
"metric": "f1",
},
"dclm_core_22_jeopardy": {
"template": "jeopardy",
"langs": [None],
"n_shot": 10,
},
# --- reasoning: single-task (English) benchmarks, one family per task
# (group-prefixed key, lang=None). n_shot per task-groups.yaml; metrics
# are not declared there, so they are omitted and the y-label falls
# back to the metric observed in the data. ---------------------------- #
"reasoning_gsm8k": {
"template": "gsm8k",
"langs": [None],
"n_shot": 4,
},
"reasoning_ifeval": {
"template": "ifeval",
"langs": [None],
"n_shot": 0,
},
"reasoning_mbpp": {
"template": "mbpp",
"langs": [None],
"n_shot": 3,
},
"reasoning_GPQADiamond": {
"template": "GPQADiamond",
"langs": [None],
"n_shot": 0,
},
"reasoning_MATH500": {
"template": "MATH500",
"langs": [None],
"n_shot": 0,
},
"reasoning_LiveCodeBench": {
"template": "LiveCodeBench",
"langs": [None],
"n_shot": 0,
},
"reasoning_HumanEval": {
"template": "HumanEval",
"langs": [None],
"n_shot": 0,
},
"reasoning_AIME24": {
"template": "AIME24",
"langs": [None],
"n_shot": 0,
},
"reasoning_AIME25": {
"template": "AIME25",
"langs": [None],
"n_shot": 0,
},
"reasoning_AMC23": {
"template": "AMC23",
"langs": [None],
"n_shot": 0,
},
}
def _build_task_index() -> Dict[str, List]:
"""Reverse map: task_name -> (family_key, lang)."""
idx: Dict[str, Tuple[str, str]] = {}
for fam_key, spec in FAMILIES.items():
tmpl = spec["template"]
if "tiers" in spec:
for tier in spec["tiers"]:
for lang in spec["langs"]:
idx[tmpl.format(lang=lang, tier=tier)] = (fam_key, lang, tier)
else:
for lang in spec["langs"]:
idx[tmpl.format(lang=lang)] = (fam_key, lang)
return idx
_TASK_INDEX = _build_task_index()
# --------------------------------------------------------------------------- #
# Parsing helpers
# --------------------------------------------------------------------------- #
_ITER_RE = re.compile(r"iter_(\d+)")
_HF_MODELS_RE = re.compile(r"/hf_models/([^/]+)")
def parse_model(model_name: str) -> Tuple[str, Optional[int]]:
"""Return (run_name, step). step is None if no iter_ token is present."""
m_iter = _ITER_RE.search(model_name)
step = int(m_iter.group(1)) if m_iter else None
m_run = _HF_MODELS_RE.search(model_name)
if m_run:
run = m_run.group(1)
else:
# Fallback: use the final path component (without iter_ suffix).
base = model_name.rstrip("/").split("/")[-1]
run = _ITER_RE.sub("", base).strip("_") or base
return run, step
def _base_metric(metric_name: str) -> str:
"""'acc_norm,none' -> 'acc_norm', 'chrf++' -> 'chrf++'."""
if not isinstance(metric_name, str):
return ""
return metric_name.split(",", 1)[0]
def classify_task(task: str) -> Tuple[str, Optional[str]]:
"""Return (family_key, lang). Unmatched task -> (task, None)."""
hit = _TASK_INDEX.get(task)
if hit is not None:
return hit
# Fallback: single-language benchmark (task is its own family).
return task, None
def declared_task_metric(task: str) -> Optional[str]:
"""Metric declared in FAMILIES for the task's family, or None when the
family declares no metric (the metric then falls back to the one
observed in the data)."""
fam_key = classify_task(task)[0]
spec = FAMILIES.get(fam_key)
if spec and spec.get("metric"):
return spec["metric"]
return None
# --------------------------------------------------------------------------- #
# Origin checkpoint (common starting point of all model lines)
# --------------------------------------------------------------------------- #
# Training step used for the prepended origin point when the checkpoint path
# (or its resolved model_name) carries no iter_ token. Matches
# baby_9b_dense_before-annealing/checkpoints/iter_0953312.
DEFAULT_ORIGIN_STEP = 953312
def _hf_models_tail(name: str) -> str:
"""Path identity from ``/hf_models/`` onwards (ignores the mount-point
prefix, so /pfs/lustrep4/scratch/... and /scratch/... compare equal)."""
name = str(name).rstrip("/")
i = name.find("/hf_models/")
return name[i:] if i != -1 else name
def _resolve_origin_model(df: pd.DataFrame, path: str) -> str:
"""Map a user-supplied checkpoint path to a model_name present in the data.
Matching order: exact string, /hf_models/ tail, (run, step) via
parse_model, then a unique run-only match (with a warning). Raises
SystemExit listing the evaluated models if nothing matches."""
candidates = list(df["model_name"].unique())
p = str(path).rstrip("/")
if p in candidates:
return p
tail = _hf_models_tail(p)
for c in candidates:
if _hf_models_tail(c) == tail:
return c
run, step = parse_model(p)
for c in candidates:
c_run, c_step = parse_model(c)
if c_run == run and step is not None and c_step == step:
return c
same_run = [c for c in candidates if parse_model(c)[0] == run]
if len(same_run) == 1:
print(
f"[warn] --origin_checkpoint: no exact match for {p}; using the "
f"only evaluated checkpoint of run '{run}': {same_run[0]}"
)
return same_run[0]
avail = "\n ".join(sorted(candidates))
raise SystemExit(
f"[error] --origin_checkpoint: '{path}' is not among the evaluated "
f"models. Evaluated model_names:\n {avail}"
)
# --------------------------------------------------------------------------- #
# Data loading
# --------------------------------------------------------------------------- #
def gather_input_files(inputs: List[str]) -> List[Path]:
paths: List[Path] = []
for inp in inputs:
p = Path(inp)
if p.is_dir():
paths.extend(sorted(p.rglob("results.csv")))
elif p.is_file() and p.name == "results.csv":
paths.append(p)
elif p.is_file():
# Accept any CSV the user points us at.
paths.append(p)
else:
print(f"[warn] input not found: {inp}", file=sys.stderr)
# de-duplicate while preserving order
seen = set()
out: List[Path] = []
for p in paths:
rp = p.resolve()
if rp not in seen:
seen.add(rp)
out.append(p)
return out
def load_results(inputs: List[str]) -> pd.DataFrame:
files = gather_input_files(inputs)
if not files:
raise SystemExit(
"No results.csv files found. Pass --input <file|dir> (repeatable)."
)
frames: List[pd.DataFrame] = []
for f in files:
df = pd.read_csv(f)
df["source_file"] = str(f)
frames.append(df)
print(f"[info] loaded {len(df)} rows from {f}")
df = pd.concat(frames, ignore_index=True)
required = {"model_name", "task", "n_shot", "performance", "metric_name"}
missing = required - set(df.columns)
if missing:
raise SystemExit(f"Missing required columns: {sorted(missing)}")
# Keep only the metric declared in FAMILIES for each task: result
# files from recent oellm-eval versions report several metrics per task
# (e.g. belebele 'acc' and 'acc_norm'); FAMILIES decides which one is plotted.
# Tasks whose family declares no metric and unknown tasks keep all
# their metrics.
declared = df["task"].map(declared_task_metric)
keep = declared.isna() | df["metric_name"].map(_base_metric).eq(declared)
dropped = df.loc[~keep]
if not dropped.empty:
print(
f"[info] metric filter: dropped {len(dropped)} row(s) whose "
"metric_name is not the metric declared in FAMILIES"
)
gone = sorted(set(dropped["task"]) - set(df.loc[keep, "task"]))
if gone:
fams = sorted({classify_task(t)[0] for t in gone})
print(
f"[warn] {len(gone)} task(s) report no row with the metric "
f"declared in FAMILIES and were dropped entirely (families: "
f"{', '.join(fams)}); check the 'metric' entries in FAMILIES"
)
df = df.loc[keep]
# Dedup: later files / later rows win (matches oellm-eval collect semantics).
df = df.drop_duplicates(
subset=["model_name", "task", "n_shot"], keep="last"
).reset_index(drop=True)
return df
# --------------------------------------------------------------------------- #
# Supergroup filtering
# --------------------------------------------------------------------------- #
NAMING_ONLY_SUPERGROUPS = ("oellm-multilingual-eu", "dclm-core-22")
def load_task_groups(path: Path) -> Dict[str, str]:
"""Read the supergroups file (headerless two-column CSV: task name,
supergroup) into a task -> supergroup dict."""
groups: Dict[str, str] = {}
with open(path, newline="", encoding="utf-8") as fh:
for lineno, row in enumerate(csv.reader(fh), 1):
fields = [f.strip() for f in row]
if len(fields) != 2 or not all(fields):
raise SystemExit(
f"[error] {path}:{lineno}: expected 'task,supergroup', "
f"got: {row}"
)
task, supergroup = fields
if task in groups and groups[task] != supergroup:
raise SystemExit(
f"[error] {path}:{lineno}: task '{task}' listed with "
f"conflicting supergroups '{groups[task]}' and "
f"'{supergroup}'"
)
groups[task] = supergroup
if not groups:
raise SystemExit(f"[error] no task groupings found in {path}")
return groups
def _resolve_groups_path(path_str: str) -> Optional[Path]:
"""Groups file path as given (CWD-relative), else relative to the script."""
p = Path(path_str)
if p.is_file():
return p
alt = Path(__file__).resolve().parent / path_str
return alt if alt.is_file() else None
def filter_by_supergroup(
df: pd.DataFrame, supergroup: str, groups_file: str
) -> pd.DataFrame:
"""Keep only the tasks the supergroups file assigns to ``supergroup``.
A supergroup defined in the groups file filters tasks (rows whose task
is not listed in the file are dropped as well); any other value (the
naming-only supergroups) leaves the data untouched and is used just for
the summary plot title and averaged_scores CSV name."""
path = _resolve_groups_path(groups_file)
if path is None:
if supergroup in NAMING_ONLY_SUPERGROUPS:
print(
f"[warn] supergroups file not found ({groups_file}); not "
f"filtering tasks for supergroup '{supergroup}'"
)
return df
raise SystemExit(
f"[error] --supergroup '{supergroup}' requires the supergroups "
f"file, not found: {groups_file} (also tried relative to the "
"script). Pass --supergroups_file."
)
groups = load_task_groups(path)
available = sorted(set(groups.values()))
if supergroup not in available:
if supergroup in NAMING_ONLY_SUPERGROUPS:
print(
f"[warn] supergroup '{supergroup}' is not defined in {path}; "
"naming only, no task filtering"
)