Upload full run contents (scripts, checkpoints, and results) (part 13)
Browse filesThis view is limited to 50 files because it contains too many changes. Β See raw diff
- babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/entity_tracking/entity_tracking/best_temperature_report.txt +28 -0
- babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/entity_tracking/entity_tracking/predictions.json +0 -0
- babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/ewok/ewok_filtered/best_temperature_report.txt +37 -0
- babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/ewok/ewok_filtered/predictions.json +0 -0
- babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/global_piqa_nonparallel/global_piqa_nonparallel/best_temperature_report.txt +107 -0
- babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/global_piqa_nonparallel/global_piqa_nonparallel/predictions.json +1 -0
- babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/global_piqa_parallel/global_piqa_parallel/best_temperature_report.txt +110 -0
- babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/global_piqa_parallel/global_piqa_parallel/predictions.json +1 -0
- babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/reading/correlations.txt +11 -0
- babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/reading/prediction.jsonl +0 -0
- babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/reading/predictions.json +0 -0
- babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/reading/predictive_power.jsonl +11 -0
- babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/reading/predictive_power_spillover.jsonl +11 -0
- babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/reading/report.txt +2 -0
- babylm_eval_repo/strict/scripts/aoa_bos_curves.py +203 -0
- babylm_eval_repo/strict/scripts/collate_preds.sh +7 -0
- babylm_eval_repo/strict/scripts/download_evals.py +7 -0
- babylm_eval_repo/strict/scripts/eval_aoa.sh +24 -0
- babylm_eval_repo/strict/scripts/eval_devbench.sh +17 -0
- babylm_eval_repo/strict/scripts/eval_finetuning.sh +174 -0
- babylm_eval_repo/strict/scripts/eval_multimodal.sh +35 -0
- babylm_eval_repo/strict/scripts/eval_zero_shot.sh +21 -0
- babylm_eval_repo/strict/scripts/eval_zero_shot_fast.sh +18 -0
- babylm_eval_repo/strict/scripts/eval_zero_shot_fast_all_revisions.sh +27 -0
- babylm_eval_repo/strict/scripts/eval_zero_shot_global_piqa.sh +68 -0
- babylm_eval_repo/strict/scripts/print_results_table.py +138 -0
- checkpoints/xpertgpt_fresh/bpe_vocab_16k.json +0 -0
- checkpoints/xpertgpt_fresh/chck_100M/config.json +17 -0
- checkpoints/xpertgpt_fresh/chck_100M/configuration_xpertgpt.py +36 -0
- checkpoints/xpertgpt_fresh/chck_100M/modeling_xpertgpt.py +456 -0
- checkpoints/xpertgpt_fresh/chck_100M/pytorch_model.bin +3 -0
- checkpoints/xpertgpt_fresh/chck_100M/tokenizer.json +0 -0
- checkpoints/xpertgpt_fresh/chck_100M/tokenizer_config.json +10 -0
- checkpoints/xpertgpt_fresh/chck_10M/config.json +17 -0
- checkpoints/xpertgpt_fresh/chck_10M/configuration_xpertgpt.py +36 -0
- checkpoints/xpertgpt_fresh/chck_10M/modeling_xpertgpt.py +456 -0
- checkpoints/xpertgpt_fresh/chck_10M/pytorch_model.bin +3 -0
- checkpoints/xpertgpt_fresh/chck_10M/tokenizer.json +0 -0
- checkpoints/xpertgpt_fresh/chck_10M/tokenizer_config.json +10 -0
- checkpoints/xpertgpt_fresh/chck_1M/config.json +17 -0
- checkpoints/xpertgpt_fresh/chck_1M/configuration_xpertgpt.py +36 -0
- checkpoints/xpertgpt_fresh/chck_1M/modeling_xpertgpt.py +456 -0
- checkpoints/xpertgpt_fresh/chck_1M/pytorch_model.bin +3 -0
- checkpoints/xpertgpt_fresh/chck_1M/tokenizer.json +0 -0
- checkpoints/xpertgpt_fresh/chck_1M/tokenizer_config.json +10 -0
- checkpoints/xpertgpt_fresh/chck_20M/config.json +17 -0
- checkpoints/xpertgpt_fresh/chck_20M/configuration_xpertgpt.py +36 -0
- checkpoints/xpertgpt_fresh/chck_20M/modeling_xpertgpt.py +456 -0
- checkpoints/xpertgpt_fresh/chck_20M/pytorch_model.bin +3 -0
- checkpoints/xpertgpt_fresh/chck_20M/tokenizer.json +0 -0
babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/entity_tracking/entity_tracking/best_temperature_report.txt
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
TEMPERATURE: 1.00
|
| 2 |
+
|
| 3 |
+
### UID ACCURACY
|
| 4 |
+
ambiref_0_ops: 17.72
|
| 5 |
+
ambiref_1_ops: 17.29
|
| 6 |
+
ambiref_2_ops: 18.40
|
| 7 |
+
ambiref_3_ops: 19.80
|
| 8 |
+
ambiref_4_ops: 22.12
|
| 9 |
+
ambiref_5_ops: 25.20
|
| 10 |
+
regular_0_ops: 18.38
|
| 11 |
+
regular_1_ops: 15.89
|
| 12 |
+
regular_2_ops: 23.21
|
| 13 |
+
regular_3_ops: 22.12
|
| 14 |
+
regular_4_ops: 22.16
|
| 15 |
+
regular_5_ops: 27.66
|
| 16 |
+
move_contents_0_ops: 17.44
|
| 17 |
+
move_contents_1_ops: 19.68
|
| 18 |
+
move_contents_2_ops: 18.30
|
| 19 |
+
move_contents_3_ops: 17.98
|
| 20 |
+
move_contents_4_ops: 20.11
|
| 21 |
+
move_contents_5_ops: 25.86
|
| 22 |
+
regular: 21.57
|
| 23 |
+
ambiref: 20.09
|
| 24 |
+
move_contents: 19.90
|
| 25 |
+
|
| 26 |
+
### AVERAGE ACCURACY
|
| 27 |
+
20.52
|
| 28 |
+
|
babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/entity_tracking/entity_tracking/predictions.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/ewok/ewok_filtered/best_temperature_report.txt
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
TEMPERATURE: 1.00
|
| 2 |
+
|
| 3 |
+
### UID ACCURACY
|
| 4 |
+
social-interactions: 57.48
|
| 5 |
+
physical-interactions: 48.92
|
| 6 |
+
social-relations: 49.94
|
| 7 |
+
material-dynamics: 47.01
|
| 8 |
+
quantitative-properties: 60.19
|
| 9 |
+
physical-relations: 51.34
|
| 10 |
+
material-properties: 45.88
|
| 11 |
+
agent-properties: 49.14
|
| 12 |
+
physical-dynamics: 48.33
|
| 13 |
+
spatial-relations: 48.78
|
| 14 |
+
social-properties: 60.98
|
| 15 |
+
|
| 16 |
+
### CONTEXT_TYPE ACCURACY
|
| 17 |
+
direct: 50.03
|
| 18 |
+
indirect: 50.76
|
| 19 |
+
|
| 20 |
+
### CONTEXT_CONTRAST ACCURACY
|
| 21 |
+
antonym: 51.81
|
| 22 |
+
variable swap: 49.96
|
| 23 |
+
other: 51.02
|
| 24 |
+
variable_swap: 43.33
|
| 25 |
+
negation: 48.42
|
| 26 |
+
active-passive: 40.00
|
| 27 |
+
material: 47.02
|
| 28 |
+
number: 62.50
|
| 29 |
+
game: 25.00
|
| 30 |
+
|
| 31 |
+
### TARGET_CONTRAST ACCURACY
|
| 32 |
+
concept swap: 51.07
|
| 33 |
+
variable swap: 49.51
|
| 34 |
+
|
| 35 |
+
### AVERAGE ACCURACY
|
| 36 |
+
51.64
|
| 37 |
+
|
babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/ewok/ewok_filtered/predictions.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/global_piqa_nonparallel/global_piqa_nonparallel/best_temperature_report.txt
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
TEMPERATURE: 1.00
|
| 2 |
+
|
| 3 |
+
### UID ACCURACY
|
| 4 |
+
group0123_ex000088_eng_latn_0_v1: 100.00
|
| 5 |
+
group0123_ex000012_eng_latn_0_v1: 0.00
|
| 6 |
+
group0123_ex000022_eng_latn_0_v1: 100.00
|
| 7 |
+
group0123_ex000102_eng_latn_0_v1: 0.00
|
| 8 |
+
group0123_ex000028_eng_latn_0_v1: 100.00
|
| 9 |
+
group0123_ex000002_eng_latn_0_v1: 0.00
|
| 10 |
+
group0123_ex000081_eng_latn_0_v1: 0.00
|
| 11 |
+
group0123_ex000018_eng_latn_0_v1: 0.00
|
| 12 |
+
group0123_ex000000_eng_latn_0_v1: 100.00
|
| 13 |
+
group0123_ex000046_eng_latn_0_v1: 100.00
|
| 14 |
+
group0123_ex000075_eng_latn_0_v1: 0.00
|
| 15 |
+
group0123_ex000033_eng_latn_0_v1: 100.00
|
| 16 |
+
group0123_ex000073_eng_latn_0_v1: 100.00
|
| 17 |
+
group0123_ex000021_eng_latn_0_v1: 100.00
|
| 18 |
+
group0123_ex000095_eng_latn_0_v1: 0.00
|
| 19 |
+
group0123_ex000013_eng_latn_0_v1: 100.00
|
| 20 |
+
group0123_ex000030_eng_latn_0_v1: 0.00
|
| 21 |
+
group0123_ex000059_eng_latn_0_v1: 100.00
|
| 22 |
+
group0123_ex000089_eng_latn_0_v1: 100.00
|
| 23 |
+
group0123_ex000061_eng_latn_0_v1: 100.00
|
| 24 |
+
group0123_ex000053_eng_latn_0_v1: 0.00
|
| 25 |
+
group0123_ex000076_eng_latn_0_v1: 0.00
|
| 26 |
+
group0123_ex000064_eng_latn_0_v1: 100.00
|
| 27 |
+
group0123_ex000041_eng_latn_0_v1: 0.00
|
| 28 |
+
group0123_ex000031_eng_latn_0_v1: 0.00
|
| 29 |
+
group0123_ex000034_eng_latn_0_v1: 100.00
|
| 30 |
+
group0123_ex000062_eng_latn_0_v1: 0.00
|
| 31 |
+
group0123_ex000036_eng_latn_0_v1: 100.00
|
| 32 |
+
group0123_ex000056_eng_latn_0_v1: 0.00
|
| 33 |
+
group0123_ex000070_eng_latn_0_v1: 0.00
|
| 34 |
+
group0123_ex000045_eng_latn_0_v1: 100.00
|
| 35 |
+
group0123_ex000014_eng_latn_0_v1: 0.00
|
| 36 |
+
group0123_ex000094_eng_latn_0_v1: 100.00
|
| 37 |
+
group0123_ex000052_eng_latn_0_v1: 0.00
|
| 38 |
+
group0123_ex000006_eng_latn_0_v1: 0.00
|
| 39 |
+
group0123_ex000007_eng_latn_0_v1: 100.00
|
| 40 |
+
group0123_ex000091_eng_latn_0_v1: 100.00
|
| 41 |
+
group0123_ex000010_eng_latn_0_v1: 0.00
|
| 42 |
+
group0123_ex000071_eng_latn_0_v1: 100.00
|
| 43 |
+
group0123_ex000072_eng_latn_0_v1: 100.00
|
| 44 |
+
group0123_ex000042_eng_latn_0_v1: 100.00
|
| 45 |
+
group0123_ex000100_eng_latn_0_v1: 100.00
|
| 46 |
+
group0123_ex000039_eng_latn_0_v1: 0.00
|
| 47 |
+
group0123_ex000024_eng_latn_0_v1: 100.00
|
| 48 |
+
group0123_ex000025_eng_latn_0_v1: 0.00
|
| 49 |
+
group0123_ex000029_eng_latn_0_v1: 0.00
|
| 50 |
+
group0123_ex000068_eng_latn_0_v1: 0.00
|
| 51 |
+
group0123_ex000086_eng_latn_0_v1: 0.00
|
| 52 |
+
group0123_ex000020_eng_latn_0_v1: 0.00
|
| 53 |
+
group0123_ex000057_eng_latn_0_v1: 0.00
|
| 54 |
+
group0123_ex000092_eng_latn_0_v1: 0.00
|
| 55 |
+
group0123_ex000037_eng_latn_0_v1: 100.00
|
| 56 |
+
group0123_ex000044_eng_latn_0_v1: 0.00
|
| 57 |
+
group0123_ex000083_eng_latn_0_v1: 100.00
|
| 58 |
+
group0123_ex000008_eng_latn_0_v1: 100.00
|
| 59 |
+
group0123_ex000032_eng_latn_0_v1: 0.00
|
| 60 |
+
group0123_ex000096_eng_latn_0_v1: 100.00
|
| 61 |
+
group0123_ex000084_eng_latn_0_v1: 0.00
|
| 62 |
+
group0123_ex000038_eng_latn_0_v1: 100.00
|
| 63 |
+
group0123_ex000005_eng_latn_0_v1: 100.00
|
| 64 |
+
group0123_ex000058_eng_latn_0_v1: 0.00
|
| 65 |
+
group0123_ex000001_eng_latn_0_v1: 0.00
|
| 66 |
+
group0123_ex000047_eng_latn_0_v1: 100.00
|
| 67 |
+
group0123_ex000069_eng_latn_0_v1: 0.00
|
| 68 |
+
group0123_ex000023_eng_latn_0_v1: 0.00
|
| 69 |
+
group0123_ex000098_eng_latn_0_v1: 100.00
|
| 70 |
+
group0123_ex000011_eng_latn_0_v1: 100.00
|
| 71 |
+
group0123_ex000009_eng_latn_0_v1: 0.00
|
| 72 |
+
group0123_ex000055_eng_latn_0_v1: 0.00
|
| 73 |
+
group0123_ex000027_eng_latn_0_v1: 0.00
|
| 74 |
+
group0123_ex000051_eng_latn_0_v1: 0.00
|
| 75 |
+
group0123_ex000004_eng_latn_0_v1: 0.00
|
| 76 |
+
group0123_ex000080_eng_latn_0_v1: 0.00
|
| 77 |
+
group0123_ex000054_eng_latn_0_v1: 0.00
|
| 78 |
+
group0123_ex000016_eng_latn_0_v1: 100.00
|
| 79 |
+
group0123_ex000066_eng_latn_0_v1: 0.00
|
| 80 |
+
group0123_ex000079_eng_latn_0_v1: 0.00
|
| 81 |
+
group0123_ex000074_eng_latn_0_v1: 0.00
|
| 82 |
+
group0123_ex000090_eng_latn_0_v1: 0.00
|
| 83 |
+
group0123_ex000099_eng_latn_0_v1: 100.00
|
| 84 |
+
group0123_ex000060_eng_latn_0_v1: 100.00
|
| 85 |
+
group0123_ex000085_eng_latn_0_v1: 100.00
|
| 86 |
+
group0123_ex000043_eng_latn_0_v1: 100.00
|
| 87 |
+
group0123_ex000050_eng_latn_0_v1: 0.00
|
| 88 |
+
group0123_ex000077_eng_latn_0_v1: 100.00
|
| 89 |
+
group0123_ex000078_eng_latn_0_v1: 100.00
|
| 90 |
+
group0123_ex000097_eng_latn_0_v1: 100.00
|
| 91 |
+
group0123_ex000067_eng_latn_0_v1: 100.00
|
| 92 |
+
group0123_ex000035_eng_latn_0_v1: 0.00
|
| 93 |
+
group0123_ex000048_eng_latn_0_v1: 0.00
|
| 94 |
+
group0123_ex000040_eng_latn_0_v1: 100.00
|
| 95 |
+
group0123_ex000003_eng_latn_0_v1: 0.00
|
| 96 |
+
group0123_ex000101_eng_latn_0_v1: 0.00
|
| 97 |
+
group0123_ex000082_eng_latn_0_v1: 0.00
|
| 98 |
+
group0123_ex000017_eng_latn_0_v1: 0.00
|
| 99 |
+
group0123_ex000015_eng_latn_0_v1: 0.00
|
| 100 |
+
group0123_ex000063_eng_latn_0_v1: 0.00
|
| 101 |
+
group0123_ex000026_eng_latn_0_v1: 0.00
|
| 102 |
+
group0123_ex000103_eng_latn_0_v1: 0.00
|
| 103 |
+
group0123_ex000049_eng_latn_0_v1: 100.00
|
| 104 |
+
|
| 105 |
+
### AVERAGE ACCURACY
|
| 106 |
+
44.00
|
| 107 |
+
|
babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/global_piqa_nonparallel/global_piqa_nonparallel/predictions.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"group0123_ex000088_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000088_eng_latn_0_v1_0", "pred": " use a muffin tin for the various condiments."}]}, "group0123_ex000012_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000012_eng_latn_0_v1_0", "pred": " tape holiday treats to the wall in pattern of a tree."}]}, "group0123_ex000022_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000022_eng_latn_0_v1_0", "pred": " Add whipped cream, nuts, and chocolate on top of ice cream."}]}, "group0123_ex000102_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000102_eng_latn_0_v1_0", "pred": " cup."}]}, "group0123_ex000028_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000028_eng_latn_0_v1_0", "pred": " Tackle the opponent in their own end zone."}]}, "group0123_ex000002_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000002_eng_latn_0_v1_0", "pred": " use a knife to crimp the edges."}]}, "group0123_ex000081_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000081_eng_latn_0_v1_0", "pred": " bite hard into the candy with your mouth closed in the dark."}]}, "group0123_ex000018_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000018_eng_latn_0_v1_0", "pred": " use an electric knife with the blade pointed away from the bird, and slice thin slices of turkey breast."}]}, "group0123_ex000000_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000000_eng_latn_0_v1_0", "pred": " To make pie crust, you will need flour, sugar, butter, and ice water."}]}, "group0123_ex000046_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000046_eng_latn_0_v1_0", "pred": " Add your dry ingredients to the bowl and stir them together well with a spoon, then add wet ingredients and stir it all together until joins, then use your hands to mix the dough until it forms a solid ball."}]}, "group0123_ex000075_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000075_eng_latn_0_v1_0", "pred": " hit more baseballs than the opposing team."}]}, "group0123_ex000033_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000033_eng_latn_0_v1_0", "pred": " Toast 2 frozen whole-wheat waffles. Spread one with peanut butter and the other with jelly. Sandwich together."}]}, "group0123_ex000073_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000073_eng_latn_0_v1_0", "pred": " Place a banana cut down the middle into a bowl and then place three scoops of ice cream along the banana. Add chocolate syrup on top if you'd like, and then a cherry on top."}]}, "group0123_ex000021_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000021_eng_latn_0_v1_0", "pred": " apply lemon juice to your hair and then sit in the sun."}]}, "group0123_ex000095_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000095_eng_latn_0_v1_0", "pred": " place 2-3 marshmallows in your bag of brown sugar. Replace the marshmallows when they are soft."}]}, "group0123_ex000013_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000013_eng_latn_0_v1_0", "pred": " many people use a pinched grip like they are holding a pencil or throwing a dart. You have much more control if you hold razor in between the handle and razor. In most circumstances try to hold the handle between you middle and pointer finger while steadying the blade with your thumb. Getting behind the neck can be tricky and you may have to modify your grip."}]}, "group0123_ex000030_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000030_eng_latn_0_v1_0", "pred": " Let the plaster soften."}]}, "group0123_ex000059_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000059_eng_latn_0_v1_0", "pred": " place 12 strawberries in a freezer and leave overnight to freeze. Place frozen strawberries in blender with 1/4 cup milk, 1 tablespoon of sugar, 1 cup plain yogurt, and 1/2 teaspoon of vanilla extract. Blend until thick and pureed."}]}, "group0123_ex000089_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000089_eng_latn_0_v1_0", "pred": " tighten the bow then apply violin rosin for 10 strokes."}]}, "group0123_ex000061_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000061_eng_latn_0_v1_0", "pred": " cannot cover a mop."}]}, "group0123_ex000053_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000053_eng_latn_0_v1_0", "pred": " by wrapping brown sugar in parchment paper and put in oven at 300 degrees for a few minutes."}]}, "group0123_ex000076_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000076_eng_latn_0_v1_0", "pred": " Place the metal end into the latch."}]}, "group0123_ex000064_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000064_eng_latn_0_v1_0", "pred": " use the front camera."}]}, "group0123_ex000041_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000041_eng_latn_0_v1_0", "pred": " Mix 2 cups of soda with one cup of sugar in a quart jar. Punch holes in the lid and sprinkle around the outside of your house."}]}, "group0123_ex000031_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000031_eng_latn_0_v1_0", "pred": " spray water on pole to make it slippery."}]}, "group0123_ex000034_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000034_eng_latn_0_v1_0", "pred": " Cover the beverage with wet paper towels and place it in the freezer."}]}, "group0123_ex000062_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000062_eng_latn_0_v1_0", "pred": " You can use a new t-shirt."}]}, "group0123_ex000036_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000036_eng_latn_0_v1_0", "pred": " Put desired number of eggs in a sauce pan and add enough water to cover. Put on a high heat and let the water come to boil. Continue to cook for 4 minutes. Remove from heat and drain."}]}, "group0123_ex000056_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000056_eng_latn_0_v1_0", "pred": " Put the spinach into a bowl. Run water over it constantly, and use your hands and fingers to help wash off any particles."}]}, "group0123_ex000070_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000070_eng_latn_0_v1_0", "pred": " Pour white vinegar into a small spray bottle. Spray the vinegar evenly onto your stovetop. Then sprinkle baking soda evenly across your stovetop. The baking soda will react with the vinegar, creating a fizzy cleaner that will loosen up grease and grime. Next, put a few drops of dish soap into a bucket or your sink, and fill it with cold water. Dunk your towel into the soapy water, then wring it out lightly so that it\u2019s wet but not dripping. Spread the wet towel over the stovetop, covering the baking soda and vinegar. Let it sit for about 15 minutes. Remove the towel and wipe away the remaining baking soda. To finish off, give your stovetop another spray with the vinegar, and use a microfiber cloth to buff it to a sparkling shine."}]}, "group0123_ex000045_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000045_eng_latn_0_v1_0", "pred": " Put a candle wick in the center of a can of crisco, it will last up to 45 days."}]}, "group0123_ex000014_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000014_eng_latn_0_v1_0", "pred": " swat it with a fly swatter then wait until it lands."}]}, "group0123_ex000094_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000094_eng_latn_0_v1_0", "pred": " use a pencil to mark a line in the center of the board before cutting it."}]}, "group0123_ex000052_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000052_eng_latn_0_v1_0", "pred": " Fill the base with water."}]}, "group0123_ex000006_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000006_eng_latn_0_v1_0", "pred": " 3 cups of strawberries, 3 cups of peaches, 2 cups of honey, and 2/3 cup of vanilla greek yogurt."}]}, "group0123_ex000007_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000007_eng_latn_0_v1_0", "pred": " add baking soda to the water while boiling."}]}, "group0123_ex000091_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000091_eng_latn_0_v1_0", "pred": " Place one foot in front of the other."}]}, "group0123_ex000010_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000010_eng_latn_0_v1_0", "pred": " Turn off the light switch and wait some time for the bulb to cool down if necessary. Place your fingers around the wide part of the bulb, and twist clockwise until the bulb comes out."}]}, "group0123_ex000071_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000071_eng_latn_0_v1_0", "pred": " turn the tip of spray nozzle to \"spray\" then pump the trigger until spray starts coming out."}]}, "group0123_ex000072_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000072_eng_latn_0_v1_0", "pred": " Place cardboard inside the windshield."}]}, "group0123_ex000042_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000042_eng_latn_0_v1_0", "pred": " Carefully cut off any areas which are growing too quickly."}]}, "group0123_ex000100_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000100_eng_latn_0_v1_0", "pred": " can tighten a nut easily."}]}, "group0123_ex000039_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000039_eng_latn_0_v1_0", "pred": " place a slice of ham and a slice of turkey on top of one slice of bread."}]}, "group0123_ex000024_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000024_eng_latn_0_v1_0", "pred": " Tape the letter on the book cover with masking tape."}]}, "group0123_ex000025_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000025_eng_latn_0_v1_0", "pred": " by placing garlic in a plastic bag under cabinet."}]}, "group0123_ex000029_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000029_eng_latn_0_v1_0", "pred": " with small twigs."}]}, "group0123_ex000068_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000068_eng_latn_0_v1_0", "pred": " by pressing the cherries on an upside down bowl."}]}, "group0123_ex000086_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000086_eng_latn_0_v1_0", "pred": " Peel unripened bananas and mash them with a fork."}]}, "group0123_ex000020_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000020_eng_latn_0_v1_0", "pred": " Rub your fingers on stainless steel, like your chopping board."}]}, "group0123_ex000057_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000057_eng_latn_0_v1_0", "pred": " Use a hair dryer to heat up a spot on the PVC pipe and slowly apply pressure on the area you want to bend after it has cooled. Once you've made a bend to the desired angle, you can remove the auger."}]}, "group0123_ex000092_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000092_eng_latn_0_v1_0", "pred": " use a hammer."}]}, "group0123_ex000037_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000037_eng_latn_0_v1_0", "pred": " Place some sausage links in a pot and cover with an inch of water. Simmer for ten minutes or until firm. Allow to cool before serving."}]}, "group0123_ex000044_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000044_eng_latn_0_v1_0", "pred": " Wash jeans on hot cycle using laundry soap and oxyclean, repeat if stain is still there."}]}, "group0123_ex000083_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000083_eng_latn_0_v1_0", "pred": " open one end of the can. Flip the can over and open the bottom. Push the paste out like a Push-Up Pop."}]}, "group0123_ex000008_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000008_eng_latn_0_v1_0", "pred": " Use a pot that holds at least eight quarts."}]}, "group0123_ex000032_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000032_eng_latn_0_v1_0", "pred": " Place the clay sticks onto a baking sheet and bake at 350\u00b0F for twenty minutes."}]}, "group0123_ex000096_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000096_eng_latn_0_v1_0", "pred": " don't try to cut all the way through in one go."}]}, "group0123_ex000084_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000084_eng_latn_0_v1_0", "pred": " Place a wet towel on the counter first."}]}, "group0123_ex000038_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000038_eng_latn_0_v1_0", "pred": " Bolt the bike racks above the cars and other furniture."}]}, "group0123_ex000005_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000005_eng_latn_0_v1_0", "pred": " insert a toothpick into the middle of the bread. If it comes out clean it is done."}]}, "group0123_ex000058_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000058_eng_latn_0_v1_0", "pred": " Lift the page up and push it to the right side."}]}, "group0123_ex000001_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000001_eng_latn_0_v1_0", "pred": " preheat oven to 450 degrees Fahrenheit. Toss the broccoli florets with the olive pits, garlic, salt, and pepper. Spread them out on a baking sheet and then roast, without stirring, until the edges are crispy and the stems are crisp tender."}]}, "group0123_ex000047_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000047_eng_latn_0_v1_0", "pred": " use a solder pen to melt it free and remove by hand."}]}, "group0123_ex000069_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000069_eng_latn_0_v1_0", "pred": " mix together two tablespoons each of red clay, cornstarch, and tapioca pudding and mix well. You can mix in a bit of cocoa powder if you have dark hair."}]}, "group0123_ex000023_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000023_eng_latn_0_v1_0", "pred": " It is best if a skateboard has two wheels to provide balance and traction."}]}, "group0123_ex000098_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000098_eng_latn_0_v1_0", "pred": " spray WD-40 on the the hinges."}]}, "group0123_ex000011_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000011_eng_latn_0_v1_0", "pred": " remove any nails and fill nail holes with spackling."}]}, "group0123_ex000009_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000009_eng_latn_0_v1_0", "pred": " put a piece of plastic wrap under the food on the lower rack."}]}, "group0123_ex000055_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000055_eng_latn_0_v1_0", "pred": " place the cake on the plate then line it with plastic wrap."}]}, "group0123_ex000027_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000027_eng_latn_0_v1_0", "pred": " take a sip of soda."}]}, "group0123_ex000051_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000051_eng_latn_0_v1_0", "pred": " dry your hair with a blow dryer instead of a towel."}]}, "group0123_ex000004_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000004_eng_latn_0_v1_0", "pred": " Clean and gut fish. Sprinkle with salt and pepper. Add about an inch of oil in pan, turn stove on low. Once oil is hot, gently put fish in. Fry each side for 5 minutes until crispy yellow brown."}]}, "group0123_ex000080_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000080_eng_latn_0_v1_0", "pred": " Heat it up on the stove top on high temperature."}]}, "group0123_ex000054_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000054_eng_latn_0_v1_0", "pred": " wait for the edges to brown and the top to bubble. Slide the spatula under the pancake so it's centered. Quickly flip your wrist 90 degrees to one side so the pancake flips over evenly."}]}, "group0123_ex000016_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000016_eng_latn_0_v1_0", "pred": " use rubbing alcohol."}]}, "group0123_ex000066_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000066_eng_latn_0_v1_0", "pred": " boil the beans for a day and then rinse them after cooking."}]}, "group0123_ex000079_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000079_eng_latn_0_v1_0", "pred": " wear dark clothing."}]}, "group0123_ex000074_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000074_eng_latn_0_v1_0", "pred": " wrap the chicken in a damp paper towel and heat in the microwave."}]}, "group0123_ex000090_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000090_eng_latn_0_v1_0", "pred": " Use a bucket with a solid lid."}]}, "group0123_ex000099_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000099_eng_latn_0_v1_0", "pred": " rub a pencil tip on the teeth of the zipper."}]}, "group0123_ex000060_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000060_eng_latn_0_v1_0", "pred": " rub a dryer sheet on your hair."}]}, "group0123_ex000085_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000085_eng_latn_0_v1_0", "pred": " by placing a white sock over the head."}]}, "group0123_ex000043_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000043_eng_latn_0_v1_0", "pred": " mashing up egg whites into a paste."}]}, "group0123_ex000050_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000050_eng_latn_0_v1_0", "pred": " In a large bowl, combine 4 teaspoons half and half light cream, 1 1/2 cups sugar, and 1 tablespoon vanilla. Stir until sugar dissolved. Stir in 2 teaspoons whipping cream. Add 4 cups diced fresh pitted cherries to mixture. Freeze in 4 or 5 quart ice cream freezer according to manufacturers directions. Top with whipped cream and a fresh cherry on top."}]}, "group0123_ex000077_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000077_eng_latn_0_v1_0", "pred": " spray the 9x9 glass pan with cooking spray."}]}, "group0123_ex000078_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000078_eng_latn_0_v1_0", "pred": " put it in the dishwasher."}]}, "group0123_ex000097_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000097_eng_latn_0_v1_0", "pred": " Rinse out blender, and add 1 1/2 cups of hot water and about 1 tablespoon of dish soap. Seal lid then turn blender on high for 1 1/2 minutes."}]}, "group0123_ex000067_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000067_eng_latn_0_v1_0", "pred": " Bolt the bench vise to a wooden work bench."}]}, "group0123_ex000035_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000035_eng_latn_0_v1_0", "pred": " You should check on the BBQ every 45 minutes to make sure it remains between 225-350\u00b0 C."}]}, "group0123_ex000048_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000048_eng_latn_0_v1_0", "pred": " Turn the knob with 'H' on it."}]}, "group0123_ex000040_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000040_eng_latn_0_v1_0", "pred": " sprinkle salt on carpet every nine days and vacuum every third day."}]}, "group0123_ex000003_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000003_eng_latn_0_v1_0", "pred": " put the jar of honey in a microwave until it becomes runny."}]}, "group0123_ex000101_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000101_eng_latn_0_v1_0", "pred": " can be used to make a ghost costume."}]}, "group0123_ex000082_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000082_eng_latn_0_v1_0", "pred": " Cut into it right away."}]}, "group0123_ex000017_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000017_eng_latn_0_v1_0", "pred": " Mix together 1 1/2 cups cornstarch, 1 cup white school glue, 1 tablespoon white vinegar, 1 teaspoon lotion, and 1 tablespoon baby oil. Mix and knead until the desired consistancy."}]}, "group0123_ex000015_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000015_eng_latn_0_v1_0", "pred": " Add 35 drops of blue food coloring and 20 drops of red food coloring to icing. Mix thoroughly before spreading on cake or cupcakes."}]}, "group0123_ex000063_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000063_eng_latn_0_v1_0", "pred": " use a ball-peen hammer."}]}, "group0123_ex000026_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000026_eng_latn_0_v1_0", "pred": " take it out of the oven about 10-15 minutes before you want to roll it out."}]}, "group0123_ex000103_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000103_eng_latn_0_v1_0", "pred": " Use a disposable knife to cut off the pills."}]}, "group0123_ex000049_eng_latn_0_v1": {"predictions": [{"id": "group0123_ex000049_eng_latn_0_v1_0", "pred": " touch the meat and see if it is soft to the touch."}]}}
|
babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/global_piqa_parallel/global_piqa_parallel/best_temperature_report.txt
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
TEMPERATURE: 1.00
|
| 2 |
+
|
| 3 |
+
### UID ACCURACY
|
| 4 |
+
parallel_ex000000_eng_latn: 0.00
|
| 5 |
+
parallel_ex000001_eng_latn: 0.00
|
| 6 |
+
parallel_ex000002_eng_latn: 0.00
|
| 7 |
+
parallel_ex000003_eng_latn: 0.00
|
| 8 |
+
parallel_ex000004_eng_latn: 100.00
|
| 9 |
+
parallel_ex000005_eng_latn: 100.00
|
| 10 |
+
parallel_ex000008_eng_latn: 0.00
|
| 11 |
+
parallel_ex000009_eng_latn: 0.00
|
| 12 |
+
parallel_ex000010_eng_latn: 0.00
|
| 13 |
+
parallel_ex000011_eng_latn: 0.00
|
| 14 |
+
parallel_ex000013_eng_latn: 0.00
|
| 15 |
+
parallel_ex000014_eng_latn: 0.00
|
| 16 |
+
parallel_ex000015_eng_latn: 0.00
|
| 17 |
+
parallel_ex000016_eng_latn: 100.00
|
| 18 |
+
parallel_ex000017_eng_latn: 0.00
|
| 19 |
+
parallel_ex000018_eng_latn: 100.00
|
| 20 |
+
parallel_ex000020_eng_latn: 0.00
|
| 21 |
+
parallel_ex000021_eng_latn: 0.00
|
| 22 |
+
parallel_ex000022_eng_latn: 0.00
|
| 23 |
+
parallel_ex000023_eng_latn: 0.00
|
| 24 |
+
parallel_ex000024_eng_latn: 0.00
|
| 25 |
+
parallel_ex000025_eng_latn: 100.00
|
| 26 |
+
parallel_ex000026_eng_latn: 0.00
|
| 27 |
+
parallel_ex000027_eng_latn: 100.00
|
| 28 |
+
parallel_ex000028_eng_latn: 0.00
|
| 29 |
+
parallel_ex000029_eng_latn: 0.00
|
| 30 |
+
parallel_ex000030_eng_latn: 0.00
|
| 31 |
+
parallel_ex000031_eng_latn: 0.00
|
| 32 |
+
parallel_ex000032_eng_latn: 0.00
|
| 33 |
+
parallel_ex000033_eng_latn: 0.00
|
| 34 |
+
parallel_ex000034_eng_latn: 0.00
|
| 35 |
+
parallel_ex000035_eng_latn: 0.00
|
| 36 |
+
parallel_ex000036_eng_latn: 0.00
|
| 37 |
+
parallel_ex000037_eng_latn: 0.00
|
| 38 |
+
parallel_ex000038_eng_latn: 100.00
|
| 39 |
+
parallel_ex000039_eng_latn: 0.00
|
| 40 |
+
parallel_ex000040_eng_latn: 0.00
|
| 41 |
+
parallel_ex000041_eng_latn: 0.00
|
| 42 |
+
parallel_ex000042_eng_latn: 0.00
|
| 43 |
+
parallel_ex000043_eng_latn: 0.00
|
| 44 |
+
parallel_ex000044_eng_latn: 0.00
|
| 45 |
+
parallel_ex000045_eng_latn: 0.00
|
| 46 |
+
parallel_ex000046_eng_latn: 100.00
|
| 47 |
+
parallel_ex000047_eng_latn: 0.00
|
| 48 |
+
parallel_ex000048_eng_latn: 0.00
|
| 49 |
+
parallel_ex000049_eng_latn: 0.00
|
| 50 |
+
parallel_ex000050_eng_latn: 0.00
|
| 51 |
+
parallel_ex000051_eng_latn: 100.00
|
| 52 |
+
parallel_ex000053_eng_latn: 0.00
|
| 53 |
+
parallel_ex000054_eng_latn: 0.00
|
| 54 |
+
parallel_ex000055_eng_latn: 0.00
|
| 55 |
+
parallel_ex000056_eng_latn: 0.00
|
| 56 |
+
parallel_ex000057_eng_latn: 0.00
|
| 57 |
+
parallel_ex000058_eng_latn: 100.00
|
| 58 |
+
parallel_ex000059_eng_latn: 0.00
|
| 59 |
+
parallel_ex000061_eng_latn: 0.00
|
| 60 |
+
parallel_ex000062_eng_latn: 0.00
|
| 61 |
+
parallel_ex000063_eng_latn: 0.00
|
| 62 |
+
parallel_ex000064_eng_latn: 0.00
|
| 63 |
+
parallel_ex000065_eng_latn: 0.00
|
| 64 |
+
parallel_ex000066_eng_latn: 0.00
|
| 65 |
+
parallel_ex000067_eng_latn: 0.00
|
| 66 |
+
parallel_ex000068_eng_latn: 100.00
|
| 67 |
+
parallel_ex000069_eng_latn: 0.00
|
| 68 |
+
parallel_ex000070_eng_latn: 0.00
|
| 69 |
+
parallel_ex000071_eng_latn: 0.00
|
| 70 |
+
parallel_ex000072_eng_latn: 100.00
|
| 71 |
+
parallel_ex000073_eng_latn: 0.00
|
| 72 |
+
parallel_ex000074_eng_latn: 100.00
|
| 73 |
+
parallel_ex000075_eng_latn: 0.00
|
| 74 |
+
parallel_ex000076_eng_latn: 100.00
|
| 75 |
+
parallel_ex000077_eng_latn: 100.00
|
| 76 |
+
parallel_ex000078_eng_latn: 0.00
|
| 77 |
+
parallel_ex000079_eng_latn: 0.00
|
| 78 |
+
parallel_ex000080_eng_latn: 0.00
|
| 79 |
+
parallel_ex000081_eng_latn: 100.00
|
| 80 |
+
parallel_ex000082_eng_latn: 0.00
|
| 81 |
+
parallel_ex000083_eng_latn: 0.00
|
| 82 |
+
parallel_ex000084_eng_latn: 0.00
|
| 83 |
+
parallel_ex000085_eng_latn: 0.00
|
| 84 |
+
parallel_ex000086_eng_latn: 100.00
|
| 85 |
+
parallel_ex000087_eng_latn: 0.00
|
| 86 |
+
parallel_ex000088_eng_latn: 0.00
|
| 87 |
+
parallel_ex000089_eng_latn: 0.00
|
| 88 |
+
parallel_ex000090_eng_latn: 0.00
|
| 89 |
+
parallel_ex000091_eng_latn: 0.00
|
| 90 |
+
parallel_ex000092_eng_latn: 0.00
|
| 91 |
+
parallel_ex000093_eng_latn: 0.00
|
| 92 |
+
parallel_ex000094_eng_latn: 0.00
|
| 93 |
+
parallel_ex000095_eng_latn: 0.00
|
| 94 |
+
parallel_ex000096_eng_latn: 0.00
|
| 95 |
+
parallel_ex000097_eng_latn: 0.00
|
| 96 |
+
parallel_ex000098_eng_latn: 100.00
|
| 97 |
+
parallel_ex000099_eng_latn: 0.00
|
| 98 |
+
parallel_ex000100_eng_latn: 0.00
|
| 99 |
+
parallel_ex000101_eng_latn: 0.00
|
| 100 |
+
parallel_ex000102_eng_latn: 0.00
|
| 101 |
+
parallel_ex000103_eng_latn: 0.00
|
| 102 |
+
parallel_ex000104_eng_latn: 0.00
|
| 103 |
+
parallel_ex000105_eng_latn: 100.00
|
| 104 |
+
parallel_ex000106_eng_latn: 100.00
|
| 105 |
+
parallel_ex000107_eng_latn: 0.00
|
| 106 |
+
parallel_ex000108_eng_latn: 0.00
|
| 107 |
+
|
| 108 |
+
### AVERAGE ACCURACY
|
| 109 |
+
19.42
|
| 110 |
+
|
babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/global_piqa_parallel/global_piqa_parallel/predictions.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"parallel_ex000000_eng_latn": {"predictions": [{"id": "parallel_ex000000_eng_latn_0", "pred": " The amount of air in the bag increases"}]}, "parallel_ex000001_eng_latn": {"predictions": [{"id": "parallel_ex000001_eng_latn_0", "pred": " The water goes into the cup"}]}, "parallel_ex000002_eng_latn": {"predictions": [{"id": "parallel_ex000002_eng_latn_0", "pred": " The ball sticks to the window"}]}, "parallel_ex000003_eng_latn": {"predictions": [{"id": "parallel_ex000003_eng_latn_0", "pred": " The ball sticks to the window"}]}, "parallel_ex000004_eng_latn": {"predictions": [{"id": "parallel_ex000004_eng_latn_0", "pred": " You see the light from the lightbulb through the glass"}]}, "parallel_ex000005_eng_latn": {"predictions": [{"id": "parallel_ex000005_eng_latn_0", "pred": " The center of the fabric gets closer to the ground"}]}, "parallel_ex000008_eng_latn": {"predictions": [{"id": "parallel_ex000008_eng_latn_0", "pred": " October"}]}, "parallel_ex000009_eng_latn": {"predictions": [{"id": "parallel_ex000009_eng_latn_0", "pred": " Friday"}]}, "parallel_ex000010_eng_latn": {"predictions": [{"id": "parallel_ex000010_eng_latn_0", "pred": " 1940"}]}, "parallel_ex000011_eng_latn": {"predictions": [{"id": "parallel_ex000011_eng_latn_0", "pred": " 1985"}]}, "parallel_ex000013_eng_latn": {"predictions": [{"id": "parallel_ex000013_eng_latn_0", "pred": " 9:30 AM"}]}, "parallel_ex000014_eng_latn": {"predictions": [{"id": "parallel_ex000014_eng_latn_0", "pred": " North"}]}, "parallel_ex000015_eng_latn": {"predictions": [{"id": "parallel_ex000015_eng_latn_0", "pred": " Late morning"}]}, "parallel_ex000016_eng_latn": {"predictions": [{"id": "parallel_ex000016_eng_latn_0", "pred": " You pull it"}]}, "parallel_ex000017_eng_latn": {"predictions": [{"id": "parallel_ex000017_eng_latn_0", "pred": " A stick"}]}, "parallel_ex000018_eng_latn": {"predictions": [{"id": "parallel_ex000018_eng_latn_0", "pred": " Watching a movie"}]}, "parallel_ex000020_eng_latn": {"predictions": [{"id": "parallel_ex000020_eng_latn_0", "pred": " A plate"}]}, "parallel_ex000021_eng_latn": {"predictions": [{"id": "parallel_ex000021_eng_latn_0", "pred": " Lemons"}]}, "parallel_ex000022_eng_latn": {"predictions": [{"id": "parallel_ex000022_eng_latn_0", "pred": " Marbles"}]}, "parallel_ex000023_eng_latn": {"predictions": [{"id": "parallel_ex000023_eng_latn_0", "pred": " A wooden box"}]}, "parallel_ex000024_eng_latn": {"predictions": [{"id": "parallel_ex000024_eng_latn_0", "pred": " A small stone"}]}, "parallel_ex000025_eng_latn": {"predictions": [{"id": "parallel_ex000025_eng_latn_0", "pred": " A piece of rope"}]}, "parallel_ex000026_eng_latn": {"predictions": [{"id": "parallel_ex000026_eng_latn_0", "pred": " Under the table"}]}, "parallel_ex000027_eng_latn": {"predictions": [{"id": "parallel_ex000027_eng_latn_0", "pred": " Inside an empty suitcase"}]}, "parallel_ex000028_eng_latn": {"predictions": [{"id": "parallel_ex000028_eng_latn_0", "pred": " Your fingers"}]}, "parallel_ex000029_eng_latn": {"predictions": [{"id": "parallel_ex000029_eng_latn_0", "pred": " Ten pairs of glasses"}]}, "parallel_ex000030_eng_latn": {"predictions": [{"id": "parallel_ex000030_eng_latn_0", "pred": " It depends on how ripe the spinach is"}]}, "parallel_ex000031_eng_latn": {"predictions": [{"id": "parallel_ex000031_eng_latn_0", "pred": " It depends on the color of the water"}]}, "parallel_ex000032_eng_latn": {"predictions": [{"id": "parallel_ex000032_eng_latn_0", "pred": " You"}]}, "parallel_ex000033_eng_latn": {"predictions": [{"id": "parallel_ex000033_eng_latn_0", "pred": " Keep the comb still"}]}, "parallel_ex000034_eng_latn": {"predictions": [{"id": "parallel_ex000034_eng_latn_0", "pred": " Your head"}]}, "parallel_ex000035_eng_latn": {"predictions": [{"id": "parallel_ex000035_eng_latn_0", "pred": " It will be crushed"}]}, "parallel_ex000036_eng_latn": {"predictions": [{"id": "parallel_ex000036_eng_latn_0", "pred": " It will break"}]}, "parallel_ex000037_eng_latn": {"predictions": [{"id": "parallel_ex000037_eng_latn_0", "pred": " Green"}]}, "parallel_ex000038_eng_latn": {"predictions": [{"id": "parallel_ex000038_eng_latn_0", "pred": " Metal"}]}, "parallel_ex000039_eng_latn": {"predictions": [{"id": "parallel_ex000039_eng_latn_0", "pred": " Chew without swallowing"}]}, "parallel_ex000040_eng_latn": {"predictions": [{"id": "parallel_ex000040_eng_latn_0", "pred": " Large and thin"}]}, "parallel_ex000041_eng_latn": {"predictions": [{"id": "parallel_ex000041_eng_latn_0", "pred": " The man and the woman are on the same floor"}]}, "parallel_ex000042_eng_latn": {"predictions": [{"id": "parallel_ex000042_eng_latn_0", "pred": " The man and the woman are on the same floor"}]}, "parallel_ex000043_eng_latn": {"predictions": [{"id": "parallel_ex000043_eng_latn_0", "pred": " The paper is on top of the book"}]}, "parallel_ex000044_eng_latn": {"predictions": [{"id": "parallel_ex000044_eng_latn_0", "pred": " A half cup"}]}, "parallel_ex000045_eng_latn": {"predictions": [{"id": "parallel_ex000045_eng_latn_0", "pred": " Your friend is closer to you"}]}, "parallel_ex000046_eng_latn": {"predictions": [{"id": "parallel_ex000046_eng_latn_0", "pred": " The rock is no longer visible"}]}, "parallel_ex000047_eng_latn": {"predictions": [{"id": "parallel_ex000047_eng_latn_0", "pred": " The tunnel is no longer visible from the car"}]}, "parallel_ex000048_eng_latn": {"predictions": [{"id": "parallel_ex000048_eng_latn_0", "pred": " From the side of the shelf"}]}, "parallel_ex000049_eng_latn": {"predictions": [{"id": "parallel_ex000049_eng_latn_0", "pred": " The can is not visible in front of the flour"}]}, "parallel_ex000050_eng_latn": {"predictions": [{"id": "parallel_ex000050_eng_latn_0", "pred": " The coin is dented"}]}, "parallel_ex000051_eng_latn": {"predictions": [{"id": "parallel_ex000051_eng_latn_0", "pred": " The cup is crushed"}]}, "parallel_ex000053_eng_latn": {"predictions": [{"id": "parallel_ex000053_eng_latn_0", "pred": " The library doesn't have any books"}]}, "parallel_ex000054_eng_latn": {"predictions": [{"id": "parallel_ex000054_eng_latn_0", "pred": " There are no students in classroom B"}]}, "parallel_ex000055_eng_latn": {"predictions": [{"id": "parallel_ex000055_eng_latn_0", "pred": " The theatre has more chairs than the school"}]}, "parallel_ex000056_eng_latn": {"predictions": [{"id": "parallel_ex000056_eng_latn_0", "pred": " All of the cups are in the cupboard"}]}, "parallel_ex000057_eng_latn": {"predictions": [{"id": "parallel_ex000057_eng_latn_0", "pred": " 16cm x 20cm"}]}, "parallel_ex000058_eng_latn": {"predictions": [{"id": "parallel_ex000058_eng_latn_0", "pred": " 1cm"}]}, "parallel_ex000059_eng_latn": {"predictions": [{"id": "parallel_ex000059_eng_latn_0", "pred": " A knife"}]}, "parallel_ex000061_eng_latn": {"predictions": [{"id": "parallel_ex000061_eng_latn_0", "pred": " They should not twist the towel"}]}, "parallel_ex000062_eng_latn": {"predictions": [{"id": "parallel_ex000062_eng_latn_0", "pred": " Your left shoulder"}]}, "parallel_ex000063_eng_latn": {"predictions": [{"id": "parallel_ex000063_eng_latn_0", "pred": " A foam cup"}]}, "parallel_ex000064_eng_latn": {"predictions": [{"id": "parallel_ex000064_eng_latn_0", "pred": " The side of the house that faces the sun"}]}, "parallel_ex000065_eng_latn": {"predictions": [{"id": "parallel_ex000065_eng_latn_0", "pred": " Without oven mitts, grab it from both sides and carefully lift it out of the oven"}]}, "parallel_ex000066_eng_latn": {"predictions": [{"id": "parallel_ex000066_eng_latn_0", "pred": " A pocket knife"}]}, "parallel_ex000067_eng_latn": {"predictions": [{"id": "parallel_ex000067_eng_latn_0", "pred": " Scissors"}]}, "parallel_ex000068_eng_latn": {"predictions": [{"id": "parallel_ex000068_eng_latn_0", "pred": " Pants, socks, then shoes"}]}, "parallel_ex000069_eng_latn": {"predictions": [{"id": "parallel_ex000069_eng_latn_0", "pred": " Heavy wool shirts"}]}, "parallel_ex000070_eng_latn": {"predictions": [{"id": "parallel_ex000070_eng_latn_0", "pred": " Drink all your water as soon as you start the hike"}]}, "parallel_ex000071_eng_latn": {"predictions": [{"id": "parallel_ex000071_eng_latn_0", "pred": " The wick should be as long as possible"}]}, "parallel_ex000072_eng_latn": {"predictions": [{"id": "parallel_ex000072_eng_latn_0", "pred": " They will make the same amount of water overflow"}]}, "parallel_ex000073_eng_latn": {"predictions": [{"id": "parallel_ex000073_eng_latn_0", "pred": " A water-soaked cotton ball"}]}, "parallel_ex000074_eng_latn": {"predictions": [{"id": "parallel_ex000074_eng_latn_0", "pred": " Wrap the cup with a plastic bag"}]}, "parallel_ex000075_eng_latn": {"predictions": [{"id": "parallel_ex000075_eng_latn_0", "pred": " 10 liters"}]}, "parallel_ex000076_eng_latn": {"predictions": [{"id": "parallel_ex000076_eng_latn_0", "pred": " Do not cover it"}]}, "parallel_ex000077_eng_latn": {"predictions": [{"id": "parallel_ex000077_eng_latn_0", "pred": " A stick"}]}, "parallel_ex000078_eng_latn": {"predictions": [{"id": "parallel_ex000078_eng_latn_0", "pred": " In the sun"}]}, "parallel_ex000079_eng_latn": {"predictions": [{"id": "parallel_ex000079_eng_latn_0", "pred": " The car has lost a tire"}]}, "parallel_ex000080_eng_latn": {"predictions": [{"id": "parallel_ex000080_eng_latn_0", "pred": " They will freeze at the same rate"}]}, "parallel_ex000081_eng_latn": {"predictions": [{"id": "parallel_ex000081_eng_latn_0", "pred": " Flatten out the towel and do not fold it"}]}, "parallel_ex000082_eng_latn": {"predictions": [{"id": "parallel_ex000082_eng_latn_0", "pred": " A high rattling sound"}]}, "parallel_ex000083_eng_latn": {"predictions": [{"id": "parallel_ex000083_eng_latn_0", "pred": " More than 20cm"}]}, "parallel_ex000084_eng_latn": {"predictions": [{"id": "parallel_ex000084_eng_latn_0", "pred": " Yes"}]}, "parallel_ex000085_eng_latn": {"predictions": [{"id": "parallel_ex000085_eng_latn_0", "pred": " Make animal shapes with your hand, then place your hand on the wall"}]}, "parallel_ex000086_eng_latn": {"predictions": [{"id": "parallel_ex000086_eng_latn_0", "pred": " The glass would break"}]}, "parallel_ex000087_eng_latn": {"predictions": [{"id": "parallel_ex000087_eng_latn_0", "pred": " Sugar and water, flour and salt"}]}, "parallel_ex000088_eng_latn": {"predictions": [{"id": "parallel_ex000088_eng_latn_0", "pred": " Two glasses of 0.2L and one glass of 0.5L"}]}, "parallel_ex000089_eng_latn": {"predictions": [{"id": "parallel_ex000089_eng_latn_0", "pred": " Put the egg in the cup, then wrap the cup with the paper"}]}, "parallel_ex000090_eng_latn": {"predictions": [{"id": "parallel_ex000090_eng_latn_0", "pred": " The water will not move"}]}, "parallel_ex000091_eng_latn": {"predictions": [{"id": "parallel_ex000091_eng_latn_0", "pred": " Blue and white"}]}, "parallel_ex000092_eng_latn": {"predictions": [{"id": "parallel_ex000092_eng_latn_0", "pred": " One drop of yellow and one drop of blue"}]}, "parallel_ex000093_eng_latn": {"predictions": [{"id": "parallel_ex000093_eng_latn_0", "pred": " Fill a bag with water"}]}, "parallel_ex000094_eng_latn": {"predictions": [{"id": "parallel_ex000094_eng_latn_0", "pred": " Folding the laundry"}]}, "parallel_ex000095_eng_latn": {"predictions": [{"id": "parallel_ex000095_eng_latn_0", "pred": " In front of you"}]}, "parallel_ex000096_eng_latn": {"predictions": [{"id": "parallel_ex000096_eng_latn_0", "pred": " You and your friend are walking towards each other"}]}, "parallel_ex000097_eng_latn": {"predictions": [{"id": "parallel_ex000097_eng_latn_0", "pred": " The right car would swerve right, and the left car would not swerve"}]}, "parallel_ex000098_eng_latn": {"predictions": [{"id": "parallel_ex000098_eng_latn_0", "pred": " 240km"}]}, "parallel_ex000099_eng_latn": {"predictions": [{"id": "parallel_ex000099_eng_latn_0", "pred": " 9:30 AM"}]}, "parallel_ex000100_eng_latn": {"predictions": [{"id": "parallel_ex000100_eng_latn_0", "pred": " Friday"}]}, "parallel_ex000101_eng_latn": {"predictions": [{"id": "parallel_ex000101_eng_latn_0", "pred": " 9:00 AM"}]}, "parallel_ex000102_eng_latn": {"predictions": [{"id": "parallel_ex000102_eng_latn_0", "pred": " Cooking oil"}]}, "parallel_ex000103_eng_latn": {"predictions": [{"id": "parallel_ex000103_eng_latn_0", "pred": " Leave the garlic in the sun"}]}, "parallel_ex000104_eng_latn": {"predictions": [{"id": "parallel_ex000104_eng_latn_0", "pred": " Small rocks"}]}, "parallel_ex000105_eng_latn": {"predictions": [{"id": "parallel_ex000105_eng_latn_0", "pred": " The meat is soft"}]}, "parallel_ex000106_eng_latn": {"predictions": [{"id": "parallel_ex000106_eng_latn_0", "pred": " A spoon"}]}, "parallel_ex000107_eng_latn": {"predictions": [{"id": "parallel_ex000107_eng_latn_0", "pred": " A heavy coat"}]}, "parallel_ex000108_eng_latn": {"predictions": [{"id": "parallel_ex000108_eng_latn_0", "pred": " A drinking cup"}]}}
|
babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/reading/correlations.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
RTfirstfix 0.5693
|
| 2 |
+
RTfirstpass 0.5957
|
| 3 |
+
RTgopast 0.4633
|
| 4 |
+
RTrightbound 0.5995
|
| 5 |
+
self_paced_reading_time 0.2430
|
| 6 |
+
ELAN 0.1066
|
| 7 |
+
LAN -0.0515
|
| 8 |
+
N400 -0.1010
|
| 9 |
+
P600 0.2130
|
| 10 |
+
EPNP 0.0968
|
| 11 |
+
PNP 0.2318
|
babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/reading/prediction.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/reading/predictions.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/reading/predictive_power.jsonl
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"Predicted variable": "RTfirstfix", "Coefficient": 1.3490699037631342, "Number of standard deviations": 4.195750408501817, "P-value": 2.861052285519171e-05, "R2": 0.6477540607490784, "Change in R2 from baseline": 0.003673608269121109, "AIC": 16389.11553716685, "Change in AIC from baseline": -15.596156912710285}
|
| 2 |
+
{"Predicted variable": "RTfirstpass", "Coefficient": 2.4611804773850223, "Number of standard deviations": 5.501074574866903, "P-value": 4.3542625538347874e-08, "R2": 0.650588875740541, "Change in R2 from baseline": 0.0062641096355765535, "AIC": 17509.67787915891, "Change in AIC from baseline": -28.135909857664956}
|
| 3 |
+
{"Predicted variable": "RTgopast", "Coefficient": 12.305662283836849, "Number of standard deviations": 9.33835253209628, "P-value": 2.9808239336644636e-20, "R2": 0.5617358589628113, "Change in R2 from baseline": 0.022641439006945485, "AIC": 21173.824833937466, "Change in AIC from baseline": -83.42992180746296}
|
| 4 |
+
{"Predicted variable": "RTrightbound", "Coefficient": 4.37062955152205, "Number of standard deviations": 7.810200157453945, "P-value": 9.953705102336702e-15, "R2": 0.6319697560710787, "Change in R2 from baseline": 0.013299502492940984, "AIC": 18268.735621979176, "Change in AIC from baseline": -58.206910505876294}
|
| 5 |
+
{"Predicted variable": "self_paced_reading_time", "Coefficient": 1.7185264038913184, "Number of standard deviations": 6.837599172601403, "P-value": 1.1217426053972441e-11, "R2": 0.09324041708333053, "Change in R2 from baseline": 0.02511464180981937, "AIC": 15553.622928507544, "Change in AIC from baseline": -44.33557993874456}
|
| 6 |
+
{"Predicted variable": "ELAN", "Coefficient": -0.026772643700025297, "Number of standard deviations": -2.3100926986452808, "P-value": 0.021003127045723314, "R2": 0.06658383148523661, "Change in R2 from baseline": 0.0029509489199446293, "AIC": 5117.480838655834, "Change in AIC from baseline": -3.353362136870601}
|
| 7 |
+
{"Predicted variable": "LAN", "Coefficient": -0.005468477371309654, "Number of standard deviations": -0.40851411308016833, "P-value": 0.6829480877546681, "R2": 0.12204982479130544, "Change in R2 from baseline": 8.679836753788805e-05, "AIC": 5606.390417937283, "Change in AIC from baseline": 1.8323335890399903}
|
| 8 |
+
{"Predicted variable": "N400", "Coefficient": -0.036789487463063514, "Number of standard deviations": -3.2812512939025096, "P-value": 0.0010545563469490558, "R2": 0.16739385815162078, "Change in R2 from baseline": 0.005310631313760639, "AIC": 5005.186440596301, "Change in AIC from baseline": -8.783283448517977}
|
| 9 |
+
{"Predicted variable": "P600", "Coefficient": 0.028012199337309463, "Number of standard deviations": 2.8988489951015777, "P-value": 0.0037937324510707417, "R2": 0.20731173471252906, "Change in R2 from baseline": 0.003946218904258503, "AIC": 4500.928498302437, "Change in AIC from baseline": -6.422205014940118}
|
| 10 |
+
{"Predicted variable": "EPNP", "Coefficient": 0.03623777396385926, "Number of standard deviations": 3.8573259094568546, "P-value": 0.00011894202763811692, "R2": 0.11988027893731101, "Change in R2 from baseline": 0.007757860732487076, "AIC": 4405.279303931775, "Change in AIC from baseline": -12.883977736527413}
|
| 11 |
+
{"Predicted variable": "PNP", "Coefficient": 0.059273137039820734, "Number of standard deviations": 5.775466017324852, "P-value": 9.1171100402867e-09, "R2": 0.1833428383886203, "Change in R2 from baseline": 0.01613769110490293, "AIC": 4705.163896945838, "Change in AIC from baseline": -31.187261221406516}
|
babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/reading/predictive_power_spillover.jsonl
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"Predicted variable": "RTfirstfix", "Coefficient": 1.6217153954117451, "Number of standard deviations": 4.841745887039933, "P-value": 1.4219074334063838e-06, "R2": 0.7071365504941127, "Change in R2 from baseline": 0.004641955620255711, "AIC": 14298.852913604147, "Change in AIC from baseline": -21.52599961041051}
|
| 2 |
+
{"Predicted variable": "RTfirstpass", "Coefficient": 2.8014033494515846, "Number of standard deviations": 6.149090535941275, "P-value": 1.0007288324286125e-09, "R2": 0.7067820953051911, "Change in R2 from baseline": 0.007496250431207052, "AIC": 15219.213651155645, "Change in AIC from baseline": -35.76521573182072}
|
| 3 |
+
{"Predicted variable": "RTgopast", "Coefficient": 13.4660921862215, "Number of standard deviations": 9.004183847817785, "P-value": 6.518290395675876e-19, "R2": 0.586109834183481, "Change in R2 from baseline": 0.02268849252097327, "AIC": 18775.711889611594, "Change in AIC from baseline": -77.83841244154974}
|
| 4 |
+
{"Predicted variable": "RTrightbound", "Coefficient": 4.711070672096454, "Number of standard deviations": 7.912726576139806, "P-value": 4.8969133890847694e-15, "R2": 0.6744689608176773, "Change in R2 from baseline": 0.013780867227876747, "AIC": 16019.952083886219, "Change in AIC from baseline": -60.02707226482562}
|
| 5 |
+
{"Predicted variable": "self_paced_reading_time", "Coefficient": 1.3743440893458203, "Number of standard deviations": 5.2317550238035, "P-value": 1.9201083048415453e-07, "R2": 0.14748370377557674, "Change in R2 from baseline": 0.015777177643346074, "AIC": 13571.85885415219, "Change in AIC from baseline": -25.432804659596513}
|
| 6 |
+
{"Predicted variable": "ELAN", "Coefficient": -0.022321853267920702, "Number of standard deviations": -1.7807583439800752, "P-value": 0.07515714344715244, "R2": 0.08033606732135334, "Change in R2 from baseline": 0.0019718367505782153, "AIC": 4468.823848831604, "Change in AIC from baseline": -1.2041159873515426}
|
| 7 |
+
{"Predicted variable": "LAN", "Coefficient": 0.007777264243250142, "Number of standard deviations": 0.5232766881289969, "P-value": 0.6008601084277922, "R2": 0.12876126826798107, "Change in R2 from baseline": 0.0001612990371812062, "AIC": 4978.429351711803, "Change in AIC from baseline": 1.723059803896831}
|
| 8 |
+
{"Predicted variable": "N400", "Coefficient": -0.0337406160300188, "Number of standard deviations": -2.717324927039772, "P-value": 0.0066579780541857125, "R2": 0.1865806933643791, "Change in R2 from baseline": 0.004060966881984318, "AIC": 4440.482323832297, "Change in AIC from baseline": -5.45014479765905}
|
| 9 |
+
{"Predicted variable": "P600", "Coefficient": 0.038339925099556346, "Number of standard deviations": 3.559916890335394, "P-value": 0.00038271288738986304, "R2": 0.22402150422229639, "Change in R2 from baseline": 0.006649074977216229, "AIC": 4014.721212766805, "Change in AIC from baseline": -10.76406748618183}
|
| 10 |
+
{"Predicted variable": "EPNP", "Coefficient": 0.05247397576153977, "Number of standard deviations": 5.0011567707408995, "P-value": 6.379359738302813e-07, "R2": 0.11019784528001031, "Change in R2 from baseline": 0.015047564590695006, "AIC": 3936.610631317539, "Change in AIC from baseline": -23.08752199507444}
|
| 11 |
+
{"Predicted variable": "PNP", "Coefficient": 0.0747711475299754, "Number of standard deviations": 6.496567833073147, "P-value": 1.119714283869015e-10, "R2": 0.19719952360571513, "Change in R2 from baseline": 0.022909067002225836, "AIC": 4213.400442108958, "Change in AIC from baseline": -40.09274101206756}
|
babylm_eval_repo/strict/results/xpertgpt_fresh/main/zero_shot/causal/reading/report.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
EYE TRACKING SCORE: 2.80
|
| 2 |
+
SELF-PACED READING SCORE: 1.82
|
babylm_eval_repo/strict/scripts/aoa_bos_curves.py
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""BOS-only AoA: extract P(word | <bos>) across checkpoints (single-BOS, fixed path)
|
| 3 |
+
and plot learning-curve small-multiples by category (averaging + k*ln(V) ceiling +
|
| 4 |
+
robust fit β the final scorer mechanism).
|
| 5 |
+
|
| 6 |
+
Run from babylm-eval-hidden/strict, or set BABYLM_STRICT to that path.
|
| 7 |
+
Point HF_HOME at scratch if disk is tight; PURGE_PER_CKPT keeps only one revision at a time.
|
| 8 |
+
"""
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
import json
|
| 12 |
+
import shutil
|
| 13 |
+
from collections import Counter
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
|
| 16 |
+
import numpy as np
|
| 17 |
+
|
| 18 |
+
# ---------------- config ----------------
|
| 19 |
+
MODEL = "BabyLM-community/BabyLM-2026-Baseline-GPT2-Strict"
|
| 20 |
+
BACKEND = "causal" # causal / mlm / mntp / enc_dec_mask / enc_dec_prefix
|
| 21 |
+
TRACK = "non-strict-small" # "strict-small" (19 ckpts) or "non-strict-small" (28)
|
| 22 |
+
MIN_CONTEXT = 20 # word set: same filter as the context run
|
| 23 |
+
PURGE_PER_CKPT = True # delete each HF revision after use (low disk)
|
| 24 |
+
EVAL_DATASET = "BabyLM-community/BabyLM-2026-Strict-Evals" # source of the AoA/CDI data
|
| 25 |
+
REPO_STRICT = Path(os.environ.get("BABYLM_STRICT", ".")).resolve()
|
| 26 |
+
OUT_DIR = REPO_STRICT / "results" / (Path(MODEL).stem + "_BOS")
|
| 27 |
+
# ----------------------------------------
|
| 28 |
+
|
| 29 |
+
sys.path.insert(0, str(REPO_STRICT))
|
| 30 |
+
from evaluation_pipeline.AoA_word.eval_util import StepConfig, load_eval # noqa: E402
|
| 31 |
+
from evaluation_pipeline.AoA_word.evaluation_functions import StepSurprisalExtractor # noqa: E402
|
| 32 |
+
from evaluation_pipeline.utils import AoAEvaluator # noqa: E402
|
| 33 |
+
|
| 34 |
+
WORD_PATH = REPO_STRICT / "evaluation_data/full_eval/aoa/cdi_childes.json"
|
| 35 |
+
CDI = REPO_STRICT / "evaluation_data/full_eval/aoa/cdi_human.csv"
|
| 36 |
+
SURPRISAL = OUT_DIR / "surprisal.json"
|
| 37 |
+
PNG = OUT_DIR / "aoa_bos_curves.png"
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def ensure_data():
|
| 41 |
+
# Fetch the AoA/CDI eval files from HF if they aren't present locally.
|
| 42 |
+
if WORD_PATH.exists() and CDI.exists():
|
| 43 |
+
return
|
| 44 |
+
from huggingface_hub import snapshot_download
|
| 45 |
+
print(f"[data] downloading AoA eval data from {EVAL_DATASET}", flush=True)
|
| 46 |
+
snapshot_download(
|
| 47 |
+
repo_id=EVAL_DATASET,
|
| 48 |
+
repo_type="dataset",
|
| 49 |
+
local_dir=str(REPO_STRICT),
|
| 50 |
+
allow_patterns=["evaluation_data/full_eval/aoa/*"],
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def sigmoid(x, a, b, c, d):
|
| 55 |
+
return a / (1 + np.exp(-b * (x - c))) + d
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def extract():
|
| 59 |
+
import torch
|
| 60 |
+
hub = Path(os.environ["HF_HOME"]) / "hub" if os.environ.get("HF_HOME") else None
|
| 61 |
+
|
| 62 |
+
def purge():
|
| 63 |
+
if PURGE_PER_CKPT and hub and hub.exists():
|
| 64 |
+
shutil.rmtree(hub, ignore_errors=True)
|
| 65 |
+
|
| 66 |
+
dev = "cuda" if torch.cuda.is_available() else "cpu"
|
| 67 |
+
words, _ = load_eval(WORD_PATH, MIN_CONTEXT, debug=False)
|
| 68 |
+
cfg = StepConfig(resume=False, track=TRACK, file_path=None, debug=False)
|
| 69 |
+
ex = StepSurprisalExtractor(config=cfg, model_name=MODEL, backend=BACKEND, device=dev)
|
| 70 |
+
print(f"[extract] {MODEL} words={len(words)} steps={len(cfg.steps)} device={dev}", flush=True)
|
| 71 |
+
rows = []
|
| 72 |
+
for step, wc in zip(cfg.steps, cfg.word_counts):
|
| 73 |
+
purge()
|
| 74 |
+
print(f"[extract] {step}", flush=True)
|
| 75 |
+
model = ex.load_model_for_step(step)
|
| 76 |
+
proc, tok = ex.load_tokenizer_for_step(step)
|
| 77 |
+
for w in words:
|
| 78 |
+
s = ex.compute_surprisal(model, proc, tok, "", w, use_bos_only=True)
|
| 79 |
+
rows.append({"step": step, "word_count": wc, "target_word": w,
|
| 80 |
+
"surprisal": s, "use_bos_only": True})
|
| 81 |
+
purge()
|
| 82 |
+
OUT_DIR.mkdir(parents=True, exist_ok=True)
|
| 83 |
+
json.dump({"results": rows}, SURPRISAL.open("w"))
|
| 84 |
+
print(f"[extract] DONE rows={len(rows)} -> {SURPRISAL}", flush=True)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def robust_fit(ls, neg):
|
| 88 |
+
from scipy.optimize import curve_fit
|
| 89 |
+
rng = neg.max() - neg.min()
|
| 90 |
+
p0 = [rng, 1.0, ls.mean(), neg.min()]
|
| 91 |
+
lb = [0.0, 0.0, ls.min() - 1, neg.min() - 2 * rng - 1]
|
| 92 |
+
ub = [10 * rng + 1, 100.0, ls.max() + 1, neg.max() + 1]
|
| 93 |
+
return curve_fit(sigmoid, ls, neg, p0=p0, bounds=(lb, ub), maxfev=20000)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def classify(us, means, k, V):
|
| 97 |
+
chance = k * np.log(V)
|
| 98 |
+
thr = chance - 0.5 * (chance - means.min())
|
| 99 |
+
neg = -means
|
| 100 |
+
ls = np.log10(us + 1)
|
| 101 |
+
try:
|
| 102 |
+
popt, _ = robust_fit(ls, neg)
|
| 103 |
+
except Exception:
|
| 104 |
+
return None, "fit-fail", None, thr
|
| 105 |
+
a, b, c, d = popt
|
| 106 |
+
nt = -thr
|
| 107 |
+
if b <= 1e-6 or a <= 1e-6:
|
| 108 |
+
return None, "bad-shape", popt, thr
|
| 109 |
+
if nt <= d:
|
| 110 |
+
return None, "already-acq", popt, thr
|
| 111 |
+
if nt >= a + d:
|
| 112 |
+
return None, "never-reached", popt, thr
|
| 113 |
+
la = c - np.log((a / (nt - d)) - 1) / b
|
| 114 |
+
if 10 ** la - 1 < us[0] or 10 ** la - 1 > us[-1]:
|
| 115 |
+
return None, "outside-range", popt, thr
|
| 116 |
+
return la, "ok", popt, thr
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def plot():
|
| 120 |
+
import matplotlib
|
| 121 |
+
matplotlib.use("Agg")
|
| 122 |
+
import matplotlib.pyplot as plt
|
| 123 |
+
from transformers import AutoTokenizer
|
| 124 |
+
|
| 125 |
+
tok = AutoTokenizer.from_pretrained(MODEL)
|
| 126 |
+
V = tok.vocab_size
|
| 127 |
+
pref = len(tok("The", add_special_tokens=False)["input_ids"])
|
| 128 |
+
|
| 129 |
+
def klen(w):
|
| 130 |
+
return max(1, len(tok("The " + w, add_special_tokens=False)["input_ids"]) - pref)
|
| 131 |
+
|
| 132 |
+
ev = AoAEvaluator(CDI)
|
| 133 |
+
wd = {}
|
| 134 |
+
for r in json.load(SURPRISAL.open())["results"]:
|
| 135 |
+
st = ev.extract_step_number(r["step"])
|
| 136 |
+
wd.setdefault(r["target_word"], {"steps": [], "s": []})
|
| 137 |
+
wd[r["target_word"]]["steps"].append(st)
|
| 138 |
+
wd[r["target_word"]]["s"].append(float(r["surprisal"]))
|
| 139 |
+
|
| 140 |
+
info = {}
|
| 141 |
+
for w, d in wd.items():
|
| 142 |
+
us = np.array(sorted(set(d["steps"])), float)
|
| 143 |
+
means = np.array([np.mean([x for s2, x in zip(d["steps"], d["s"]) if s2 == u]) for u in us])
|
| 144 |
+
aoa, cat, popt, thr = classify(us, means, klen(w), V)
|
| 145 |
+
info[w] = dict(us=us, means=means, cat=cat, popt=popt, aoa=aoa, thr=thr,
|
| 146 |
+
chance=klen(w) * np.log(V), minm=float(means.min()), k=klen(w))
|
| 147 |
+
print("category counts:", dict(Counter(i["cat"] for i in info.values()).most_common()))
|
| 148 |
+
|
| 149 |
+
C_MEAN, C_RAW, C_FIT, C_THR, C_ANCH, C_CROSS = "#111", "#CCC", "#0072B2", "#009E73", "#999", "#D55E00"
|
| 150 |
+
counts = Counter(i["cat"] for i in info.values())
|
| 151 |
+
cats = ["ok"] + [c for c, _ in counts.most_common() if c != "ok"][:4]
|
| 152 |
+
ncol = 3
|
| 153 |
+
fig, axes = plt.subplots(len(cats), ncol, figsize=(11, 2.6 * len(cats)),
|
| 154 |
+
constrained_layout=True, squeeze=False)
|
| 155 |
+
for ri, cat in enumerate(cats):
|
| 156 |
+
words = sorted([w for w, i in info.items() if i["cat"] == cat])[:ncol]
|
| 157 |
+
for ci in range(ncol):
|
| 158 |
+
ax = axes[ri][ci]
|
| 159 |
+
if ci >= len(words):
|
| 160 |
+
ax.axis("off")
|
| 161 |
+
continue
|
| 162 |
+
w = words[ci]; I = info[w]; d = wd[w]
|
| 163 |
+
st = np.array(d["steps"], float); s = np.array(d["s"], float)
|
| 164 |
+
ax.scatter(np.log10(st), s, s=5, c=C_RAW, alpha=0.35, zorder=1, linewidths=0)
|
| 165 |
+
ax.plot(np.log10(I["us"]), I["means"], "-o", color=C_MEAN, ms=3, lw=1.5, zorder=4)
|
| 166 |
+
if I["popt"] is not None:
|
| 167 |
+
xs = np.linspace(np.log10(I["us"].min() + 1), np.log10(I["us"].max() + 1), 200)
|
| 168 |
+
ax.plot(xs, -sigmoid(xs, *I["popt"]), color=C_FIT, lw=1.6, zorder=3)
|
| 169 |
+
ax.axhline(I["chance"], color=C_ANCH, ls=":", lw=1.0)
|
| 170 |
+
ax.axhline(I["minm"], color=C_ANCH, ls=":", lw=1.0)
|
| 171 |
+
ax.axhline(I["thr"], color=C_THR, lw=1.6)
|
| 172 |
+
if I["aoa"] is not None:
|
| 173 |
+
ax.axvline(I["aoa"], color=C_CROSS, ls="--", lw=1.2)
|
| 174 |
+
ax.set_title(f"{w} (k={I['k']})", fontsize=8.5)
|
| 175 |
+
ax.grid(True, color="#F0F0F0", lw=0.6); ax.set_axisbelow(True)
|
| 176 |
+
for sp in ("top", "right"):
|
| 177 |
+
ax.spines[sp].set_visible(False)
|
| 178 |
+
ax.tick_params(labelsize=7)
|
| 179 |
+
if ci == 0:
|
| 180 |
+
ax.set_ylabel(f"{cat}\nsurprisal (nats)", fontsize=8)
|
| 181 |
+
for ci in range(ncol):
|
| 182 |
+
axes[-1][ci].set_xlabel("log10(training words)", fontsize=8)
|
| 183 |
+
handles = [
|
| 184 |
+
plt.Line2D([], [], color=C_MEAN, marker="o", ms=3, lw=1.5, label="mean surprisal / ckpt"),
|
| 185 |
+
plt.Line2D([], [], color=C_FIT, lw=1.6, label="robust sigmoid fit"),
|
| 186 |
+
plt.Line2D([], [], color=C_THR, lw=1.6, label="threshold = midpoint"),
|
| 187 |
+
plt.Line2D([], [], color=C_ANCH, ls=":", lw=1.0, label="anchors: kΒ·ln(V) & min"),
|
| 188 |
+
plt.Line2D([], [], color=C_CROSS, ls="--", lw=1.2, label="crossing (AoA)"),
|
| 189 |
+
]
|
| 190 |
+
fig.legend(handles=handles, loc="upper center", ncol=5, fontsize=8,
|
| 191 |
+
bbox_to_anchor=(0.5, 1.02), frameon=False)
|
| 192 |
+
fig.suptitle(f"BOS-only AoA curves β {Path(MODEL).stem}", y=1.04, fontsize=11)
|
| 193 |
+
fig.savefig(PNG, dpi=130, bbox_inches="tight")
|
| 194 |
+
print(f"[plot] -> {PNG}")
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
if __name__ == "__main__":
|
| 198 |
+
ensure_data()
|
| 199 |
+
if not SURPRISAL.exists():
|
| 200 |
+
extract()
|
| 201 |
+
else:
|
| 202 |
+
print(f"[extract] {SURPRISAL} exists, skipping extraction")
|
| 203 |
+
plot()
|
babylm_eval_repo/strict/scripts/collate_preds.sh
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
MODEL_NAME=$1
|
| 4 |
+
BACKEND=$2 # "mlm", "causal", "mntp", "enc_dec_mask", "enc_dec_prefix
|
| 5 |
+
TRACK=$3 # "strict-small", "multimodal", "strict", "interaction"
|
| 6 |
+
|
| 7 |
+
python -m evaluation_pipeline.collate_preds --model_path_or_name=$MODEL_NAME --backend=$BACKEND --fast --track=$TRACK
|
babylm_eval_repo/strict/scripts/download_evals.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import snapshot_download
|
| 2 |
+
|
| 3 |
+
snapshot_download(
|
| 4 |
+
repo_id="BabyLM-community/BabyLM-2026-Strict-Evals",
|
| 5 |
+
repo_type="dataset",
|
| 6 |
+
local_dir=".",
|
| 7 |
+
)
|
babylm_eval_repo/strict/scripts/eval_aoa.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
MODEL_NAME=$1
|
| 3 |
+
BACKEND=$2
|
| 4 |
+
TRACK_NAME=$3
|
| 5 |
+
WORD_PATH=${4:-"evaluation_data/full_eval/aoa/cdi_childes.json"}
|
| 6 |
+
OUTPUT_DIR=${5:-"results"}
|
| 7 |
+
|
| 8 |
+
# please check evaluation_pipeline/AoA_word/README.md for more information on parameter setting
|
| 9 |
+
|
| 10 |
+
# Set default parameters
|
| 11 |
+
MIN_CONTEXT=${MIN_CONTEXT:-20}
|
| 12 |
+
echo "Running AoA evaluation for model: $MODEL_NAME"
|
| 13 |
+
echo "Word path: $WORD_PATH"
|
| 14 |
+
echo "Output directory: $OUTPUT_DIR"
|
| 15 |
+
# Create output directory if it doesn't exist
|
| 16 |
+
mkdir -p $OUTPUT_DIR
|
| 17 |
+
# Run the main evaluation
|
| 18 |
+
python -m evaluation_pipeline.AoA_word.run \
|
| 19 |
+
--model_name $MODEL_NAME \
|
| 20 |
+
--backend $BACKEND \
|
| 21 |
+
--track_name $TRACK_NAME \
|
| 22 |
+
--word_path $WORD_PATH \
|
| 23 |
+
--output_dir $OUTPUT_DIR
|
| 24 |
+
|
babylm_eval_repo/strict/scripts/eval_devbench.sh
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
MODEL_PATH=$1
|
| 4 |
+
MODEL_TYPE=$2
|
| 5 |
+
IMAGE_MODEL={$3:-$MODEL_PATH}
|
| 6 |
+
|
| 7 |
+
# Supported MODEL_TYPE values:
|
| 8 |
+
# git, flamingo, llava, flava, clip, blip, siglip, bridgetower, vilt, cvcl
|
| 9 |
+
|
| 10 |
+
# If you need a different MODEL_TYPE, implement it in the `evaluation_pipeline/devbench/model_classes` folder.
|
| 11 |
+
# (See other files in that folder for examples.)
|
| 12 |
+
# Then add a wrapper to `evaluation_pipeline/devbench/eval.py`.
|
| 13 |
+
# Be sure to submit a pull request so others can benefit from your implementation!
|
| 14 |
+
|
| 15 |
+
python -m evaluation_pipeline.devbench.eval --model $MODEL_PATH \
|
| 16 |
+
--model_type $MODEL_TYPE \
|
| 17 |
+
--image_model $IMAGE_MODEL
|
babylm_eval_repo/strict/scripts/eval_finetuning.sh
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
set -a
|
| 4 |
+
source ../.env
|
| 5 |
+
set +a
|
| 6 |
+
|
| 7 |
+
# Default values
|
| 8 |
+
MODEL_PATH=""
|
| 9 |
+
LR=3e-5
|
| 10 |
+
BSZ=32
|
| 11 |
+
BIG_BSZ=16
|
| 12 |
+
MAX_EPOCHS=10
|
| 13 |
+
WSC_EPOCHS=30
|
| 14 |
+
SEED=42
|
| 15 |
+
WANDB_FLAG=""
|
| 16 |
+
|
| 17 |
+
# Parse named arguments
|
| 18 |
+
while [[ $# -gt 0 ]]; do
|
| 19 |
+
case $1 in
|
| 20 |
+
--model_path)
|
| 21 |
+
MODEL_PATH="$2"
|
| 22 |
+
shift 2
|
| 23 |
+
;;
|
| 24 |
+
--lr)
|
| 25 |
+
LR="$2"
|
| 26 |
+
shift 2
|
| 27 |
+
;;
|
| 28 |
+
--bsz)
|
| 29 |
+
BSZ="$2"
|
| 30 |
+
shift 2
|
| 31 |
+
;;
|
| 32 |
+
--big_bsz)
|
| 33 |
+
BIG_BSZ="$2"
|
| 34 |
+
shift 2
|
| 35 |
+
;;
|
| 36 |
+
--max_epochs)
|
| 37 |
+
MAX_EPOCHS="$2"
|
| 38 |
+
shift 2
|
| 39 |
+
;;
|
| 40 |
+
--wsc_epochs)
|
| 41 |
+
WSC_EPOCHS="$2"
|
| 42 |
+
shift 2
|
| 43 |
+
;;
|
| 44 |
+
--seed)
|
| 45 |
+
SEED="$2"
|
| 46 |
+
shift 2
|
| 47 |
+
;;
|
| 48 |
+
--wandb)
|
| 49 |
+
WANDB_FLAG="--wandb"
|
| 50 |
+
shift
|
| 51 |
+
;;
|
| 52 |
+
*)
|
| 53 |
+
echo "Unknown argument: $1"
|
| 54 |
+
exit 1
|
| 55 |
+
;;
|
| 56 |
+
esac
|
| 57 |
+
done
|
| 58 |
+
|
| 59 |
+
for task in {boolq,multirc}; do
|
| 60 |
+
echo $task
|
| 61 |
+
|
| 62 |
+
python -m evaluation_pipeline.finetune.run \
|
| 63 |
+
--model_name_or_path "$MODEL_PATH" \
|
| 64 |
+
--train_data "evaluation_data/full_eval/glue_filtered/$task.train.jsonl" \
|
| 65 |
+
--valid_data "evaluation_data/full_eval/glue_filtered/$task.valid.jsonl" \
|
| 66 |
+
--predict_data "evaluation_data/full_eval/glue_filtered/$task.valid.jsonl" \
|
| 67 |
+
--task "$task" \
|
| 68 |
+
--num_labels 2 \
|
| 69 |
+
--batch_size $BIG_BSZ \
|
| 70 |
+
--learning_rate $LR \
|
| 71 |
+
--num_epochs $MAX_EPOCHS \
|
| 72 |
+
--sequence_length 512 \
|
| 73 |
+
--results_dir "results" \
|
| 74 |
+
--save \
|
| 75 |
+
--save_dir "models" \
|
| 76 |
+
--metrics accuracy f1 mcc \
|
| 77 |
+
--metric_for_valid accuracy \
|
| 78 |
+
--seed $SEED \
|
| 79 |
+
--verbose \
|
| 80 |
+
--padding_side left \
|
| 81 |
+
--take_final \
|
| 82 |
+
$WANDB_FLAG
|
| 83 |
+
done
|
| 84 |
+
|
| 85 |
+
python -m evaluation_pipeline.finetune.run \
|
| 86 |
+
--model_name_or_path "$MODEL_PATH" \
|
| 87 |
+
--train_data "evaluation_data/full_eval/glue_filtered/rte.train.jsonl" \
|
| 88 |
+
--valid_data "evaluation_data/full_eval/glue_filtered/rte.valid.jsonl" \
|
| 89 |
+
--predict_data "evaluation_data/full_eval/glue_filtered/rte.valid.jsonl" \
|
| 90 |
+
--task rte \
|
| 91 |
+
--num_labels 2 \
|
| 92 |
+
--batch_size $BSZ \
|
| 93 |
+
--learning_rate $LR \
|
| 94 |
+
--num_epochs $MAX_EPOCHS \
|
| 95 |
+
--sequence_length 512 \
|
| 96 |
+
--results_dir "results" \
|
| 97 |
+
--save \
|
| 98 |
+
--save_dir "models" \
|
| 99 |
+
--metrics accuracy f1 mcc \
|
| 100 |
+
--metric_for_valid accuracy \
|
| 101 |
+
--seed $SEED \
|
| 102 |
+
--verbose \
|
| 103 |
+
--padding_side left \
|
| 104 |
+
--take_final \
|
| 105 |
+
$WANDB_FLAG
|
| 106 |
+
|
| 107 |
+
python -m evaluation_pipeline.finetune.run \
|
| 108 |
+
--model_name_or_path "$MODEL_PATH" \
|
| 109 |
+
--train_data "evaluation_data/full_eval/glue_filtered/wsc.train.jsonl" \
|
| 110 |
+
--valid_data "evaluation_data/full_eval/glue_filtered/wsc.valid.jsonl" \
|
| 111 |
+
--predict_data "evaluation_data/full_eval/glue_filtered/wsc.valid.jsonl" \
|
| 112 |
+
--task wsc \
|
| 113 |
+
--num_labels 2 \
|
| 114 |
+
--batch_size $BSZ \
|
| 115 |
+
--learning_rate $LR \
|
| 116 |
+
--num_epochs $WSC_EPOCHS \
|
| 117 |
+
--sequence_length 512 \
|
| 118 |
+
--results_dir "results" \
|
| 119 |
+
--save \
|
| 120 |
+
--save_dir "models" \
|
| 121 |
+
--metrics accuracy f1 mcc \
|
| 122 |
+
--metric_for_valid accuracy \
|
| 123 |
+
--seed $SEED \
|
| 124 |
+
--verbose \
|
| 125 |
+
--padding_side left \
|
| 126 |
+
--take_final \
|
| 127 |
+
$WANDB_FLAG
|
| 128 |
+
|
| 129 |
+
for task in {mrpc,qqp}; do
|
| 130 |
+
|
| 131 |
+
python -m evaluation_pipeline.finetune.run \
|
| 132 |
+
--model_name_or_path "$MODEL_PATH" \
|
| 133 |
+
--train_data "evaluation_data/full_eval/glue_filtered/$task.train.jsonl" \
|
| 134 |
+
--valid_data "evaluation_data/full_eval/glue_filtered/$task.valid.jsonl" \
|
| 135 |
+
--predict_data "evaluation_data/full_eval/glue_filtered/$task.valid.jsonl" \
|
| 136 |
+
--task "$task" \
|
| 137 |
+
--num_labels 2 \
|
| 138 |
+
--batch_size $BSZ \
|
| 139 |
+
--learning_rate $LR \
|
| 140 |
+
--num_epochs $MAX_EPOCHS \
|
| 141 |
+
--sequence_length 512 \
|
| 142 |
+
--results_dir "results" \
|
| 143 |
+
--save \
|
| 144 |
+
--save_dir "models" \
|
| 145 |
+
--metrics accuracy f1 mcc \
|
| 146 |
+
--metric_for_valid f1 \
|
| 147 |
+
--seed $SEED \
|
| 148 |
+
--verbose \
|
| 149 |
+
--padding_side left \
|
| 150 |
+
--take_final \
|
| 151 |
+
$WANDB_FLAG
|
| 152 |
+
done
|
| 153 |
+
|
| 154 |
+
python -m evaluation_pipeline.finetune.run \
|
| 155 |
+
--model_name_or_path "$MODEL_PATH" \
|
| 156 |
+
--train_data "evaluation_data/full_eval/glue_filtered/mnli.train.jsonl" \
|
| 157 |
+
--valid_data "evaluation_data/full_eval/glue_filtered/mnli.valid.jsonl" \
|
| 158 |
+
--predict_data "evaluation_data/full_eval/glue_filtered/mnli.valid.jsonl" \
|
| 159 |
+
--task mnli \
|
| 160 |
+
--num_labels 3 \
|
| 161 |
+
--batch_size $BSZ \
|
| 162 |
+
--learning_rate $LR \
|
| 163 |
+
--num_epochs $MAX_EPOCHS \
|
| 164 |
+
--sequence_length 512 \
|
| 165 |
+
--results_dir "results" \
|
| 166 |
+
--save \
|
| 167 |
+
--save_dir "models" \
|
| 168 |
+
--metrics accuracy \
|
| 169 |
+
--metric_for_valid accuracy \
|
| 170 |
+
--seed $SEED \
|
| 171 |
+
--verbose \
|
| 172 |
+
--padding_side left \
|
| 173 |
+
--take_final \
|
| 174 |
+
$WANDB_FLAG
|
babylm_eval_repo/strict/scripts/eval_multimodal.sh
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
MODEL_PATH=$1
|
| 4 |
+
BACKEND=$2
|
| 5 |
+
MODEL_TYPE=$3
|
| 6 |
+
IMAGE_MODEL=$4
|
| 7 |
+
EVAL_DIR=${5:-"evaluation_data/full_eval"}
|
| 8 |
+
|
| 9 |
+
if [[ "$BACKEND" == *"enc_dec"* ]]; then
|
| 10 |
+
BACKEND_READ="enc_dec"
|
| 11 |
+
else
|
| 12 |
+
BACKEND_READ=$BACKEND
|
| 13 |
+
fi
|
| 14 |
+
|
| 15 |
+
echo $BACKEND_READ
|
| 16 |
+
|
| 17 |
+
# Winoground and VQA
|
| 18 |
+
python -m evaluation_pipeline.sentence_zero_shot.run --model_path_or_name $MODEL_PATH --backend $BACKEND --task vqa --data_path "evaluation_data/full_eval/vqa_filtered" --save_predictions --images_path=HuggingFaceM4/VQAv2 --image_split=validation --batch_size=1
|
| 19 |
+
python -m evaluation_pipeline.sentence_zero_shot.run --model_path_or_name $MODEL_PATH --backend $BACKEND --task winoground --data_path "evaluation_data/full_eval/winoground_filtered" --save_predictions --images_path=facebook/winoground --image_split=test --batch_size=1
|
| 20 |
+
|
| 21 |
+
# Devbench
|
| 22 |
+
# Supported MODEL_TYPE values:
|
| 23 |
+
# git, flamingo, llava, flava, clip, blip, siglip, bridgetower, vilt, cvcl
|
| 24 |
+
|
| 25 |
+
# If you need a different MODEL_TYPE, implement it in the `evaluation_pipeline/devbench/model_classes` folder.
|
| 26 |
+
# (See other files in that folder for examples.)
|
| 27 |
+
# Then add a wrapper to `evaluation_pipeline/devbench/eval.py`.
|
| 28 |
+
# Be sure to submit a pull request so others can benefit from your implementation!
|
| 29 |
+
|
| 30 |
+
python -m evaluation_pipeline.devbench.eval --model $MODEL_PATH \
|
| 31 |
+
--model_type $MODEL_TYPE \
|
| 32 |
+
--image_model $IMAGE_MODEL
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
babylm_eval_repo/strict/scripts/eval_zero_shot.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
MODEL_PATH=$1
|
| 4 |
+
BACKEND=$2
|
| 5 |
+
EVAL_DIR=${3:-"evaluation_data/full_eval"}
|
| 6 |
+
REVISION=${4:-main}
|
| 7 |
+
|
| 8 |
+
if [[ "$BACKEND" == *"enc_dec"* ]]; then
|
| 9 |
+
BACKEND_READ="enc_dec"
|
| 10 |
+
else
|
| 11 |
+
BACKEND_READ=$BACKEND
|
| 12 |
+
fi
|
| 13 |
+
|
| 14 |
+
echo $BACKEND_READ
|
| 15 |
+
|
| 16 |
+
python -m evaluation_pipeline.sentence_zero_shot.run --model_path_or_name $MODEL_PATH --backend $BACKEND --task blimp --data_path "${EVAL_DIR}/blimp_filtered" --save_predictions --revision_name $REVISION
|
| 17 |
+
python -m evaluation_pipeline.sentence_zero_shot.run --model_path_or_name $MODEL_PATH --backend $BACKEND --task blimp --data_path "${EVAL_DIR}/supplement_filtered" --save_predictions --revision_name $REVISION
|
| 18 |
+
python -m evaluation_pipeline.sentence_zero_shot.run --model_path_or_name $MODEL_PATH --backend $BACKEND --task ewok --data_path "${EVAL_DIR}/ewok_filtered" --save_predictions --revision_name $REVISION
|
| 19 |
+
python -m evaluation_pipeline.sentence_zero_shot.run --model_path_or_name $MODEL_PATH --backend $BACKEND --task entity_tracking --data_path "${EVAL_DIR}/entity_tracking" --save_predictions --revision_name $REVISION
|
| 20 |
+
python -m evaluation_pipeline.sentence_zero_shot.run --model_path_or_name $MODEL_PATH --backend $BACKEND --task comps --data_path "${EVAL_DIR}/comps" --save_predictions --revision_name $REVISION
|
| 21 |
+
python -m evaluation_pipeline.reading.run --model_path_or_name $MODEL_PATH --backend $BACKEND_READ --data_path "${EVAL_DIR}/reading/reading_data.csv" --revision_name $REVISION
|
babylm_eval_repo/strict/scripts/eval_zero_shot_fast.sh
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
MODEL_PATH=$1
|
| 4 |
+
REVISION_NAME=$2
|
| 5 |
+
BACKEND=$3
|
| 6 |
+
EVAL_DIR=${4:-"evaluation_data/fast_eval"}
|
| 7 |
+
|
| 8 |
+
if [[ "$BACKEND" == *"enc_dec"* ]]; then
|
| 9 |
+
BACKEND_READ="enc_dec"
|
| 10 |
+
else
|
| 11 |
+
BACKEND_READ=$BACKEND
|
| 12 |
+
fi
|
| 13 |
+
|
| 14 |
+
python -m evaluation_pipeline.sentence_zero_shot.run --model_path_or_name $MODEL_PATH --backend $BACKEND --task blimp --data_path "${EVAL_DIR}/blimp_fast" --save_predictions --revision_name $REVISION_NAME
|
| 15 |
+
python -m evaluation_pipeline.sentence_zero_shot.run --model_path_or_name $MODEL_PATH --backend $BACKEND --task blimp --data_path "${EVAL_DIR}/supplement_fast" --save_predictions --revision_name $REVISION_NAME
|
| 16 |
+
python -m evaluation_pipeline.sentence_zero_shot.run --model_path_or_name $MODEL_PATH --backend $BACKEND --task ewok --data_path "${EVAL_DIR}/ewok_fast" --save_predictions --revision_name $REVISION_NAME
|
| 17 |
+
python -m evaluation_pipeline.sentence_zero_shot.run --model_path_or_name $MODEL_PATH --backend $BACKEND --task entity_tracking --data_path "${EVAL_DIR}/entity_tracking_fast" --save_predictions --revision_name $REVISION_NAME
|
| 18 |
+
python -m evaluation_pipeline.reading.run --model_path_or_name $MODEL_PATH --backend $BACKEND_READ --data_path "${EVAL_DIR}/reading/reading_data.csv" --revision_name $REVISION_NAME
|
babylm_eval_repo/strict/scripts/eval_zero_shot_fast_all_revisions.sh
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
MODEL_PATH=$1
|
| 4 |
+
BACKEND=$2
|
| 5 |
+
TRACK=$3
|
| 6 |
+
EVAL_DIR=${4:-"evaluation_data/fast_eval"}
|
| 7 |
+
|
| 8 |
+
for i in {1..9}; do
|
| 9 |
+
checkpoint="chck_${i}M"
|
| 10 |
+
echo "Evaluating checkpoint ${checkpoint}"
|
| 11 |
+
bash scripts/eval_zero_shot_fast.sh $MODEL_PATH $checkpoint $BACKEND $EVAL_DIR
|
| 12 |
+
done
|
| 13 |
+
|
| 14 |
+
for i in {10..100..10}; do
|
| 15 |
+
checkpoint="chck_${i}M"
|
| 16 |
+
echo "Evaluating checkpoint ${checkpoint}"
|
| 17 |
+
bash scripts/eval_zero_shot_fast.sh $MODEL_PATH $checkpoint $BACKEND $EVAL_DIR
|
| 18 |
+
done
|
| 19 |
+
|
| 20 |
+
# Conditional on whether the track is strict-small
|
| 21 |
+
if [[ "$3" != "strict-small" ]]; then
|
| 22 |
+
for i in {200..1000..100}; do
|
| 23 |
+
checkpoint="chck_${i}M"
|
| 24 |
+
echo "Evaluating checkpoint ${checkpoint}"
|
| 25 |
+
bash scripts/eval_zero_shot_fast.sh $MODEL_PATH $checkpoint $BACKEND $EVAL_DIR
|
| 26 |
+
done
|
| 27 |
+
fi
|
babylm_eval_repo/strict/scripts/eval_zero_shot_global_piqa.sh
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# GlobalPIQA-only zero-shot evaluation for a single model, covering both the
|
| 3 |
+
# main checkpoint and all intermediate (fast-revision) checkpoints. This is a
|
| 4 |
+
# combined, GlobalPIQA-dedicated version of eval_zero_shot.sh +
|
| 5 |
+
# eval_zero_shot_fast_all_revisions.sh.
|
| 6 |
+
#
|
| 7 |
+
# GlobalPIQA is not subsampled for the fast evaluation, so the parallel/
|
| 8 |
+
# nonparallel data are identical under full_eval and fast_eval. The main
|
| 9 |
+
# checkpoint (which feeds the full-eval collation) is scored against full_eval;
|
| 10 |
+
# the intermediate checkpoints (which feed the fast-eval collation) are scored
|
| 11 |
+
# against fast_eval, mirroring every other fast task. Predictions are
|
| 12 |
+
# length-normalized at inference time, so the resulting accuracy is acc_norm.
|
| 13 |
+
#
|
| 14 |
+
# Usage (run from the strict/ directory):
|
| 15 |
+
# bash scripts/eval_zero_shot_global_piqa.sh MODEL_PATH BACKEND TRACK [EVAL_DIR] [FAST_EVAL_DIR]
|
| 16 |
+
#
|
| 17 |
+
# MODEL_PATH HuggingFace repo id or local path to the model.
|
| 18 |
+
# BACKEND Evaluation backend (causal, mlm, mntp, enc_dec_mask, enc_dec_prefix).
|
| 19 |
+
# TRACK strict | strict-small (strict-small stops at the 100M checkpoint).
|
| 20 |
+
# EVAL_DIR Optional full-eval data dir for the main checkpoint (default evaluation_data/full_eval).
|
| 21 |
+
# FAST_EVAL_DIR Optional fast-eval data dir for intermediate checkpoints (default evaluation_data/fast_eval).
|
| 22 |
+
|
| 23 |
+
MODEL_PATH=$1
|
| 24 |
+
BACKEND=$2
|
| 25 |
+
TRACK=$3
|
| 26 |
+
EVAL_DIR=${4:-"evaluation_data/full_eval"}
|
| 27 |
+
FAST_EVAL_DIR=${5:-"evaluation_data/fast_eval"}
|
| 28 |
+
|
| 29 |
+
# Run the two GlobalPIQA tasks for one checkpoint against the given data dir.
|
| 30 |
+
# With no revision argument the pipeline defaults to the "main" checkpoint;
|
| 31 |
+
# otherwise the given revision name is passed through.
|
| 32 |
+
run_global_piqa () {
|
| 33 |
+
local revision=$1
|
| 34 |
+
local data_dir=$2
|
| 35 |
+
local revision_args=""
|
| 36 |
+
if [[ -n "$revision" ]]; then
|
| 37 |
+
revision_args="--revision_name $revision"
|
| 38 |
+
fi
|
| 39 |
+
|
| 40 |
+
python -m evaluation_pipeline.sentence_zero_shot.run --model_path_or_name $MODEL_PATH --backend $BACKEND --task global_piqa_parallel --data_path "${data_dir}/global_piqa_parallel" --save_predictions $revision_args
|
| 41 |
+
python -m evaluation_pipeline.sentence_zero_shot.run --model_path_or_name $MODEL_PATH --backend $BACKEND --task global_piqa_nonparallel --data_path "${data_dir}/global_piqa_nonparallel" --save_predictions $revision_args
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
# Main checkpoint -> full_eval
|
| 45 |
+
echo "Evaluating checkpoint main"
|
| 46 |
+
run_global_piqa "" "$EVAL_DIR"
|
| 47 |
+
|
| 48 |
+
# Intermediate checkpoints -> fast_eval: 1M..9M, then 10M..100M
|
| 49 |
+
for i in {1..9}; do
|
| 50 |
+
checkpoint="chck_${i}M"
|
| 51 |
+
echo "Evaluating checkpoint ${checkpoint}"
|
| 52 |
+
run_global_piqa $checkpoint "$FAST_EVAL_DIR"
|
| 53 |
+
done
|
| 54 |
+
|
| 55 |
+
for i in {10..100..10}; do
|
| 56 |
+
checkpoint="chck_${i}M"
|
| 57 |
+
echo "Evaluating checkpoint ${checkpoint}"
|
| 58 |
+
run_global_piqa $checkpoint "$FAST_EVAL_DIR"
|
| 59 |
+
done
|
| 60 |
+
|
| 61 |
+
# Full strict track continues past 100M up to 1000M; strict-small stops at 100M.
|
| 62 |
+
if [[ "$TRACK" != "strict-small" ]]; then
|
| 63 |
+
for i in {200..1000..100}; do
|
| 64 |
+
checkpoint="chck_${i}M"
|
| 65 |
+
echo "Evaluating checkpoint ${checkpoint}"
|
| 66 |
+
run_global_piqa $checkpoint "$FAST_EVAL_DIR"
|
| 67 |
+
done
|
| 68 |
+
fi
|
babylm_eval_repo/strict/scripts/print_results_table.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Print aggregate markdown tables of strict-track results from results/.
|
| 3 |
+
|
| 4 |
+
Zero-shot results are read from:
|
| 5 |
+
results/{model}/main/{eval_type}/causal/{task}/{subtask}/best_temperature_report.txt
|
| 6 |
+
|
| 7 |
+
Finetune results are read from:
|
| 8 |
+
results/{model}/main/finetune/{task}/results.txt
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
# Primary metric per GLUE task, matching the leaderboard definition in about.py.
|
| 14 |
+
FINETUNE_METRIC = {
|
| 15 |
+
"boolq": "accuracy",
|
| 16 |
+
"mnli": "accuracy",
|
| 17 |
+
"mrpc": "f1",
|
| 18 |
+
"multirc": "accuracy",
|
| 19 |
+
"qqp": "f1",
|
| 20 |
+
"rte": "accuracy",
|
| 21 |
+
"wsc": "accuracy",
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def parse_average_score(report_path: Path) -> float | None:
|
| 26 |
+
"""Return the average score from a best_temperature_report.txt file.
|
| 27 |
+
|
| 28 |
+
Handles both '### AVERAGE ACCURACY' and '### AVERAGE SPEARMAN'S RHO' headers.
|
| 29 |
+
"""
|
| 30 |
+
lines = report_path.read_text().splitlines()
|
| 31 |
+
for i, line in enumerate(lines):
|
| 32 |
+
if line.strip().startswith("### AVERAGE"):
|
| 33 |
+
if i + 1 < len(lines):
|
| 34 |
+
try:
|
| 35 |
+
return float(lines[i + 1].strip())
|
| 36 |
+
except ValueError:
|
| 37 |
+
return None
|
| 38 |
+
return None
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def parse_finetune_score(results_path: Path, metric: str) -> float | None:
|
| 42 |
+
"""Return the value of `metric` from a finetune results.txt file."""
|
| 43 |
+
for line in results_path.read_text().splitlines():
|
| 44 |
+
key, _, value = line.partition(":")
|
| 45 |
+
if key.strip() == metric:
|
| 46 |
+
try:
|
| 47 |
+
return float(value.strip()) * 100
|
| 48 |
+
except ValueError:
|
| 49 |
+
return None
|
| 50 |
+
return None
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def fmt_row(cells: list[str]) -> str:
|
| 54 |
+
return "| " + " | ".join(cells) + " |"
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def print_table(
|
| 58 |
+
all_models: dict[str, dict[str, float]],
|
| 59 |
+
row_order: list[str],
|
| 60 |
+
models: list[str],
|
| 61 |
+
) -> None:
|
| 62 |
+
print(fmt_row(["task"] + models))
|
| 63 |
+
print(fmt_row(["---"] + ["---"] * len(models)))
|
| 64 |
+
for row_key in row_order:
|
| 65 |
+
vals = [all_models[model].get(row_key) for model in models]
|
| 66 |
+
best = max((v for v in vals if v is not None), default=None)
|
| 67 |
+
row = [row_key]
|
| 68 |
+
for val in vals:
|
| 69 |
+
if val is None:
|
| 70 |
+
row.append("")
|
| 71 |
+
elif val == best:
|
| 72 |
+
row.append(f"**{val:.2f}**")
|
| 73 |
+
else:
|
| 74 |
+
row.append(f"{val:.2f}")
|
| 75 |
+
print(fmt_row(row))
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def main():
|
| 79 |
+
results_dir = Path(__file__).parent.parent / "results"
|
| 80 |
+
|
| 81 |
+
# --- Zero-shot ---
|
| 82 |
+
zeroshot_models: dict[str, dict[str, float]] = {}
|
| 83 |
+
zeroshot_row_order: list[str] = []
|
| 84 |
+
|
| 85 |
+
for report in sorted(results_dir.glob("*/main/*/causal/*/*/best_temperature_report.txt")):
|
| 86 |
+
# parts: results / model / main / eval_type / causal / task / subtask / filename
|
| 87 |
+
parts = report.parts
|
| 88 |
+
model = parts[-7]
|
| 89 |
+
eval_type = parts[-5]
|
| 90 |
+
task = parts[-3]
|
| 91 |
+
subtask = parts[-2]
|
| 92 |
+
|
| 93 |
+
score = parse_average_score(report)
|
| 94 |
+
if score is None:
|
| 95 |
+
continue
|
| 96 |
+
|
| 97 |
+
row_key = f"{eval_type}/{task}/{subtask}"
|
| 98 |
+
if row_key not in zeroshot_row_order:
|
| 99 |
+
zeroshot_row_order.append(row_key)
|
| 100 |
+
zeroshot_models.setdefault(model, {})[row_key] = score
|
| 101 |
+
|
| 102 |
+
# --- Finetune ---
|
| 103 |
+
finetune_models: dict[str, dict[str, float]] = {}
|
| 104 |
+
finetune_row_order: list[str] = []
|
| 105 |
+
|
| 106 |
+
for results_file in sorted(results_dir.glob("*/main/finetune/*/results.txt")):
|
| 107 |
+
# parts: results / model / main / finetune / task / filename
|
| 108 |
+
parts = results_file.parts
|
| 109 |
+
model = parts[-5]
|
| 110 |
+
task = parts[-2]
|
| 111 |
+
|
| 112 |
+
metric = FINETUNE_METRIC.get(task, "accuracy")
|
| 113 |
+
score = parse_finetune_score(results_file, metric)
|
| 114 |
+
if score is None:
|
| 115 |
+
continue
|
| 116 |
+
|
| 117 |
+
row_key = f"{task} ({metric})"
|
| 118 |
+
if row_key not in finetune_row_order:
|
| 119 |
+
finetune_row_order.append(row_key)
|
| 120 |
+
finetune_models.setdefault(model, {})[row_key] = score
|
| 121 |
+
|
| 122 |
+
if not zeroshot_models and not finetune_models:
|
| 123 |
+
print("No results found.")
|
| 124 |
+
return
|
| 125 |
+
|
| 126 |
+
all_models = sorted(set(list(zeroshot_models) + list(finetune_models)))
|
| 127 |
+
|
| 128 |
+
if zeroshot_models:
|
| 129 |
+
print("## Zero-shot\n")
|
| 130 |
+
print_table(zeroshot_models, zeroshot_row_order, all_models)
|
| 131 |
+
|
| 132 |
+
if finetune_models:
|
| 133 |
+
print("\n## Finetune (GLUE)\n")
|
| 134 |
+
print_table(finetune_models, finetune_row_order, all_models)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
if __name__ == "__main__":
|
| 138 |
+
main()
|
checkpoints/xpertgpt_fresh/bpe_vocab_16k.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
checkpoints/xpertgpt_fresh/chck_100M/config.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"auto_map": {
|
| 3 |
+
"AutoConfig": "configuration_xpertgpt.XpertGPTConfig",
|
| 4 |
+
"AutoModel": "modeling_xpertgpt.XpertGPTModelWrapper",
|
| 5 |
+
"AutoModelForCausalLM": "modeling_xpertgpt.XpertGPTForCausalLM"
|
| 6 |
+
},
|
| 7 |
+
"vocab_size": 16384,
|
| 8 |
+
"block_size": 512,
|
| 9 |
+
"d_model": 256,
|
| 10 |
+
"hidden_size": 256,
|
| 11 |
+
"d_thin": 384,
|
| 12 |
+
"num_layers": 6,
|
| 13 |
+
"num_blocks": 4,
|
| 14 |
+
"capacity_factor": 0.5,
|
| 15 |
+
"dropout": 0.1,
|
| 16 |
+
"model_type": "xpertgpt"
|
| 17 |
+
}
|
checkpoints/xpertgpt_fresh/chck_100M/configuration_xpertgpt.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import PretrainedConfig
|
| 2 |
+
|
| 3 |
+
class XpertGPTConfig(PretrainedConfig):
|
| 4 |
+
model_type = "xpertgpt"
|
| 5 |
+
|
| 6 |
+
def __init__(
|
| 7 |
+
self,
|
| 8 |
+
vocab_size: int = 16384,
|
| 9 |
+
block_size: int = 512,
|
| 10 |
+
d_model: int = 256,
|
| 11 |
+
d_thin: int = 384,
|
| 12 |
+
num_layers: int = 6,
|
| 13 |
+
num_blocks: int = 4,
|
| 14 |
+
capacity_factor: float = 0.5,
|
| 15 |
+
dropout: float = 0.1,
|
| 16 |
+
**kwargs
|
| 17 |
+
):
|
| 18 |
+
kwargs.setdefault("is_decoder", True)
|
| 19 |
+
kwargs.setdefault("bos_token_id", 2) # [CLS]
|
| 20 |
+
kwargs.setdefault("eos_token_id", 3) # [SEP]
|
| 21 |
+
kwargs.setdefault("pad_token_id", 1) # [PAD]
|
| 22 |
+
|
| 23 |
+
self.vocab_size = vocab_size
|
| 24 |
+
self.block_size = block_size
|
| 25 |
+
self.d_model = d_model
|
| 26 |
+
self.d_thin = d_thin
|
| 27 |
+
self.num_layers = num_layers
|
| 28 |
+
self.num_blocks = num_blocks
|
| 29 |
+
self.capacity_factor = capacity_factor
|
| 30 |
+
self.dropout = dropout
|
| 31 |
+
|
| 32 |
+
# Attribute parity for classification heads
|
| 33 |
+
self.hidden_size = d_model
|
| 34 |
+
self.num_hidden_layers = num_layers
|
| 35 |
+
|
| 36 |
+
super().__init__(**kwargs)
|
checkpoints/xpertgpt_fresh/chck_100M/modeling_xpertgpt.py
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import math
|
| 3 |
+
import random
|
| 4 |
+
import inspect
|
| 5 |
+
from typing import Optional, Tuple, Dict, Any
|
| 6 |
+
from dataclasses import dataclass
|
| 7 |
+
|
| 8 |
+
import torch
|
| 9 |
+
import torch.nn as nn
|
| 10 |
+
import torch.nn.functional as F
|
| 11 |
+
|
| 12 |
+
from transformers import PretrainedConfig, PreTrainedModel, GenerationMixin, AutoConfig, AutoModel, AutoModelForCausalLM
|
| 13 |
+
from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
|
| 14 |
+
|
| 15 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 16 |
+
# Configuration Classes
|
| 17 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 18 |
+
|
| 19 |
+
@dataclass
|
| 20 |
+
class XpertGPTModelConfig:
|
| 21 |
+
vocab_size: int = 16384
|
| 22 |
+
block_size: int = 512
|
| 23 |
+
d_model: int = 256
|
| 24 |
+
d_thin: int = 384
|
| 25 |
+
num_layers: int = 6
|
| 26 |
+
num_blocks: int = 4
|
| 27 |
+
capacity_factor: float = 0.5
|
| 28 |
+
dropout: float = 0.1
|
| 29 |
+
|
| 30 |
+
class XpertGPTConfig(PretrainedConfig):
|
| 31 |
+
model_type = "xpertgpt"
|
| 32 |
+
auto_map = {
|
| 33 |
+
"AutoConfig": "configuration_xpertgpt.XpertGPTConfig",
|
| 34 |
+
"AutoModel": "modeling_xpertgpt.XpertGPTModelWrapper",
|
| 35 |
+
"AutoModelForCausalLM": "modeling_xpertgpt.XpertGPTForCausalLM"
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
def __init__(
|
| 39 |
+
self,
|
| 40 |
+
vocab_size: int = 16384,
|
| 41 |
+
block_size: int = 512,
|
| 42 |
+
d_model: int = 256,
|
| 43 |
+
d_thin: int = 384,
|
| 44 |
+
num_layers: int = 6,
|
| 45 |
+
num_blocks: int = 4,
|
| 46 |
+
capacity_factor: float = 0.5,
|
| 47 |
+
dropout: float = 0.1,
|
| 48 |
+
**kwargs
|
| 49 |
+
):
|
| 50 |
+
kwargs.setdefault("is_decoder", True)
|
| 51 |
+
kwargs.setdefault("bos_token_id", 2) # [CLS]
|
| 52 |
+
kwargs.setdefault("eos_token_id", 3) # [SEP]
|
| 53 |
+
kwargs.setdefault("pad_token_id", 1) # [PAD]
|
| 54 |
+
|
| 55 |
+
self.vocab_size = vocab_size
|
| 56 |
+
self.block_size = block_size
|
| 57 |
+
self.d_model = d_model
|
| 58 |
+
self.d_thin = d_thin
|
| 59 |
+
self.num_layers = num_layers
|
| 60 |
+
self.num_blocks = num_blocks
|
| 61 |
+
self.capacity_factor = capacity_factor
|
| 62 |
+
self.dropout = dropout
|
| 63 |
+
|
| 64 |
+
# Attribute parity for classification heads
|
| 65 |
+
self.hidden_size = d_model
|
| 66 |
+
self.num_hidden_layers = num_layers
|
| 67 |
+
|
| 68 |
+
super().__init__(**kwargs)
|
| 69 |
+
|
| 70 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 71 |
+
# ROPE HELPERS
|
| 72 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 73 |
+
|
| 74 |
+
def _precompute_rope_freqs(head_dim: int, seq_len: int, device: torch.device, theta: float = 10000.0):
|
| 75 |
+
assert head_dim % 2 == 0, "head_dim must be divisible by 2 for RoPE"
|
| 76 |
+
inv_freq = 1.0 / (theta ** (torch.arange(0, head_dim, 2, device=device).float() / head_dim))
|
| 77 |
+
t = torch.arange(seq_len, device=device).float()
|
| 78 |
+
freqs = torch.outer(t, inv_freq)
|
| 79 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 80 |
+
return emb.cos(), emb.sin()
|
| 81 |
+
|
| 82 |
+
def _apply_rope(x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor):
|
| 83 |
+
L = x.size(2)
|
| 84 |
+
cos = cos[:L, :].unsqueeze(0).unsqueeze(1)
|
| 85 |
+
sin = sin[:L, :].unsqueeze(0).unsqueeze(1)
|
| 86 |
+
|
| 87 |
+
half_dim = x.size(-1) // 2
|
| 88 |
+
x1 = x[..., :half_dim]
|
| 89 |
+
x2 = x[..., half_dim:]
|
| 90 |
+
rotated_x = torch.cat((-x2, x1), dim=-1)
|
| 91 |
+
|
| 92 |
+
return (x * cos) + (rotated_x * sin)
|
| 93 |
+
|
| 94 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 95 |
+
# 1. SLIDING WINDOW ATTENTION
|
| 96 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 97 |
+
|
| 98 |
+
class SlidingWindowAttention(nn.Module):
|
| 99 |
+
def __init__(self, dim: int, num_heads: int, window_size=None):
|
| 100 |
+
super().__init__()
|
| 101 |
+
assert dim % num_heads == 0, "dim must be divisible by num_heads"
|
| 102 |
+
self.num_heads = num_heads
|
| 103 |
+
self.window_size = window_size
|
| 104 |
+
self.head_dim = dim // num_heads
|
| 105 |
+
|
| 106 |
+
self.q_proj = nn.Linear(dim, dim, bias=False)
|
| 107 |
+
self.k_proj = nn.Linear(dim, dim, bias=False)
|
| 108 |
+
self.v_proj = nn.Linear(dim, dim, bias=False)
|
| 109 |
+
self.o_proj = nn.Linear(dim, dim, bias=False)
|
| 110 |
+
|
| 111 |
+
def forward(self, x: torch.Tensor,
|
| 112 |
+
past_kv=None,
|
| 113 |
+
use_cache: bool = False,
|
| 114 |
+
bidirectional: bool = False):
|
| 115 |
+
B, L, D = x.size()
|
| 116 |
+
|
| 117 |
+
q = self.q_proj(x).view(B, L, self.num_heads, self.head_dim).transpose(1, 2)
|
| 118 |
+
k = self.k_proj(x).view(B, L, self.num_heads, self.head_dim).transpose(1, 2)
|
| 119 |
+
v = self.v_proj(x).view(B, L, self.num_heads, self.head_dim).transpose(1, 2)
|
| 120 |
+
|
| 121 |
+
if past_kv is not None:
|
| 122 |
+
past_k, past_v = past_kv
|
| 123 |
+
past_len = past_k.size(2)
|
| 124 |
+
q_cos, q_sin = _precompute_rope_freqs(self.head_dim, past_len + L, x.device)
|
| 125 |
+
q = _apply_rope(q, q_cos[past_len:, :], q_sin[past_len:, :])
|
| 126 |
+
k = _apply_rope(k, q_cos[past_len:, :], q_sin[past_len:, :])
|
| 127 |
+
|
| 128 |
+
k = torch.cat([past_k, k], dim=2)
|
| 129 |
+
v = torch.cat([past_v, v], dim=2)
|
| 130 |
+
else:
|
| 131 |
+
cos, sin = _precompute_rope_freqs(self.head_dim, L, x.device)
|
| 132 |
+
q = _apply_rope(q, cos, sin)
|
| 133 |
+
k = _apply_rope(k, cos, sin)
|
| 134 |
+
|
| 135 |
+
L_kv = k.size(2)
|
| 136 |
+
scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(self.head_dim)
|
| 137 |
+
|
| 138 |
+
if bidirectional:
|
| 139 |
+
if self.window_size is not None:
|
| 140 |
+
past_len = L_kv - L
|
| 141 |
+
pos_i = (past_len + torch.arange(L, device=x.device)).unsqueeze(1)
|
| 142 |
+
pos_j = torch.arange(L_kv, device=x.device).unsqueeze(0)
|
| 143 |
+
dist = torch.abs(pos_i - pos_j)
|
| 144 |
+
win_mask = dist < self.window_size
|
| 145 |
+
scores = scores.masked_fill(
|
| 146 |
+
~win_mask.unsqueeze(0).unsqueeze(0), float('-inf')
|
| 147 |
+
)
|
| 148 |
+
else:
|
| 149 |
+
past_len = L_kv - L
|
| 150 |
+
pos_i = (past_len + torch.arange(L, device=x.device)).unsqueeze(1)
|
| 151 |
+
pos_j = torch.arange(L_kv, device=x.device).unsqueeze(0)
|
| 152 |
+
dist = pos_i - pos_j
|
| 153 |
+
|
| 154 |
+
causal_mask = dist >= 0
|
| 155 |
+
if self.window_size is not None:
|
| 156 |
+
causal_mask = causal_mask & (dist < self.window_size)
|
| 157 |
+
|
| 158 |
+
scores = scores.masked_fill(
|
| 159 |
+
~causal_mask.unsqueeze(0).unsqueeze(0), float('-inf')
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
attn = torch.softmax(scores, dim=-1)
|
| 163 |
+
out = torch.matmul(attn, v)
|
| 164 |
+
out = out.transpose(1, 2).contiguous().view(B, L, D)
|
| 165 |
+
out = self.o_proj(out)
|
| 166 |
+
|
| 167 |
+
if use_cache:
|
| 168 |
+
if self.window_size is not None:
|
| 169 |
+
present_kv = (
|
| 170 |
+
k[:, :, -self.window_size:, :],
|
| 171 |
+
v[:, :, -self.window_size:, :]
|
| 172 |
+
)
|
| 173 |
+
else:
|
| 174 |
+
present_kv = (k, v)
|
| 175 |
+
else:
|
| 176 |
+
present_kv = None
|
| 177 |
+
|
| 178 |
+
return out, present_kv
|
| 179 |
+
|
| 180 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 181 |
+
# 2. MSIT BRANCH BLOCK (Pre-Norm)
|
| 182 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 183 |
+
|
| 184 |
+
class SwiGLU(nn.Module):
|
| 185 |
+
def __init__(self, dim: int):
|
| 186 |
+
super().__init__()
|
| 187 |
+
# Keep parameter count comparable to regular FFN with dim * 4:
|
| 188 |
+
# 3 * dim * hidden_dim ~= 8 * dim^2 => hidden_dim = 8/3 * dim
|
| 189 |
+
hidden_dim = int(dim * 8 / 3)
|
| 190 |
+
hidden_dim = ((hidden_dim + 7) // 8) * 8
|
| 191 |
+
self.fc1 = nn.Linear(dim, hidden_dim, bias=False)
|
| 192 |
+
self.fc2 = nn.Linear(dim, hidden_dim, bias=False)
|
| 193 |
+
self.fc3 = nn.Linear(hidden_dim, dim, bias=False)
|
| 194 |
+
|
| 195 |
+
def forward(self, x):
|
| 196 |
+
return self.fc3(F.silu(self.fc1(x)) * self.fc2(x))
|
| 197 |
+
|
| 198 |
+
class MSITBranchBlock(nn.Module):
|
| 199 |
+
def __init__(self, dim: int, num_heads: int, window_size):
|
| 200 |
+
super().__init__()
|
| 201 |
+
self.ln1 = nn.LayerNorm(dim)
|
| 202 |
+
self.attn = SlidingWindowAttention(dim, num_heads, window_size)
|
| 203 |
+
self.ln2 = nn.LayerNorm(dim)
|
| 204 |
+
self.ffn = SwiGLU(dim)
|
| 205 |
+
self.ln3 = nn.LayerNorm(dim)
|
| 206 |
+
|
| 207 |
+
def forward(self, x: torch.Tensor,
|
| 208 |
+
past_kv=None,
|
| 209 |
+
use_cache: bool = False,
|
| 210 |
+
bidirectional: bool = False):
|
| 211 |
+
attn_out, present_kv = self.attn(
|
| 212 |
+
self.ln1(x), past_kv, use_cache, bidirectional
|
| 213 |
+
)
|
| 214 |
+
x = x + attn_out
|
| 215 |
+
x = x + self.ffn(self.ln2(x))
|
| 216 |
+
x = self.ln3(x)
|
| 217 |
+
return x, present_kv
|
| 218 |
+
|
| 219 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 220 |
+
# 3. MoEP-MSIT ARCHITECTURE BLOCK (Expert Choice routing)
|
| 221 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 222 |
+
|
| 223 |
+
class MoEPMSITBlock(nn.Module):
|
| 224 |
+
def __init__(self, d_model: int = 512, d_thin: int = 192, num_blocks: int = 14,
|
| 225 |
+
capacity_factor: float = 0.5):
|
| 226 |
+
super().__init__()
|
| 227 |
+
self.d_model = d_model
|
| 228 |
+
self.d_thin = d_thin
|
| 229 |
+
self.num_blocks = num_blocks
|
| 230 |
+
self.capacity_factor = capacity_factor
|
| 231 |
+
|
| 232 |
+
# 1. Global Block (Dense, d_model)
|
| 233 |
+
num_heads_global = max(1, d_model // 64)
|
| 234 |
+
self.global_block = MSITBranchBlock(d_model, num_heads_global, window_size=None)
|
| 235 |
+
|
| 236 |
+
# 2. Router
|
| 237 |
+
self.router_ln = nn.LayerNorm(d_model)
|
| 238 |
+
self.w_router = nn.Linear(d_model, num_blocks, bias=False)
|
| 239 |
+
|
| 240 |
+
# 3. Shrink Projection
|
| 241 |
+
self.w_down = nn.Linear(d_model, d_thin, bias=False)
|
| 242 |
+
|
| 243 |
+
# 4. Thin Parallel Blocks (d_thin)
|
| 244 |
+
self.windows = [64, 16, 8, 4] + [None] * (num_blocks - 4)
|
| 245 |
+
self.heads = [max(1, d_thin // 64)] * num_blocks
|
| 246 |
+
|
| 247 |
+
self.thin_blocks = nn.ModuleList([
|
| 248 |
+
MSITBranchBlock(d_thin, self.heads[i], self.windows[i])
|
| 249 |
+
for i in range(num_blocks)
|
| 250 |
+
])
|
| 251 |
+
|
| 252 |
+
# 6. Grow Projection
|
| 253 |
+
self.w_up = nn.Linear(d_thin, d_model, bias=False)
|
| 254 |
+
self.last_topk_indices = None
|
| 255 |
+
self.ln_post_moe = nn.LayerNorm(d_model)
|
| 256 |
+
|
| 257 |
+
def forward(self, x_0: torch.Tensor, past_kvs=None, use_cache: bool = False, bidirectional: bool = False):
|
| 258 |
+
B, T, D = x_0.size()
|
| 259 |
+
n_tokens = B * T
|
| 260 |
+
|
| 261 |
+
# Step 1: Global Block
|
| 262 |
+
pkv_g = past_kvs[0] if past_kvs else None
|
| 263 |
+
x_1, nkv_g = self.global_block(x_0, pkv_g, use_cache, bidirectional)
|
| 264 |
+
|
| 265 |
+
# Step 2: Gated input stream
|
| 266 |
+
x_2 = x_1
|
| 267 |
+
|
| 268 |
+
# Router scores
|
| 269 |
+
r_logits = self.w_router(self.router_ln(x_2)).view(n_tokens, self.num_blocks)
|
| 270 |
+
r_probs = F.softmax(r_logits, dim=-1)
|
| 271 |
+
|
| 272 |
+
# Per-expert capacity: k = (n * c) / e
|
| 273 |
+
k_capacity = max(1, int(round(n_tokens * self.capacity_factor / self.num_blocks)))
|
| 274 |
+
k_capacity = min(k_capacity, n_tokens)
|
| 275 |
+
|
| 276 |
+
# Expert Choice routing: topk over the token axis for each expert
|
| 277 |
+
expert_token_scores = r_probs.transpose(0, 1) # (num_blocks, n_tokens)
|
| 278 |
+
topk_scores, topk_token_idx = torch.topk(expert_token_scores, k_capacity, dim=-1)
|
| 279 |
+
self.last_topk_indices = topk_token_idx
|
| 280 |
+
|
| 281 |
+
# Load balancing is guaranteed by construction in Expert Choice
|
| 282 |
+
layer_aux_loss = x_2.new_zeros(())
|
| 283 |
+
|
| 284 |
+
# Shrink projection
|
| 285 |
+
x_2_thin = self.w_down(x_2) # (B, T, d_thin)
|
| 286 |
+
x_2_thin_flat = x_2_thin.view(n_tokens, self.d_thin)
|
| 287 |
+
|
| 288 |
+
# Expert computations
|
| 289 |
+
new_kvs = [nkv_g]
|
| 290 |
+
expert_outputs_flat = torch.zeros(n_tokens, self.d_model, device=x_2.device, dtype=x_2.dtype)
|
| 291 |
+
|
| 292 |
+
for i, block in enumerate(self.thin_blocks):
|
| 293 |
+
sel_idx = topk_token_idx[i]
|
| 294 |
+
bucket_in = x_2_thin_flat[sel_idx].unsqueeze(0) # (1, k_capacity, d_thin)
|
| 295 |
+
|
| 296 |
+
pkv_i = past_kvs[i + 1] if past_kvs else None
|
| 297 |
+
bucket_out, nkv_i = block(bucket_in, pkv_i, use_cache, bidirectional)
|
| 298 |
+
if use_cache:
|
| 299 |
+
new_kvs.append(nkv_i)
|
| 300 |
+
|
| 301 |
+
bucket_out = bucket_out.squeeze(0) # (k_capacity, d_thin)
|
| 302 |
+
bucket_out_full = self.w_up(bucket_out) # (k_capacity, d_model)
|
| 303 |
+
|
| 304 |
+
gate = topk_scores[i].unsqueeze(-1) # (k_capacity, 1)
|
| 305 |
+
expert_outputs_flat.index_add_(0, sel_idx, bucket_out_full * gate)
|
| 306 |
+
|
| 307 |
+
x_3_full = expert_outputs_flat.view(B, T, self.d_model)
|
| 308 |
+
out = x_2 + x_3_full
|
| 309 |
+
out = self.ln_post_moe(out)
|
| 310 |
+
|
| 311 |
+
present_kvs = tuple(new_kvs) if use_cache else None
|
| 312 |
+
return out, present_kvs, layer_aux_loss
|
| 313 |
+
|
| 314 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 315 |
+
# 4. RAW XpertGPT MODEL
|
| 316 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 317 |
+
|
| 318 |
+
class XpertGPTModel(nn.Module):
|
| 319 |
+
def __init__(self, cfg):
|
| 320 |
+
super().__init__()
|
| 321 |
+
self.cfg = cfg
|
| 322 |
+
self.wte = nn.Embedding(cfg.vocab_size, cfg.d_model)
|
| 323 |
+
self.drop_emb = nn.Dropout(cfg.dropout)
|
| 324 |
+
self.blocks = nn.ModuleList([
|
| 325 |
+
MoEPMSITBlock(
|
| 326 |
+
d_model=cfg.d_model,
|
| 327 |
+
d_thin=cfg.d_thin,
|
| 328 |
+
num_blocks=cfg.num_blocks,
|
| 329 |
+
capacity_factor=cfg.capacity_factor
|
| 330 |
+
)
|
| 331 |
+
for _ in range(cfg.num_layers)
|
| 332 |
+
])
|
| 333 |
+
self.ln_f = nn.LayerNorm(cfg.d_model)
|
| 334 |
+
self.lm_head = nn.Linear(cfg.d_model, cfg.vocab_size, bias=False)
|
| 335 |
+
self.wte.weight = self.lm_head.weight
|
| 336 |
+
|
| 337 |
+
def forward(self, input_ids: torch.Tensor, targets: torch.Tensor = None, bidirectional: bool = False):
|
| 338 |
+
x = self.drop_emb(self.wte(input_ids))
|
| 339 |
+
total_aux_loss = 0.0
|
| 340 |
+
|
| 341 |
+
for block in self.blocks:
|
| 342 |
+
x, _, layer_aux = block(x, past_kvs=None, use_cache=False, bidirectional=bidirectional)
|
| 343 |
+
total_aux_loss += layer_aux
|
| 344 |
+
|
| 345 |
+
x = self.ln_f(x)
|
| 346 |
+
logits = self.lm_head(x)
|
| 347 |
+
|
| 348 |
+
loss = None
|
| 349 |
+
if targets is not None:
|
| 350 |
+
ce_loss = F.cross_entropy(logits.view(-1, self.cfg.vocab_size), targets.view(-1), ignore_index=-100)
|
| 351 |
+
avg_aux_loss = total_aux_loss / self.cfg.num_layers
|
| 352 |
+
loss = ce_loss + (0.01 * avg_aux_loss)
|
| 353 |
+
|
| 354 |
+
return logits, loss
|
| 355 |
+
|
| 356 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 357 |
+
# 5. HUGGING FACE MODEL WRAPPERS
|
| 358 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 359 |
+
|
| 360 |
+
class XpertGPTModelWrapper(PreTrainedModel):
|
| 361 |
+
config_class = XpertGPTConfig
|
| 362 |
+
base_model_prefix = "transformer"
|
| 363 |
+
|
| 364 |
+
def __init__(self, config: XpertGPTConfig):
|
| 365 |
+
super().__init__(config)
|
| 366 |
+
self.wte = nn.Embedding(config.vocab_size, config.d_model)
|
| 367 |
+
self.drop_emb = nn.Dropout(config.dropout)
|
| 368 |
+
self.blocks = nn.ModuleList([
|
| 369 |
+
MoEPMSITBlock(config.d_model, config.d_thin, config.num_blocks, config.capacity_factor)
|
| 370 |
+
for _ in range(config.num_layers)
|
| 371 |
+
])
|
| 372 |
+
self.ln_f = nn.LayerNorm(config.d_model)
|
| 373 |
+
self.post_init()
|
| 374 |
+
|
| 375 |
+
def forward(self, input_ids, **kwargs):
|
| 376 |
+
x = self.drop_emb(self.wte(input_ids))
|
| 377 |
+
for block in self.blocks:
|
| 378 |
+
x, _, _ = block(x, past_kvs=None, use_cache=False, bidirectional=False)
|
| 379 |
+
x = self.ln_f(x)
|
| 380 |
+
return BaseModelOutputWithPast(last_hidden_state=x)
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
class XpertGPTForCausalLM(PreTrainedModel, GenerationMixin):
|
| 384 |
+
config_class = XpertGPTConfig
|
| 385 |
+
base_model_prefix = "transformer"
|
| 386 |
+
_no_split_modules = ["MoEPMSITBlock"]
|
| 387 |
+
_tied_weights_keys = {"transformer.lm_head.weight": "transformer.wte.weight"}
|
| 388 |
+
|
| 389 |
+
def __init__(self, config: XpertGPTConfig):
|
| 390 |
+
super().__init__(config)
|
| 391 |
+
self.transformer = XpertGPTModelWrapper(config)
|
| 392 |
+
self.lm_head = nn.Linear(config.d_model, config.vocab_size, bias=False)
|
| 393 |
+
self.post_init()
|
| 394 |
+
|
| 395 |
+
# State-dict pre-hook for backwards compatibility with checkpoint key naming
|
| 396 |
+
def _prefix_cleaner(state_dict, prefix, local_metadata, Moore, missing_keys, unexpected_keys, error_msgs):
|
| 397 |
+
keys = list(state_dict.keys())
|
| 398 |
+
for k in keys:
|
| 399 |
+
if k.startswith("transformer."):
|
| 400 |
+
state_dict[k.replace("transformer.", "", 1)] = state_dict.pop(k)
|
| 401 |
+
elif f"{prefix}transformer." in k:
|
| 402 |
+
state_dict[k.replace("transformer.", "", 1)] = state_dict.pop(k)
|
| 403 |
+
|
| 404 |
+
self._register_load_state_dict_pre_hook(_prefix_cleaner)
|
| 405 |
+
|
| 406 |
+
def tie_weights(self, **kwargs):
|
| 407 |
+
if hasattr(self, "transformer") and hasattr(self.transformer, "wte") and hasattr(self.transformer, "lm_head"):
|
| 408 |
+
self.transformer.wte.weight = self.lm_head.weight
|
| 409 |
+
|
| 410 |
+
def get_input_embeddings(self):
|
| 411 |
+
return self.transformer.wte
|
| 412 |
+
|
| 413 |
+
def set_input_embeddings(self, new_embeddings):
|
| 414 |
+
self.transformer.wte = new_embeddings
|
| 415 |
+
|
| 416 |
+
def get_output_embeddings(self):
|
| 417 |
+
return self.lm_head
|
| 418 |
+
|
| 419 |
+
def set_output_embeddings(self, new_embeddings):
|
| 420 |
+
self.lm_head = new_embeddings
|
| 421 |
+
|
| 422 |
+
def forward(self,
|
| 423 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 424 |
+
attention_mask: Optional[torch.FloatTensor] = None,
|
| 425 |
+
labels: Optional[torch.LongTensor] = None,
|
| 426 |
+
**kwargs) -> CausalLMOutputWithPast:
|
| 427 |
+
outputs = self.transformer(input_ids)
|
| 428 |
+
hidden_states = outputs.last_hidden_state
|
| 429 |
+
logits = self.lm_head(hidden_states)
|
| 430 |
+
|
| 431 |
+
loss = None
|
| 432 |
+
if labels is not None:
|
| 433 |
+
shift_logits = logits[:, :-1, :].contiguous()
|
| 434 |
+
shift_labels = labels[:, 1:].contiguous()
|
| 435 |
+
loss = F.cross_entropy(
|
| 436 |
+
shift_logits.view(-1, self.config.vocab_size),
|
| 437 |
+
shift_labels.view(-1),
|
| 438 |
+
ignore_index=-100
|
| 439 |
+
)
|
| 440 |
+
|
| 441 |
+
return CausalLMOutputWithPast(
|
| 442 |
+
loss=loss,
|
| 443 |
+
logits=logits,
|
| 444 |
+
past_key_values=None,
|
| 445 |
+
hidden_states=None,
|
| 446 |
+
attentions=None,
|
| 447 |
+
)
|
| 448 |
+
|
| 449 |
+
def prepare_inputs_for_generation(self, input_ids, **kwargs):
|
| 450 |
+
return {"input_ids": input_ids}
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
# Register with auto-mapping
|
| 454 |
+
AutoConfig.register("xpertgpt", XpertGPTConfig)
|
| 455 |
+
AutoModel.register(XpertGPTConfig, XpertGPTModelWrapper)
|
| 456 |
+
AutoModelForCausalLM.register(XpertGPTConfig, XpertGPTForCausalLM)
|
checkpoints/xpertgpt_fresh/chck_100M/pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e8d879766106dff337673cee6ceb268e706b04faefa2196e4ce93b1f1686e24f
|
| 3 |
+
size 210797423
|
checkpoints/xpertgpt_fresh/chck_100M/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
checkpoints/xpertgpt_fresh/chck_100M/tokenizer_config.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"bos_token": "[CLS]",
|
| 4 |
+
"eos_token": "[SEP]",
|
| 5 |
+
"mask_token": "[MASK]",
|
| 6 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 7 |
+
"pad_token": "[PAD]",
|
| 8 |
+
"tokenizer_class": "TokenizersBackend",
|
| 9 |
+
"unk_token": "[UNK]"
|
| 10 |
+
}
|
checkpoints/xpertgpt_fresh/chck_10M/config.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"auto_map": {
|
| 3 |
+
"AutoConfig": "configuration_xpertgpt.XpertGPTConfig",
|
| 4 |
+
"AutoModel": "modeling_xpertgpt.XpertGPTModelWrapper",
|
| 5 |
+
"AutoModelForCausalLM": "modeling_xpertgpt.XpertGPTForCausalLM"
|
| 6 |
+
},
|
| 7 |
+
"vocab_size": 16384,
|
| 8 |
+
"block_size": 512,
|
| 9 |
+
"d_model": 256,
|
| 10 |
+
"hidden_size": 256,
|
| 11 |
+
"d_thin": 384,
|
| 12 |
+
"num_layers": 6,
|
| 13 |
+
"num_blocks": 4,
|
| 14 |
+
"capacity_factor": 0.5,
|
| 15 |
+
"dropout": 0.1,
|
| 16 |
+
"model_type": "xpertgpt"
|
| 17 |
+
}
|
checkpoints/xpertgpt_fresh/chck_10M/configuration_xpertgpt.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import PretrainedConfig
|
| 2 |
+
|
| 3 |
+
class XpertGPTConfig(PretrainedConfig):
|
| 4 |
+
model_type = "xpertgpt"
|
| 5 |
+
|
| 6 |
+
def __init__(
|
| 7 |
+
self,
|
| 8 |
+
vocab_size: int = 16384,
|
| 9 |
+
block_size: int = 512,
|
| 10 |
+
d_model: int = 256,
|
| 11 |
+
d_thin: int = 384,
|
| 12 |
+
num_layers: int = 6,
|
| 13 |
+
num_blocks: int = 4,
|
| 14 |
+
capacity_factor: float = 0.5,
|
| 15 |
+
dropout: float = 0.1,
|
| 16 |
+
**kwargs
|
| 17 |
+
):
|
| 18 |
+
kwargs.setdefault("is_decoder", True)
|
| 19 |
+
kwargs.setdefault("bos_token_id", 2) # [CLS]
|
| 20 |
+
kwargs.setdefault("eos_token_id", 3) # [SEP]
|
| 21 |
+
kwargs.setdefault("pad_token_id", 1) # [PAD]
|
| 22 |
+
|
| 23 |
+
self.vocab_size = vocab_size
|
| 24 |
+
self.block_size = block_size
|
| 25 |
+
self.d_model = d_model
|
| 26 |
+
self.d_thin = d_thin
|
| 27 |
+
self.num_layers = num_layers
|
| 28 |
+
self.num_blocks = num_blocks
|
| 29 |
+
self.capacity_factor = capacity_factor
|
| 30 |
+
self.dropout = dropout
|
| 31 |
+
|
| 32 |
+
# Attribute parity for classification heads
|
| 33 |
+
self.hidden_size = d_model
|
| 34 |
+
self.num_hidden_layers = num_layers
|
| 35 |
+
|
| 36 |
+
super().__init__(**kwargs)
|
checkpoints/xpertgpt_fresh/chck_10M/modeling_xpertgpt.py
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import math
|
| 3 |
+
import random
|
| 4 |
+
import inspect
|
| 5 |
+
from typing import Optional, Tuple, Dict, Any
|
| 6 |
+
from dataclasses import dataclass
|
| 7 |
+
|
| 8 |
+
import torch
|
| 9 |
+
import torch.nn as nn
|
| 10 |
+
import torch.nn.functional as F
|
| 11 |
+
|
| 12 |
+
from transformers import PretrainedConfig, PreTrainedModel, GenerationMixin, AutoConfig, AutoModel, AutoModelForCausalLM
|
| 13 |
+
from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
|
| 14 |
+
|
| 15 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 16 |
+
# Configuration Classes
|
| 17 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 18 |
+
|
| 19 |
+
@dataclass
|
| 20 |
+
class XpertGPTModelConfig:
|
| 21 |
+
vocab_size: int = 16384
|
| 22 |
+
block_size: int = 512
|
| 23 |
+
d_model: int = 256
|
| 24 |
+
d_thin: int = 384
|
| 25 |
+
num_layers: int = 6
|
| 26 |
+
num_blocks: int = 4
|
| 27 |
+
capacity_factor: float = 0.5
|
| 28 |
+
dropout: float = 0.1
|
| 29 |
+
|
| 30 |
+
class XpertGPTConfig(PretrainedConfig):
|
| 31 |
+
model_type = "xpertgpt"
|
| 32 |
+
auto_map = {
|
| 33 |
+
"AutoConfig": "configuration_xpertgpt.XpertGPTConfig",
|
| 34 |
+
"AutoModel": "modeling_xpertgpt.XpertGPTModelWrapper",
|
| 35 |
+
"AutoModelForCausalLM": "modeling_xpertgpt.XpertGPTForCausalLM"
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
def __init__(
|
| 39 |
+
self,
|
| 40 |
+
vocab_size: int = 16384,
|
| 41 |
+
block_size: int = 512,
|
| 42 |
+
d_model: int = 256,
|
| 43 |
+
d_thin: int = 384,
|
| 44 |
+
num_layers: int = 6,
|
| 45 |
+
num_blocks: int = 4,
|
| 46 |
+
capacity_factor: float = 0.5,
|
| 47 |
+
dropout: float = 0.1,
|
| 48 |
+
**kwargs
|
| 49 |
+
):
|
| 50 |
+
kwargs.setdefault("is_decoder", True)
|
| 51 |
+
kwargs.setdefault("bos_token_id", 2) # [CLS]
|
| 52 |
+
kwargs.setdefault("eos_token_id", 3) # [SEP]
|
| 53 |
+
kwargs.setdefault("pad_token_id", 1) # [PAD]
|
| 54 |
+
|
| 55 |
+
self.vocab_size = vocab_size
|
| 56 |
+
self.block_size = block_size
|
| 57 |
+
self.d_model = d_model
|
| 58 |
+
self.d_thin = d_thin
|
| 59 |
+
self.num_layers = num_layers
|
| 60 |
+
self.num_blocks = num_blocks
|
| 61 |
+
self.capacity_factor = capacity_factor
|
| 62 |
+
self.dropout = dropout
|
| 63 |
+
|
| 64 |
+
# Attribute parity for classification heads
|
| 65 |
+
self.hidden_size = d_model
|
| 66 |
+
self.num_hidden_layers = num_layers
|
| 67 |
+
|
| 68 |
+
super().__init__(**kwargs)
|
| 69 |
+
|
| 70 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 71 |
+
# ROPE HELPERS
|
| 72 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 73 |
+
|
| 74 |
+
def _precompute_rope_freqs(head_dim: int, seq_len: int, device: torch.device, theta: float = 10000.0):
|
| 75 |
+
assert head_dim % 2 == 0, "head_dim must be divisible by 2 for RoPE"
|
| 76 |
+
inv_freq = 1.0 / (theta ** (torch.arange(0, head_dim, 2, device=device).float() / head_dim))
|
| 77 |
+
t = torch.arange(seq_len, device=device).float()
|
| 78 |
+
freqs = torch.outer(t, inv_freq)
|
| 79 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 80 |
+
return emb.cos(), emb.sin()
|
| 81 |
+
|
| 82 |
+
def _apply_rope(x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor):
|
| 83 |
+
L = x.size(2)
|
| 84 |
+
cos = cos[:L, :].unsqueeze(0).unsqueeze(1)
|
| 85 |
+
sin = sin[:L, :].unsqueeze(0).unsqueeze(1)
|
| 86 |
+
|
| 87 |
+
half_dim = x.size(-1) // 2
|
| 88 |
+
x1 = x[..., :half_dim]
|
| 89 |
+
x2 = x[..., half_dim:]
|
| 90 |
+
rotated_x = torch.cat((-x2, x1), dim=-1)
|
| 91 |
+
|
| 92 |
+
return (x * cos) + (rotated_x * sin)
|
| 93 |
+
|
| 94 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 95 |
+
# 1. SLIDING WINDOW ATTENTION
|
| 96 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 97 |
+
|
| 98 |
+
class SlidingWindowAttention(nn.Module):
|
| 99 |
+
def __init__(self, dim: int, num_heads: int, window_size=None):
|
| 100 |
+
super().__init__()
|
| 101 |
+
assert dim % num_heads == 0, "dim must be divisible by num_heads"
|
| 102 |
+
self.num_heads = num_heads
|
| 103 |
+
self.window_size = window_size
|
| 104 |
+
self.head_dim = dim // num_heads
|
| 105 |
+
|
| 106 |
+
self.q_proj = nn.Linear(dim, dim, bias=False)
|
| 107 |
+
self.k_proj = nn.Linear(dim, dim, bias=False)
|
| 108 |
+
self.v_proj = nn.Linear(dim, dim, bias=False)
|
| 109 |
+
self.o_proj = nn.Linear(dim, dim, bias=False)
|
| 110 |
+
|
| 111 |
+
def forward(self, x: torch.Tensor,
|
| 112 |
+
past_kv=None,
|
| 113 |
+
use_cache: bool = False,
|
| 114 |
+
bidirectional: bool = False):
|
| 115 |
+
B, L, D = x.size()
|
| 116 |
+
|
| 117 |
+
q = self.q_proj(x).view(B, L, self.num_heads, self.head_dim).transpose(1, 2)
|
| 118 |
+
k = self.k_proj(x).view(B, L, self.num_heads, self.head_dim).transpose(1, 2)
|
| 119 |
+
v = self.v_proj(x).view(B, L, self.num_heads, self.head_dim).transpose(1, 2)
|
| 120 |
+
|
| 121 |
+
if past_kv is not None:
|
| 122 |
+
past_k, past_v = past_kv
|
| 123 |
+
past_len = past_k.size(2)
|
| 124 |
+
q_cos, q_sin = _precompute_rope_freqs(self.head_dim, past_len + L, x.device)
|
| 125 |
+
q = _apply_rope(q, q_cos[past_len:, :], q_sin[past_len:, :])
|
| 126 |
+
k = _apply_rope(k, q_cos[past_len:, :], q_sin[past_len:, :])
|
| 127 |
+
|
| 128 |
+
k = torch.cat([past_k, k], dim=2)
|
| 129 |
+
v = torch.cat([past_v, v], dim=2)
|
| 130 |
+
else:
|
| 131 |
+
cos, sin = _precompute_rope_freqs(self.head_dim, L, x.device)
|
| 132 |
+
q = _apply_rope(q, cos, sin)
|
| 133 |
+
k = _apply_rope(k, cos, sin)
|
| 134 |
+
|
| 135 |
+
L_kv = k.size(2)
|
| 136 |
+
scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(self.head_dim)
|
| 137 |
+
|
| 138 |
+
if bidirectional:
|
| 139 |
+
if self.window_size is not None:
|
| 140 |
+
past_len = L_kv - L
|
| 141 |
+
pos_i = (past_len + torch.arange(L, device=x.device)).unsqueeze(1)
|
| 142 |
+
pos_j = torch.arange(L_kv, device=x.device).unsqueeze(0)
|
| 143 |
+
dist = torch.abs(pos_i - pos_j)
|
| 144 |
+
win_mask = dist < self.window_size
|
| 145 |
+
scores = scores.masked_fill(
|
| 146 |
+
~win_mask.unsqueeze(0).unsqueeze(0), float('-inf')
|
| 147 |
+
)
|
| 148 |
+
else:
|
| 149 |
+
past_len = L_kv - L
|
| 150 |
+
pos_i = (past_len + torch.arange(L, device=x.device)).unsqueeze(1)
|
| 151 |
+
pos_j = torch.arange(L_kv, device=x.device).unsqueeze(0)
|
| 152 |
+
dist = pos_i - pos_j
|
| 153 |
+
|
| 154 |
+
causal_mask = dist >= 0
|
| 155 |
+
if self.window_size is not None:
|
| 156 |
+
causal_mask = causal_mask & (dist < self.window_size)
|
| 157 |
+
|
| 158 |
+
scores = scores.masked_fill(
|
| 159 |
+
~causal_mask.unsqueeze(0).unsqueeze(0), float('-inf')
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
attn = torch.softmax(scores, dim=-1)
|
| 163 |
+
out = torch.matmul(attn, v)
|
| 164 |
+
out = out.transpose(1, 2).contiguous().view(B, L, D)
|
| 165 |
+
out = self.o_proj(out)
|
| 166 |
+
|
| 167 |
+
if use_cache:
|
| 168 |
+
if self.window_size is not None:
|
| 169 |
+
present_kv = (
|
| 170 |
+
k[:, :, -self.window_size:, :],
|
| 171 |
+
v[:, :, -self.window_size:, :]
|
| 172 |
+
)
|
| 173 |
+
else:
|
| 174 |
+
present_kv = (k, v)
|
| 175 |
+
else:
|
| 176 |
+
present_kv = None
|
| 177 |
+
|
| 178 |
+
return out, present_kv
|
| 179 |
+
|
| 180 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 181 |
+
# 2. MSIT BRANCH BLOCK (Pre-Norm)
|
| 182 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 183 |
+
|
| 184 |
+
class SwiGLU(nn.Module):
|
| 185 |
+
def __init__(self, dim: int):
|
| 186 |
+
super().__init__()
|
| 187 |
+
# Keep parameter count comparable to regular FFN with dim * 4:
|
| 188 |
+
# 3 * dim * hidden_dim ~= 8 * dim^2 => hidden_dim = 8/3 * dim
|
| 189 |
+
hidden_dim = int(dim * 8 / 3)
|
| 190 |
+
hidden_dim = ((hidden_dim + 7) // 8) * 8
|
| 191 |
+
self.fc1 = nn.Linear(dim, hidden_dim, bias=False)
|
| 192 |
+
self.fc2 = nn.Linear(dim, hidden_dim, bias=False)
|
| 193 |
+
self.fc3 = nn.Linear(hidden_dim, dim, bias=False)
|
| 194 |
+
|
| 195 |
+
def forward(self, x):
|
| 196 |
+
return self.fc3(F.silu(self.fc1(x)) * self.fc2(x))
|
| 197 |
+
|
| 198 |
+
class MSITBranchBlock(nn.Module):
|
| 199 |
+
def __init__(self, dim: int, num_heads: int, window_size):
|
| 200 |
+
super().__init__()
|
| 201 |
+
self.ln1 = nn.LayerNorm(dim)
|
| 202 |
+
self.attn = SlidingWindowAttention(dim, num_heads, window_size)
|
| 203 |
+
self.ln2 = nn.LayerNorm(dim)
|
| 204 |
+
self.ffn = SwiGLU(dim)
|
| 205 |
+
self.ln3 = nn.LayerNorm(dim)
|
| 206 |
+
|
| 207 |
+
def forward(self, x: torch.Tensor,
|
| 208 |
+
past_kv=None,
|
| 209 |
+
use_cache: bool = False,
|
| 210 |
+
bidirectional: bool = False):
|
| 211 |
+
attn_out, present_kv = self.attn(
|
| 212 |
+
self.ln1(x), past_kv, use_cache, bidirectional
|
| 213 |
+
)
|
| 214 |
+
x = x + attn_out
|
| 215 |
+
x = x + self.ffn(self.ln2(x))
|
| 216 |
+
x = self.ln3(x)
|
| 217 |
+
return x, present_kv
|
| 218 |
+
|
| 219 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 220 |
+
# 3. MoEP-MSIT ARCHITECTURE BLOCK (Expert Choice routing)
|
| 221 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 222 |
+
|
| 223 |
+
class MoEPMSITBlock(nn.Module):
|
| 224 |
+
def __init__(self, d_model: int = 512, d_thin: int = 192, num_blocks: int = 14,
|
| 225 |
+
capacity_factor: float = 0.5):
|
| 226 |
+
super().__init__()
|
| 227 |
+
self.d_model = d_model
|
| 228 |
+
self.d_thin = d_thin
|
| 229 |
+
self.num_blocks = num_blocks
|
| 230 |
+
self.capacity_factor = capacity_factor
|
| 231 |
+
|
| 232 |
+
# 1. Global Block (Dense, d_model)
|
| 233 |
+
num_heads_global = max(1, d_model // 64)
|
| 234 |
+
self.global_block = MSITBranchBlock(d_model, num_heads_global, window_size=None)
|
| 235 |
+
|
| 236 |
+
# 2. Router
|
| 237 |
+
self.router_ln = nn.LayerNorm(d_model)
|
| 238 |
+
self.w_router = nn.Linear(d_model, num_blocks, bias=False)
|
| 239 |
+
|
| 240 |
+
# 3. Shrink Projection
|
| 241 |
+
self.w_down = nn.Linear(d_model, d_thin, bias=False)
|
| 242 |
+
|
| 243 |
+
# 4. Thin Parallel Blocks (d_thin)
|
| 244 |
+
self.windows = [64, 16, 8, 4] + [None] * (num_blocks - 4)
|
| 245 |
+
self.heads = [max(1, d_thin // 64)] * num_blocks
|
| 246 |
+
|
| 247 |
+
self.thin_blocks = nn.ModuleList([
|
| 248 |
+
MSITBranchBlock(d_thin, self.heads[i], self.windows[i])
|
| 249 |
+
for i in range(num_blocks)
|
| 250 |
+
])
|
| 251 |
+
|
| 252 |
+
# 6. Grow Projection
|
| 253 |
+
self.w_up = nn.Linear(d_thin, d_model, bias=False)
|
| 254 |
+
self.last_topk_indices = None
|
| 255 |
+
self.ln_post_moe = nn.LayerNorm(d_model)
|
| 256 |
+
|
| 257 |
+
def forward(self, x_0: torch.Tensor, past_kvs=None, use_cache: bool = False, bidirectional: bool = False):
|
| 258 |
+
B, T, D = x_0.size()
|
| 259 |
+
n_tokens = B * T
|
| 260 |
+
|
| 261 |
+
# Step 1: Global Block
|
| 262 |
+
pkv_g = past_kvs[0] if past_kvs else None
|
| 263 |
+
x_1, nkv_g = self.global_block(x_0, pkv_g, use_cache, bidirectional)
|
| 264 |
+
|
| 265 |
+
# Step 2: Gated input stream
|
| 266 |
+
x_2 = x_1
|
| 267 |
+
|
| 268 |
+
# Router scores
|
| 269 |
+
r_logits = self.w_router(self.router_ln(x_2)).view(n_tokens, self.num_blocks)
|
| 270 |
+
r_probs = F.softmax(r_logits, dim=-1)
|
| 271 |
+
|
| 272 |
+
# Per-expert capacity: k = (n * c) / e
|
| 273 |
+
k_capacity = max(1, int(round(n_tokens * self.capacity_factor / self.num_blocks)))
|
| 274 |
+
k_capacity = min(k_capacity, n_tokens)
|
| 275 |
+
|
| 276 |
+
# Expert Choice routing: topk over the token axis for each expert
|
| 277 |
+
expert_token_scores = r_probs.transpose(0, 1) # (num_blocks, n_tokens)
|
| 278 |
+
topk_scores, topk_token_idx = torch.topk(expert_token_scores, k_capacity, dim=-1)
|
| 279 |
+
self.last_topk_indices = topk_token_idx
|
| 280 |
+
|
| 281 |
+
# Load balancing is guaranteed by construction in Expert Choice
|
| 282 |
+
layer_aux_loss = x_2.new_zeros(())
|
| 283 |
+
|
| 284 |
+
# Shrink projection
|
| 285 |
+
x_2_thin = self.w_down(x_2) # (B, T, d_thin)
|
| 286 |
+
x_2_thin_flat = x_2_thin.view(n_tokens, self.d_thin)
|
| 287 |
+
|
| 288 |
+
# Expert computations
|
| 289 |
+
new_kvs = [nkv_g]
|
| 290 |
+
expert_outputs_flat = torch.zeros(n_tokens, self.d_model, device=x_2.device, dtype=x_2.dtype)
|
| 291 |
+
|
| 292 |
+
for i, block in enumerate(self.thin_blocks):
|
| 293 |
+
sel_idx = topk_token_idx[i]
|
| 294 |
+
bucket_in = x_2_thin_flat[sel_idx].unsqueeze(0) # (1, k_capacity, d_thin)
|
| 295 |
+
|
| 296 |
+
pkv_i = past_kvs[i + 1] if past_kvs else None
|
| 297 |
+
bucket_out, nkv_i = block(bucket_in, pkv_i, use_cache, bidirectional)
|
| 298 |
+
if use_cache:
|
| 299 |
+
new_kvs.append(nkv_i)
|
| 300 |
+
|
| 301 |
+
bucket_out = bucket_out.squeeze(0) # (k_capacity, d_thin)
|
| 302 |
+
bucket_out_full = self.w_up(bucket_out) # (k_capacity, d_model)
|
| 303 |
+
|
| 304 |
+
gate = topk_scores[i].unsqueeze(-1) # (k_capacity, 1)
|
| 305 |
+
expert_outputs_flat.index_add_(0, sel_idx, bucket_out_full * gate)
|
| 306 |
+
|
| 307 |
+
x_3_full = expert_outputs_flat.view(B, T, self.d_model)
|
| 308 |
+
out = x_2 + x_3_full
|
| 309 |
+
out = self.ln_post_moe(out)
|
| 310 |
+
|
| 311 |
+
present_kvs = tuple(new_kvs) if use_cache else None
|
| 312 |
+
return out, present_kvs, layer_aux_loss
|
| 313 |
+
|
| 314 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 315 |
+
# 4. RAW XpertGPT MODEL
|
| 316 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 317 |
+
|
| 318 |
+
class XpertGPTModel(nn.Module):
|
| 319 |
+
def __init__(self, cfg):
|
| 320 |
+
super().__init__()
|
| 321 |
+
self.cfg = cfg
|
| 322 |
+
self.wte = nn.Embedding(cfg.vocab_size, cfg.d_model)
|
| 323 |
+
self.drop_emb = nn.Dropout(cfg.dropout)
|
| 324 |
+
self.blocks = nn.ModuleList([
|
| 325 |
+
MoEPMSITBlock(
|
| 326 |
+
d_model=cfg.d_model,
|
| 327 |
+
d_thin=cfg.d_thin,
|
| 328 |
+
num_blocks=cfg.num_blocks,
|
| 329 |
+
capacity_factor=cfg.capacity_factor
|
| 330 |
+
)
|
| 331 |
+
for _ in range(cfg.num_layers)
|
| 332 |
+
])
|
| 333 |
+
self.ln_f = nn.LayerNorm(cfg.d_model)
|
| 334 |
+
self.lm_head = nn.Linear(cfg.d_model, cfg.vocab_size, bias=False)
|
| 335 |
+
self.wte.weight = self.lm_head.weight
|
| 336 |
+
|
| 337 |
+
def forward(self, input_ids: torch.Tensor, targets: torch.Tensor = None, bidirectional: bool = False):
|
| 338 |
+
x = self.drop_emb(self.wte(input_ids))
|
| 339 |
+
total_aux_loss = 0.0
|
| 340 |
+
|
| 341 |
+
for block in self.blocks:
|
| 342 |
+
x, _, layer_aux = block(x, past_kvs=None, use_cache=False, bidirectional=bidirectional)
|
| 343 |
+
total_aux_loss += layer_aux
|
| 344 |
+
|
| 345 |
+
x = self.ln_f(x)
|
| 346 |
+
logits = self.lm_head(x)
|
| 347 |
+
|
| 348 |
+
loss = None
|
| 349 |
+
if targets is not None:
|
| 350 |
+
ce_loss = F.cross_entropy(logits.view(-1, self.cfg.vocab_size), targets.view(-1), ignore_index=-100)
|
| 351 |
+
avg_aux_loss = total_aux_loss / self.cfg.num_layers
|
| 352 |
+
loss = ce_loss + (0.01 * avg_aux_loss)
|
| 353 |
+
|
| 354 |
+
return logits, loss
|
| 355 |
+
|
| 356 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 357 |
+
# 5. HUGGING FACE MODEL WRAPPERS
|
| 358 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 359 |
+
|
| 360 |
+
class XpertGPTModelWrapper(PreTrainedModel):
|
| 361 |
+
config_class = XpertGPTConfig
|
| 362 |
+
base_model_prefix = "transformer"
|
| 363 |
+
|
| 364 |
+
def __init__(self, config: XpertGPTConfig):
|
| 365 |
+
super().__init__(config)
|
| 366 |
+
self.wte = nn.Embedding(config.vocab_size, config.d_model)
|
| 367 |
+
self.drop_emb = nn.Dropout(config.dropout)
|
| 368 |
+
self.blocks = nn.ModuleList([
|
| 369 |
+
MoEPMSITBlock(config.d_model, config.d_thin, config.num_blocks, config.capacity_factor)
|
| 370 |
+
for _ in range(config.num_layers)
|
| 371 |
+
])
|
| 372 |
+
self.ln_f = nn.LayerNorm(config.d_model)
|
| 373 |
+
self.post_init()
|
| 374 |
+
|
| 375 |
+
def forward(self, input_ids, **kwargs):
|
| 376 |
+
x = self.drop_emb(self.wte(input_ids))
|
| 377 |
+
for block in self.blocks:
|
| 378 |
+
x, _, _ = block(x, past_kvs=None, use_cache=False, bidirectional=False)
|
| 379 |
+
x = self.ln_f(x)
|
| 380 |
+
return BaseModelOutputWithPast(last_hidden_state=x)
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
class XpertGPTForCausalLM(PreTrainedModel, GenerationMixin):
|
| 384 |
+
config_class = XpertGPTConfig
|
| 385 |
+
base_model_prefix = "transformer"
|
| 386 |
+
_no_split_modules = ["MoEPMSITBlock"]
|
| 387 |
+
_tied_weights_keys = {"transformer.lm_head.weight": "transformer.wte.weight"}
|
| 388 |
+
|
| 389 |
+
def __init__(self, config: XpertGPTConfig):
|
| 390 |
+
super().__init__(config)
|
| 391 |
+
self.transformer = XpertGPTModelWrapper(config)
|
| 392 |
+
self.lm_head = nn.Linear(config.d_model, config.vocab_size, bias=False)
|
| 393 |
+
self.post_init()
|
| 394 |
+
|
| 395 |
+
# State-dict pre-hook for backwards compatibility with checkpoint key naming
|
| 396 |
+
def _prefix_cleaner(state_dict, prefix, local_metadata, Moore, missing_keys, unexpected_keys, error_msgs):
|
| 397 |
+
keys = list(state_dict.keys())
|
| 398 |
+
for k in keys:
|
| 399 |
+
if k.startswith("transformer."):
|
| 400 |
+
state_dict[k.replace("transformer.", "", 1)] = state_dict.pop(k)
|
| 401 |
+
elif f"{prefix}transformer." in k:
|
| 402 |
+
state_dict[k.replace("transformer.", "", 1)] = state_dict.pop(k)
|
| 403 |
+
|
| 404 |
+
self._register_load_state_dict_pre_hook(_prefix_cleaner)
|
| 405 |
+
|
| 406 |
+
def tie_weights(self, **kwargs):
|
| 407 |
+
if hasattr(self, "transformer") and hasattr(self.transformer, "wte") and hasattr(self.transformer, "lm_head"):
|
| 408 |
+
self.transformer.wte.weight = self.lm_head.weight
|
| 409 |
+
|
| 410 |
+
def get_input_embeddings(self):
|
| 411 |
+
return self.transformer.wte
|
| 412 |
+
|
| 413 |
+
def set_input_embeddings(self, new_embeddings):
|
| 414 |
+
self.transformer.wte = new_embeddings
|
| 415 |
+
|
| 416 |
+
def get_output_embeddings(self):
|
| 417 |
+
return self.lm_head
|
| 418 |
+
|
| 419 |
+
def set_output_embeddings(self, new_embeddings):
|
| 420 |
+
self.lm_head = new_embeddings
|
| 421 |
+
|
| 422 |
+
def forward(self,
|
| 423 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 424 |
+
attention_mask: Optional[torch.FloatTensor] = None,
|
| 425 |
+
labels: Optional[torch.LongTensor] = None,
|
| 426 |
+
**kwargs) -> CausalLMOutputWithPast:
|
| 427 |
+
outputs = self.transformer(input_ids)
|
| 428 |
+
hidden_states = outputs.last_hidden_state
|
| 429 |
+
logits = self.lm_head(hidden_states)
|
| 430 |
+
|
| 431 |
+
loss = None
|
| 432 |
+
if labels is not None:
|
| 433 |
+
shift_logits = logits[:, :-1, :].contiguous()
|
| 434 |
+
shift_labels = labels[:, 1:].contiguous()
|
| 435 |
+
loss = F.cross_entropy(
|
| 436 |
+
shift_logits.view(-1, self.config.vocab_size),
|
| 437 |
+
shift_labels.view(-1),
|
| 438 |
+
ignore_index=-100
|
| 439 |
+
)
|
| 440 |
+
|
| 441 |
+
return CausalLMOutputWithPast(
|
| 442 |
+
loss=loss,
|
| 443 |
+
logits=logits,
|
| 444 |
+
past_key_values=None,
|
| 445 |
+
hidden_states=None,
|
| 446 |
+
attentions=None,
|
| 447 |
+
)
|
| 448 |
+
|
| 449 |
+
def prepare_inputs_for_generation(self, input_ids, **kwargs):
|
| 450 |
+
return {"input_ids": input_ids}
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
# Register with auto-mapping
|
| 454 |
+
AutoConfig.register("xpertgpt", XpertGPTConfig)
|
| 455 |
+
AutoModel.register(XpertGPTConfig, XpertGPTModelWrapper)
|
| 456 |
+
AutoModelForCausalLM.register(XpertGPTConfig, XpertGPTForCausalLM)
|
checkpoints/xpertgpt_fresh/chck_10M/pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7cc187eb5c740121cab9a411116f131df4051fafaa43dfebe04293a8b817874a
|
| 3 |
+
size 210797423
|
checkpoints/xpertgpt_fresh/chck_10M/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
checkpoints/xpertgpt_fresh/chck_10M/tokenizer_config.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"bos_token": "[CLS]",
|
| 4 |
+
"eos_token": "[SEP]",
|
| 5 |
+
"mask_token": "[MASK]",
|
| 6 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 7 |
+
"pad_token": "[PAD]",
|
| 8 |
+
"tokenizer_class": "TokenizersBackend",
|
| 9 |
+
"unk_token": "[UNK]"
|
| 10 |
+
}
|
checkpoints/xpertgpt_fresh/chck_1M/config.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"auto_map": {
|
| 3 |
+
"AutoConfig": "configuration_xpertgpt.XpertGPTConfig",
|
| 4 |
+
"AutoModel": "modeling_xpertgpt.XpertGPTModelWrapper",
|
| 5 |
+
"AutoModelForCausalLM": "modeling_xpertgpt.XpertGPTForCausalLM"
|
| 6 |
+
},
|
| 7 |
+
"vocab_size": 16384,
|
| 8 |
+
"block_size": 512,
|
| 9 |
+
"d_model": 256,
|
| 10 |
+
"hidden_size": 256,
|
| 11 |
+
"d_thin": 384,
|
| 12 |
+
"num_layers": 6,
|
| 13 |
+
"num_blocks": 4,
|
| 14 |
+
"capacity_factor": 0.5,
|
| 15 |
+
"dropout": 0.1,
|
| 16 |
+
"model_type": "xpertgpt"
|
| 17 |
+
}
|
checkpoints/xpertgpt_fresh/chck_1M/configuration_xpertgpt.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import PretrainedConfig
|
| 2 |
+
|
| 3 |
+
class XpertGPTConfig(PretrainedConfig):
|
| 4 |
+
model_type = "xpertgpt"
|
| 5 |
+
|
| 6 |
+
def __init__(
|
| 7 |
+
self,
|
| 8 |
+
vocab_size: int = 16384,
|
| 9 |
+
block_size: int = 512,
|
| 10 |
+
d_model: int = 256,
|
| 11 |
+
d_thin: int = 384,
|
| 12 |
+
num_layers: int = 6,
|
| 13 |
+
num_blocks: int = 4,
|
| 14 |
+
capacity_factor: float = 0.5,
|
| 15 |
+
dropout: float = 0.1,
|
| 16 |
+
**kwargs
|
| 17 |
+
):
|
| 18 |
+
kwargs.setdefault("is_decoder", True)
|
| 19 |
+
kwargs.setdefault("bos_token_id", 2) # [CLS]
|
| 20 |
+
kwargs.setdefault("eos_token_id", 3) # [SEP]
|
| 21 |
+
kwargs.setdefault("pad_token_id", 1) # [PAD]
|
| 22 |
+
|
| 23 |
+
self.vocab_size = vocab_size
|
| 24 |
+
self.block_size = block_size
|
| 25 |
+
self.d_model = d_model
|
| 26 |
+
self.d_thin = d_thin
|
| 27 |
+
self.num_layers = num_layers
|
| 28 |
+
self.num_blocks = num_blocks
|
| 29 |
+
self.capacity_factor = capacity_factor
|
| 30 |
+
self.dropout = dropout
|
| 31 |
+
|
| 32 |
+
# Attribute parity for classification heads
|
| 33 |
+
self.hidden_size = d_model
|
| 34 |
+
self.num_hidden_layers = num_layers
|
| 35 |
+
|
| 36 |
+
super().__init__(**kwargs)
|
checkpoints/xpertgpt_fresh/chck_1M/modeling_xpertgpt.py
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import math
|
| 3 |
+
import random
|
| 4 |
+
import inspect
|
| 5 |
+
from typing import Optional, Tuple, Dict, Any
|
| 6 |
+
from dataclasses import dataclass
|
| 7 |
+
|
| 8 |
+
import torch
|
| 9 |
+
import torch.nn as nn
|
| 10 |
+
import torch.nn.functional as F
|
| 11 |
+
|
| 12 |
+
from transformers import PretrainedConfig, PreTrainedModel, GenerationMixin, AutoConfig, AutoModel, AutoModelForCausalLM
|
| 13 |
+
from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
|
| 14 |
+
|
| 15 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 16 |
+
# Configuration Classes
|
| 17 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 18 |
+
|
| 19 |
+
@dataclass
|
| 20 |
+
class XpertGPTModelConfig:
|
| 21 |
+
vocab_size: int = 16384
|
| 22 |
+
block_size: int = 512
|
| 23 |
+
d_model: int = 256
|
| 24 |
+
d_thin: int = 384
|
| 25 |
+
num_layers: int = 6
|
| 26 |
+
num_blocks: int = 4
|
| 27 |
+
capacity_factor: float = 0.5
|
| 28 |
+
dropout: float = 0.1
|
| 29 |
+
|
| 30 |
+
class XpertGPTConfig(PretrainedConfig):
|
| 31 |
+
model_type = "xpertgpt"
|
| 32 |
+
auto_map = {
|
| 33 |
+
"AutoConfig": "configuration_xpertgpt.XpertGPTConfig",
|
| 34 |
+
"AutoModel": "modeling_xpertgpt.XpertGPTModelWrapper",
|
| 35 |
+
"AutoModelForCausalLM": "modeling_xpertgpt.XpertGPTForCausalLM"
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
def __init__(
|
| 39 |
+
self,
|
| 40 |
+
vocab_size: int = 16384,
|
| 41 |
+
block_size: int = 512,
|
| 42 |
+
d_model: int = 256,
|
| 43 |
+
d_thin: int = 384,
|
| 44 |
+
num_layers: int = 6,
|
| 45 |
+
num_blocks: int = 4,
|
| 46 |
+
capacity_factor: float = 0.5,
|
| 47 |
+
dropout: float = 0.1,
|
| 48 |
+
**kwargs
|
| 49 |
+
):
|
| 50 |
+
kwargs.setdefault("is_decoder", True)
|
| 51 |
+
kwargs.setdefault("bos_token_id", 2) # [CLS]
|
| 52 |
+
kwargs.setdefault("eos_token_id", 3) # [SEP]
|
| 53 |
+
kwargs.setdefault("pad_token_id", 1) # [PAD]
|
| 54 |
+
|
| 55 |
+
self.vocab_size = vocab_size
|
| 56 |
+
self.block_size = block_size
|
| 57 |
+
self.d_model = d_model
|
| 58 |
+
self.d_thin = d_thin
|
| 59 |
+
self.num_layers = num_layers
|
| 60 |
+
self.num_blocks = num_blocks
|
| 61 |
+
self.capacity_factor = capacity_factor
|
| 62 |
+
self.dropout = dropout
|
| 63 |
+
|
| 64 |
+
# Attribute parity for classification heads
|
| 65 |
+
self.hidden_size = d_model
|
| 66 |
+
self.num_hidden_layers = num_layers
|
| 67 |
+
|
| 68 |
+
super().__init__(**kwargs)
|
| 69 |
+
|
| 70 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 71 |
+
# ROPE HELPERS
|
| 72 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 73 |
+
|
| 74 |
+
def _precompute_rope_freqs(head_dim: int, seq_len: int, device: torch.device, theta: float = 10000.0):
|
| 75 |
+
assert head_dim % 2 == 0, "head_dim must be divisible by 2 for RoPE"
|
| 76 |
+
inv_freq = 1.0 / (theta ** (torch.arange(0, head_dim, 2, device=device).float() / head_dim))
|
| 77 |
+
t = torch.arange(seq_len, device=device).float()
|
| 78 |
+
freqs = torch.outer(t, inv_freq)
|
| 79 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 80 |
+
return emb.cos(), emb.sin()
|
| 81 |
+
|
| 82 |
+
def _apply_rope(x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor):
|
| 83 |
+
L = x.size(2)
|
| 84 |
+
cos = cos[:L, :].unsqueeze(0).unsqueeze(1)
|
| 85 |
+
sin = sin[:L, :].unsqueeze(0).unsqueeze(1)
|
| 86 |
+
|
| 87 |
+
half_dim = x.size(-1) // 2
|
| 88 |
+
x1 = x[..., :half_dim]
|
| 89 |
+
x2 = x[..., half_dim:]
|
| 90 |
+
rotated_x = torch.cat((-x2, x1), dim=-1)
|
| 91 |
+
|
| 92 |
+
return (x * cos) + (rotated_x * sin)
|
| 93 |
+
|
| 94 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 95 |
+
# 1. SLIDING WINDOW ATTENTION
|
| 96 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 97 |
+
|
| 98 |
+
class SlidingWindowAttention(nn.Module):
|
| 99 |
+
def __init__(self, dim: int, num_heads: int, window_size=None):
|
| 100 |
+
super().__init__()
|
| 101 |
+
assert dim % num_heads == 0, "dim must be divisible by num_heads"
|
| 102 |
+
self.num_heads = num_heads
|
| 103 |
+
self.window_size = window_size
|
| 104 |
+
self.head_dim = dim // num_heads
|
| 105 |
+
|
| 106 |
+
self.q_proj = nn.Linear(dim, dim, bias=False)
|
| 107 |
+
self.k_proj = nn.Linear(dim, dim, bias=False)
|
| 108 |
+
self.v_proj = nn.Linear(dim, dim, bias=False)
|
| 109 |
+
self.o_proj = nn.Linear(dim, dim, bias=False)
|
| 110 |
+
|
| 111 |
+
def forward(self, x: torch.Tensor,
|
| 112 |
+
past_kv=None,
|
| 113 |
+
use_cache: bool = False,
|
| 114 |
+
bidirectional: bool = False):
|
| 115 |
+
B, L, D = x.size()
|
| 116 |
+
|
| 117 |
+
q = self.q_proj(x).view(B, L, self.num_heads, self.head_dim).transpose(1, 2)
|
| 118 |
+
k = self.k_proj(x).view(B, L, self.num_heads, self.head_dim).transpose(1, 2)
|
| 119 |
+
v = self.v_proj(x).view(B, L, self.num_heads, self.head_dim).transpose(1, 2)
|
| 120 |
+
|
| 121 |
+
if past_kv is not None:
|
| 122 |
+
past_k, past_v = past_kv
|
| 123 |
+
past_len = past_k.size(2)
|
| 124 |
+
q_cos, q_sin = _precompute_rope_freqs(self.head_dim, past_len + L, x.device)
|
| 125 |
+
q = _apply_rope(q, q_cos[past_len:, :], q_sin[past_len:, :])
|
| 126 |
+
k = _apply_rope(k, q_cos[past_len:, :], q_sin[past_len:, :])
|
| 127 |
+
|
| 128 |
+
k = torch.cat([past_k, k], dim=2)
|
| 129 |
+
v = torch.cat([past_v, v], dim=2)
|
| 130 |
+
else:
|
| 131 |
+
cos, sin = _precompute_rope_freqs(self.head_dim, L, x.device)
|
| 132 |
+
q = _apply_rope(q, cos, sin)
|
| 133 |
+
k = _apply_rope(k, cos, sin)
|
| 134 |
+
|
| 135 |
+
L_kv = k.size(2)
|
| 136 |
+
scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(self.head_dim)
|
| 137 |
+
|
| 138 |
+
if bidirectional:
|
| 139 |
+
if self.window_size is not None:
|
| 140 |
+
past_len = L_kv - L
|
| 141 |
+
pos_i = (past_len + torch.arange(L, device=x.device)).unsqueeze(1)
|
| 142 |
+
pos_j = torch.arange(L_kv, device=x.device).unsqueeze(0)
|
| 143 |
+
dist = torch.abs(pos_i - pos_j)
|
| 144 |
+
win_mask = dist < self.window_size
|
| 145 |
+
scores = scores.masked_fill(
|
| 146 |
+
~win_mask.unsqueeze(0).unsqueeze(0), float('-inf')
|
| 147 |
+
)
|
| 148 |
+
else:
|
| 149 |
+
past_len = L_kv - L
|
| 150 |
+
pos_i = (past_len + torch.arange(L, device=x.device)).unsqueeze(1)
|
| 151 |
+
pos_j = torch.arange(L_kv, device=x.device).unsqueeze(0)
|
| 152 |
+
dist = pos_i - pos_j
|
| 153 |
+
|
| 154 |
+
causal_mask = dist >= 0
|
| 155 |
+
if self.window_size is not None:
|
| 156 |
+
causal_mask = causal_mask & (dist < self.window_size)
|
| 157 |
+
|
| 158 |
+
scores = scores.masked_fill(
|
| 159 |
+
~causal_mask.unsqueeze(0).unsqueeze(0), float('-inf')
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
attn = torch.softmax(scores, dim=-1)
|
| 163 |
+
out = torch.matmul(attn, v)
|
| 164 |
+
out = out.transpose(1, 2).contiguous().view(B, L, D)
|
| 165 |
+
out = self.o_proj(out)
|
| 166 |
+
|
| 167 |
+
if use_cache:
|
| 168 |
+
if self.window_size is not None:
|
| 169 |
+
present_kv = (
|
| 170 |
+
k[:, :, -self.window_size:, :],
|
| 171 |
+
v[:, :, -self.window_size:, :]
|
| 172 |
+
)
|
| 173 |
+
else:
|
| 174 |
+
present_kv = (k, v)
|
| 175 |
+
else:
|
| 176 |
+
present_kv = None
|
| 177 |
+
|
| 178 |
+
return out, present_kv
|
| 179 |
+
|
| 180 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 181 |
+
# 2. MSIT BRANCH BLOCK (Pre-Norm)
|
| 182 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 183 |
+
|
| 184 |
+
class SwiGLU(nn.Module):
|
| 185 |
+
def __init__(self, dim: int):
|
| 186 |
+
super().__init__()
|
| 187 |
+
# Keep parameter count comparable to regular FFN with dim * 4:
|
| 188 |
+
# 3 * dim * hidden_dim ~= 8 * dim^2 => hidden_dim = 8/3 * dim
|
| 189 |
+
hidden_dim = int(dim * 8 / 3)
|
| 190 |
+
hidden_dim = ((hidden_dim + 7) // 8) * 8
|
| 191 |
+
self.fc1 = nn.Linear(dim, hidden_dim, bias=False)
|
| 192 |
+
self.fc2 = nn.Linear(dim, hidden_dim, bias=False)
|
| 193 |
+
self.fc3 = nn.Linear(hidden_dim, dim, bias=False)
|
| 194 |
+
|
| 195 |
+
def forward(self, x):
|
| 196 |
+
return self.fc3(F.silu(self.fc1(x)) * self.fc2(x))
|
| 197 |
+
|
| 198 |
+
class MSITBranchBlock(nn.Module):
|
| 199 |
+
def __init__(self, dim: int, num_heads: int, window_size):
|
| 200 |
+
super().__init__()
|
| 201 |
+
self.ln1 = nn.LayerNorm(dim)
|
| 202 |
+
self.attn = SlidingWindowAttention(dim, num_heads, window_size)
|
| 203 |
+
self.ln2 = nn.LayerNorm(dim)
|
| 204 |
+
self.ffn = SwiGLU(dim)
|
| 205 |
+
self.ln3 = nn.LayerNorm(dim)
|
| 206 |
+
|
| 207 |
+
def forward(self, x: torch.Tensor,
|
| 208 |
+
past_kv=None,
|
| 209 |
+
use_cache: bool = False,
|
| 210 |
+
bidirectional: bool = False):
|
| 211 |
+
attn_out, present_kv = self.attn(
|
| 212 |
+
self.ln1(x), past_kv, use_cache, bidirectional
|
| 213 |
+
)
|
| 214 |
+
x = x + attn_out
|
| 215 |
+
x = x + self.ffn(self.ln2(x))
|
| 216 |
+
x = self.ln3(x)
|
| 217 |
+
return x, present_kv
|
| 218 |
+
|
| 219 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 220 |
+
# 3. MoEP-MSIT ARCHITECTURE BLOCK (Expert Choice routing)
|
| 221 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 222 |
+
|
| 223 |
+
class MoEPMSITBlock(nn.Module):
|
| 224 |
+
def __init__(self, d_model: int = 512, d_thin: int = 192, num_blocks: int = 14,
|
| 225 |
+
capacity_factor: float = 0.5):
|
| 226 |
+
super().__init__()
|
| 227 |
+
self.d_model = d_model
|
| 228 |
+
self.d_thin = d_thin
|
| 229 |
+
self.num_blocks = num_blocks
|
| 230 |
+
self.capacity_factor = capacity_factor
|
| 231 |
+
|
| 232 |
+
# 1. Global Block (Dense, d_model)
|
| 233 |
+
num_heads_global = max(1, d_model // 64)
|
| 234 |
+
self.global_block = MSITBranchBlock(d_model, num_heads_global, window_size=None)
|
| 235 |
+
|
| 236 |
+
# 2. Router
|
| 237 |
+
self.router_ln = nn.LayerNorm(d_model)
|
| 238 |
+
self.w_router = nn.Linear(d_model, num_blocks, bias=False)
|
| 239 |
+
|
| 240 |
+
# 3. Shrink Projection
|
| 241 |
+
self.w_down = nn.Linear(d_model, d_thin, bias=False)
|
| 242 |
+
|
| 243 |
+
# 4. Thin Parallel Blocks (d_thin)
|
| 244 |
+
self.windows = [64, 16, 8, 4] + [None] * (num_blocks - 4)
|
| 245 |
+
self.heads = [max(1, d_thin // 64)] * num_blocks
|
| 246 |
+
|
| 247 |
+
self.thin_blocks = nn.ModuleList([
|
| 248 |
+
MSITBranchBlock(d_thin, self.heads[i], self.windows[i])
|
| 249 |
+
for i in range(num_blocks)
|
| 250 |
+
])
|
| 251 |
+
|
| 252 |
+
# 6. Grow Projection
|
| 253 |
+
self.w_up = nn.Linear(d_thin, d_model, bias=False)
|
| 254 |
+
self.last_topk_indices = None
|
| 255 |
+
self.ln_post_moe = nn.LayerNorm(d_model)
|
| 256 |
+
|
| 257 |
+
def forward(self, x_0: torch.Tensor, past_kvs=None, use_cache: bool = False, bidirectional: bool = False):
|
| 258 |
+
B, T, D = x_0.size()
|
| 259 |
+
n_tokens = B * T
|
| 260 |
+
|
| 261 |
+
# Step 1: Global Block
|
| 262 |
+
pkv_g = past_kvs[0] if past_kvs else None
|
| 263 |
+
x_1, nkv_g = self.global_block(x_0, pkv_g, use_cache, bidirectional)
|
| 264 |
+
|
| 265 |
+
# Step 2: Gated input stream
|
| 266 |
+
x_2 = x_1
|
| 267 |
+
|
| 268 |
+
# Router scores
|
| 269 |
+
r_logits = self.w_router(self.router_ln(x_2)).view(n_tokens, self.num_blocks)
|
| 270 |
+
r_probs = F.softmax(r_logits, dim=-1)
|
| 271 |
+
|
| 272 |
+
# Per-expert capacity: k = (n * c) / e
|
| 273 |
+
k_capacity = max(1, int(round(n_tokens * self.capacity_factor / self.num_blocks)))
|
| 274 |
+
k_capacity = min(k_capacity, n_tokens)
|
| 275 |
+
|
| 276 |
+
# Expert Choice routing: topk over the token axis for each expert
|
| 277 |
+
expert_token_scores = r_probs.transpose(0, 1) # (num_blocks, n_tokens)
|
| 278 |
+
topk_scores, topk_token_idx = torch.topk(expert_token_scores, k_capacity, dim=-1)
|
| 279 |
+
self.last_topk_indices = topk_token_idx
|
| 280 |
+
|
| 281 |
+
# Load balancing is guaranteed by construction in Expert Choice
|
| 282 |
+
layer_aux_loss = x_2.new_zeros(())
|
| 283 |
+
|
| 284 |
+
# Shrink projection
|
| 285 |
+
x_2_thin = self.w_down(x_2) # (B, T, d_thin)
|
| 286 |
+
x_2_thin_flat = x_2_thin.view(n_tokens, self.d_thin)
|
| 287 |
+
|
| 288 |
+
# Expert computations
|
| 289 |
+
new_kvs = [nkv_g]
|
| 290 |
+
expert_outputs_flat = torch.zeros(n_tokens, self.d_model, device=x_2.device, dtype=x_2.dtype)
|
| 291 |
+
|
| 292 |
+
for i, block in enumerate(self.thin_blocks):
|
| 293 |
+
sel_idx = topk_token_idx[i]
|
| 294 |
+
bucket_in = x_2_thin_flat[sel_idx].unsqueeze(0) # (1, k_capacity, d_thin)
|
| 295 |
+
|
| 296 |
+
pkv_i = past_kvs[i + 1] if past_kvs else None
|
| 297 |
+
bucket_out, nkv_i = block(bucket_in, pkv_i, use_cache, bidirectional)
|
| 298 |
+
if use_cache:
|
| 299 |
+
new_kvs.append(nkv_i)
|
| 300 |
+
|
| 301 |
+
bucket_out = bucket_out.squeeze(0) # (k_capacity, d_thin)
|
| 302 |
+
bucket_out_full = self.w_up(bucket_out) # (k_capacity, d_model)
|
| 303 |
+
|
| 304 |
+
gate = topk_scores[i].unsqueeze(-1) # (k_capacity, 1)
|
| 305 |
+
expert_outputs_flat.index_add_(0, sel_idx, bucket_out_full * gate)
|
| 306 |
+
|
| 307 |
+
x_3_full = expert_outputs_flat.view(B, T, self.d_model)
|
| 308 |
+
out = x_2 + x_3_full
|
| 309 |
+
out = self.ln_post_moe(out)
|
| 310 |
+
|
| 311 |
+
present_kvs = tuple(new_kvs) if use_cache else None
|
| 312 |
+
return out, present_kvs, layer_aux_loss
|
| 313 |
+
|
| 314 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 315 |
+
# 4. RAW XpertGPT MODEL
|
| 316 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 317 |
+
|
| 318 |
+
class XpertGPTModel(nn.Module):
|
| 319 |
+
def __init__(self, cfg):
|
| 320 |
+
super().__init__()
|
| 321 |
+
self.cfg = cfg
|
| 322 |
+
self.wte = nn.Embedding(cfg.vocab_size, cfg.d_model)
|
| 323 |
+
self.drop_emb = nn.Dropout(cfg.dropout)
|
| 324 |
+
self.blocks = nn.ModuleList([
|
| 325 |
+
MoEPMSITBlock(
|
| 326 |
+
d_model=cfg.d_model,
|
| 327 |
+
d_thin=cfg.d_thin,
|
| 328 |
+
num_blocks=cfg.num_blocks,
|
| 329 |
+
capacity_factor=cfg.capacity_factor
|
| 330 |
+
)
|
| 331 |
+
for _ in range(cfg.num_layers)
|
| 332 |
+
])
|
| 333 |
+
self.ln_f = nn.LayerNorm(cfg.d_model)
|
| 334 |
+
self.lm_head = nn.Linear(cfg.d_model, cfg.vocab_size, bias=False)
|
| 335 |
+
self.wte.weight = self.lm_head.weight
|
| 336 |
+
|
| 337 |
+
def forward(self, input_ids: torch.Tensor, targets: torch.Tensor = None, bidirectional: bool = False):
|
| 338 |
+
x = self.drop_emb(self.wte(input_ids))
|
| 339 |
+
total_aux_loss = 0.0
|
| 340 |
+
|
| 341 |
+
for block in self.blocks:
|
| 342 |
+
x, _, layer_aux = block(x, past_kvs=None, use_cache=False, bidirectional=bidirectional)
|
| 343 |
+
total_aux_loss += layer_aux
|
| 344 |
+
|
| 345 |
+
x = self.ln_f(x)
|
| 346 |
+
logits = self.lm_head(x)
|
| 347 |
+
|
| 348 |
+
loss = None
|
| 349 |
+
if targets is not None:
|
| 350 |
+
ce_loss = F.cross_entropy(logits.view(-1, self.cfg.vocab_size), targets.view(-1), ignore_index=-100)
|
| 351 |
+
avg_aux_loss = total_aux_loss / self.cfg.num_layers
|
| 352 |
+
loss = ce_loss + (0.01 * avg_aux_loss)
|
| 353 |
+
|
| 354 |
+
return logits, loss
|
| 355 |
+
|
| 356 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 357 |
+
# 5. HUGGING FACE MODEL WRAPPERS
|
| 358 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 359 |
+
|
| 360 |
+
class XpertGPTModelWrapper(PreTrainedModel):
|
| 361 |
+
config_class = XpertGPTConfig
|
| 362 |
+
base_model_prefix = "transformer"
|
| 363 |
+
|
| 364 |
+
def __init__(self, config: XpertGPTConfig):
|
| 365 |
+
super().__init__(config)
|
| 366 |
+
self.wte = nn.Embedding(config.vocab_size, config.d_model)
|
| 367 |
+
self.drop_emb = nn.Dropout(config.dropout)
|
| 368 |
+
self.blocks = nn.ModuleList([
|
| 369 |
+
MoEPMSITBlock(config.d_model, config.d_thin, config.num_blocks, config.capacity_factor)
|
| 370 |
+
for _ in range(config.num_layers)
|
| 371 |
+
])
|
| 372 |
+
self.ln_f = nn.LayerNorm(config.d_model)
|
| 373 |
+
self.post_init()
|
| 374 |
+
|
| 375 |
+
def forward(self, input_ids, **kwargs):
|
| 376 |
+
x = self.drop_emb(self.wte(input_ids))
|
| 377 |
+
for block in self.blocks:
|
| 378 |
+
x, _, _ = block(x, past_kvs=None, use_cache=False, bidirectional=False)
|
| 379 |
+
x = self.ln_f(x)
|
| 380 |
+
return BaseModelOutputWithPast(last_hidden_state=x)
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
class XpertGPTForCausalLM(PreTrainedModel, GenerationMixin):
|
| 384 |
+
config_class = XpertGPTConfig
|
| 385 |
+
base_model_prefix = "transformer"
|
| 386 |
+
_no_split_modules = ["MoEPMSITBlock"]
|
| 387 |
+
_tied_weights_keys = {"transformer.lm_head.weight": "transformer.wte.weight"}
|
| 388 |
+
|
| 389 |
+
def __init__(self, config: XpertGPTConfig):
|
| 390 |
+
super().__init__(config)
|
| 391 |
+
self.transformer = XpertGPTModelWrapper(config)
|
| 392 |
+
self.lm_head = nn.Linear(config.d_model, config.vocab_size, bias=False)
|
| 393 |
+
self.post_init()
|
| 394 |
+
|
| 395 |
+
# State-dict pre-hook for backwards compatibility with checkpoint key naming
|
| 396 |
+
def _prefix_cleaner(state_dict, prefix, local_metadata, Moore, missing_keys, unexpected_keys, error_msgs):
|
| 397 |
+
keys = list(state_dict.keys())
|
| 398 |
+
for k in keys:
|
| 399 |
+
if k.startswith("transformer."):
|
| 400 |
+
state_dict[k.replace("transformer.", "", 1)] = state_dict.pop(k)
|
| 401 |
+
elif f"{prefix}transformer." in k:
|
| 402 |
+
state_dict[k.replace("transformer.", "", 1)] = state_dict.pop(k)
|
| 403 |
+
|
| 404 |
+
self._register_load_state_dict_pre_hook(_prefix_cleaner)
|
| 405 |
+
|
| 406 |
+
def tie_weights(self, **kwargs):
|
| 407 |
+
if hasattr(self, "transformer") and hasattr(self.transformer, "wte") and hasattr(self.transformer, "lm_head"):
|
| 408 |
+
self.transformer.wte.weight = self.lm_head.weight
|
| 409 |
+
|
| 410 |
+
def get_input_embeddings(self):
|
| 411 |
+
return self.transformer.wte
|
| 412 |
+
|
| 413 |
+
def set_input_embeddings(self, new_embeddings):
|
| 414 |
+
self.transformer.wte = new_embeddings
|
| 415 |
+
|
| 416 |
+
def get_output_embeddings(self):
|
| 417 |
+
return self.lm_head
|
| 418 |
+
|
| 419 |
+
def set_output_embeddings(self, new_embeddings):
|
| 420 |
+
self.lm_head = new_embeddings
|
| 421 |
+
|
| 422 |
+
def forward(self,
|
| 423 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 424 |
+
attention_mask: Optional[torch.FloatTensor] = None,
|
| 425 |
+
labels: Optional[torch.LongTensor] = None,
|
| 426 |
+
**kwargs) -> CausalLMOutputWithPast:
|
| 427 |
+
outputs = self.transformer(input_ids)
|
| 428 |
+
hidden_states = outputs.last_hidden_state
|
| 429 |
+
logits = self.lm_head(hidden_states)
|
| 430 |
+
|
| 431 |
+
loss = None
|
| 432 |
+
if labels is not None:
|
| 433 |
+
shift_logits = logits[:, :-1, :].contiguous()
|
| 434 |
+
shift_labels = labels[:, 1:].contiguous()
|
| 435 |
+
loss = F.cross_entropy(
|
| 436 |
+
shift_logits.view(-1, self.config.vocab_size),
|
| 437 |
+
shift_labels.view(-1),
|
| 438 |
+
ignore_index=-100
|
| 439 |
+
)
|
| 440 |
+
|
| 441 |
+
return CausalLMOutputWithPast(
|
| 442 |
+
loss=loss,
|
| 443 |
+
logits=logits,
|
| 444 |
+
past_key_values=None,
|
| 445 |
+
hidden_states=None,
|
| 446 |
+
attentions=None,
|
| 447 |
+
)
|
| 448 |
+
|
| 449 |
+
def prepare_inputs_for_generation(self, input_ids, **kwargs):
|
| 450 |
+
return {"input_ids": input_ids}
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
# Register with auto-mapping
|
| 454 |
+
AutoConfig.register("xpertgpt", XpertGPTConfig)
|
| 455 |
+
AutoModel.register(XpertGPTConfig, XpertGPTModelWrapper)
|
| 456 |
+
AutoModelForCausalLM.register(XpertGPTConfig, XpertGPTForCausalLM)
|
checkpoints/xpertgpt_fresh/chck_1M/pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:98f17695615310b4faf9d92d2aba05d53e53225a7bc557769520d778b017414b
|
| 3 |
+
size 210797423
|
checkpoints/xpertgpt_fresh/chck_1M/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
checkpoints/xpertgpt_fresh/chck_1M/tokenizer_config.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"bos_token": "[CLS]",
|
| 4 |
+
"eos_token": "[SEP]",
|
| 5 |
+
"mask_token": "[MASK]",
|
| 6 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 7 |
+
"pad_token": "[PAD]",
|
| 8 |
+
"tokenizer_class": "TokenizersBackend",
|
| 9 |
+
"unk_token": "[UNK]"
|
| 10 |
+
}
|
checkpoints/xpertgpt_fresh/chck_20M/config.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"auto_map": {
|
| 3 |
+
"AutoConfig": "configuration_xpertgpt.XpertGPTConfig",
|
| 4 |
+
"AutoModel": "modeling_xpertgpt.XpertGPTModelWrapper",
|
| 5 |
+
"AutoModelForCausalLM": "modeling_xpertgpt.XpertGPTForCausalLM"
|
| 6 |
+
},
|
| 7 |
+
"vocab_size": 16384,
|
| 8 |
+
"block_size": 512,
|
| 9 |
+
"d_model": 256,
|
| 10 |
+
"hidden_size": 256,
|
| 11 |
+
"d_thin": 384,
|
| 12 |
+
"num_layers": 6,
|
| 13 |
+
"num_blocks": 4,
|
| 14 |
+
"capacity_factor": 0.5,
|
| 15 |
+
"dropout": 0.1,
|
| 16 |
+
"model_type": "xpertgpt"
|
| 17 |
+
}
|
checkpoints/xpertgpt_fresh/chck_20M/configuration_xpertgpt.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import PretrainedConfig
|
| 2 |
+
|
| 3 |
+
class XpertGPTConfig(PretrainedConfig):
|
| 4 |
+
model_type = "xpertgpt"
|
| 5 |
+
|
| 6 |
+
def __init__(
|
| 7 |
+
self,
|
| 8 |
+
vocab_size: int = 16384,
|
| 9 |
+
block_size: int = 512,
|
| 10 |
+
d_model: int = 256,
|
| 11 |
+
d_thin: int = 384,
|
| 12 |
+
num_layers: int = 6,
|
| 13 |
+
num_blocks: int = 4,
|
| 14 |
+
capacity_factor: float = 0.5,
|
| 15 |
+
dropout: float = 0.1,
|
| 16 |
+
**kwargs
|
| 17 |
+
):
|
| 18 |
+
kwargs.setdefault("is_decoder", True)
|
| 19 |
+
kwargs.setdefault("bos_token_id", 2) # [CLS]
|
| 20 |
+
kwargs.setdefault("eos_token_id", 3) # [SEP]
|
| 21 |
+
kwargs.setdefault("pad_token_id", 1) # [PAD]
|
| 22 |
+
|
| 23 |
+
self.vocab_size = vocab_size
|
| 24 |
+
self.block_size = block_size
|
| 25 |
+
self.d_model = d_model
|
| 26 |
+
self.d_thin = d_thin
|
| 27 |
+
self.num_layers = num_layers
|
| 28 |
+
self.num_blocks = num_blocks
|
| 29 |
+
self.capacity_factor = capacity_factor
|
| 30 |
+
self.dropout = dropout
|
| 31 |
+
|
| 32 |
+
# Attribute parity for classification heads
|
| 33 |
+
self.hidden_size = d_model
|
| 34 |
+
self.num_hidden_layers = num_layers
|
| 35 |
+
|
| 36 |
+
super().__init__(**kwargs)
|
checkpoints/xpertgpt_fresh/chck_20M/modeling_xpertgpt.py
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import math
|
| 3 |
+
import random
|
| 4 |
+
import inspect
|
| 5 |
+
from typing import Optional, Tuple, Dict, Any
|
| 6 |
+
from dataclasses import dataclass
|
| 7 |
+
|
| 8 |
+
import torch
|
| 9 |
+
import torch.nn as nn
|
| 10 |
+
import torch.nn.functional as F
|
| 11 |
+
|
| 12 |
+
from transformers import PretrainedConfig, PreTrainedModel, GenerationMixin, AutoConfig, AutoModel, AutoModelForCausalLM
|
| 13 |
+
from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
|
| 14 |
+
|
| 15 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 16 |
+
# Configuration Classes
|
| 17 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 18 |
+
|
| 19 |
+
@dataclass
|
| 20 |
+
class XpertGPTModelConfig:
|
| 21 |
+
vocab_size: int = 16384
|
| 22 |
+
block_size: int = 512
|
| 23 |
+
d_model: int = 256
|
| 24 |
+
d_thin: int = 384
|
| 25 |
+
num_layers: int = 6
|
| 26 |
+
num_blocks: int = 4
|
| 27 |
+
capacity_factor: float = 0.5
|
| 28 |
+
dropout: float = 0.1
|
| 29 |
+
|
| 30 |
+
class XpertGPTConfig(PretrainedConfig):
|
| 31 |
+
model_type = "xpertgpt"
|
| 32 |
+
auto_map = {
|
| 33 |
+
"AutoConfig": "configuration_xpertgpt.XpertGPTConfig",
|
| 34 |
+
"AutoModel": "modeling_xpertgpt.XpertGPTModelWrapper",
|
| 35 |
+
"AutoModelForCausalLM": "modeling_xpertgpt.XpertGPTForCausalLM"
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
def __init__(
|
| 39 |
+
self,
|
| 40 |
+
vocab_size: int = 16384,
|
| 41 |
+
block_size: int = 512,
|
| 42 |
+
d_model: int = 256,
|
| 43 |
+
d_thin: int = 384,
|
| 44 |
+
num_layers: int = 6,
|
| 45 |
+
num_blocks: int = 4,
|
| 46 |
+
capacity_factor: float = 0.5,
|
| 47 |
+
dropout: float = 0.1,
|
| 48 |
+
**kwargs
|
| 49 |
+
):
|
| 50 |
+
kwargs.setdefault("is_decoder", True)
|
| 51 |
+
kwargs.setdefault("bos_token_id", 2) # [CLS]
|
| 52 |
+
kwargs.setdefault("eos_token_id", 3) # [SEP]
|
| 53 |
+
kwargs.setdefault("pad_token_id", 1) # [PAD]
|
| 54 |
+
|
| 55 |
+
self.vocab_size = vocab_size
|
| 56 |
+
self.block_size = block_size
|
| 57 |
+
self.d_model = d_model
|
| 58 |
+
self.d_thin = d_thin
|
| 59 |
+
self.num_layers = num_layers
|
| 60 |
+
self.num_blocks = num_blocks
|
| 61 |
+
self.capacity_factor = capacity_factor
|
| 62 |
+
self.dropout = dropout
|
| 63 |
+
|
| 64 |
+
# Attribute parity for classification heads
|
| 65 |
+
self.hidden_size = d_model
|
| 66 |
+
self.num_hidden_layers = num_layers
|
| 67 |
+
|
| 68 |
+
super().__init__(**kwargs)
|
| 69 |
+
|
| 70 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 71 |
+
# ROPE HELPERS
|
| 72 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 73 |
+
|
| 74 |
+
def _precompute_rope_freqs(head_dim: int, seq_len: int, device: torch.device, theta: float = 10000.0):
|
| 75 |
+
assert head_dim % 2 == 0, "head_dim must be divisible by 2 for RoPE"
|
| 76 |
+
inv_freq = 1.0 / (theta ** (torch.arange(0, head_dim, 2, device=device).float() / head_dim))
|
| 77 |
+
t = torch.arange(seq_len, device=device).float()
|
| 78 |
+
freqs = torch.outer(t, inv_freq)
|
| 79 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 80 |
+
return emb.cos(), emb.sin()
|
| 81 |
+
|
| 82 |
+
def _apply_rope(x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor):
|
| 83 |
+
L = x.size(2)
|
| 84 |
+
cos = cos[:L, :].unsqueeze(0).unsqueeze(1)
|
| 85 |
+
sin = sin[:L, :].unsqueeze(0).unsqueeze(1)
|
| 86 |
+
|
| 87 |
+
half_dim = x.size(-1) // 2
|
| 88 |
+
x1 = x[..., :half_dim]
|
| 89 |
+
x2 = x[..., half_dim:]
|
| 90 |
+
rotated_x = torch.cat((-x2, x1), dim=-1)
|
| 91 |
+
|
| 92 |
+
return (x * cos) + (rotated_x * sin)
|
| 93 |
+
|
| 94 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 95 |
+
# 1. SLIDING WINDOW ATTENTION
|
| 96 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 97 |
+
|
| 98 |
+
class SlidingWindowAttention(nn.Module):
|
| 99 |
+
def __init__(self, dim: int, num_heads: int, window_size=None):
|
| 100 |
+
super().__init__()
|
| 101 |
+
assert dim % num_heads == 0, "dim must be divisible by num_heads"
|
| 102 |
+
self.num_heads = num_heads
|
| 103 |
+
self.window_size = window_size
|
| 104 |
+
self.head_dim = dim // num_heads
|
| 105 |
+
|
| 106 |
+
self.q_proj = nn.Linear(dim, dim, bias=False)
|
| 107 |
+
self.k_proj = nn.Linear(dim, dim, bias=False)
|
| 108 |
+
self.v_proj = nn.Linear(dim, dim, bias=False)
|
| 109 |
+
self.o_proj = nn.Linear(dim, dim, bias=False)
|
| 110 |
+
|
| 111 |
+
def forward(self, x: torch.Tensor,
|
| 112 |
+
past_kv=None,
|
| 113 |
+
use_cache: bool = False,
|
| 114 |
+
bidirectional: bool = False):
|
| 115 |
+
B, L, D = x.size()
|
| 116 |
+
|
| 117 |
+
q = self.q_proj(x).view(B, L, self.num_heads, self.head_dim).transpose(1, 2)
|
| 118 |
+
k = self.k_proj(x).view(B, L, self.num_heads, self.head_dim).transpose(1, 2)
|
| 119 |
+
v = self.v_proj(x).view(B, L, self.num_heads, self.head_dim).transpose(1, 2)
|
| 120 |
+
|
| 121 |
+
if past_kv is not None:
|
| 122 |
+
past_k, past_v = past_kv
|
| 123 |
+
past_len = past_k.size(2)
|
| 124 |
+
q_cos, q_sin = _precompute_rope_freqs(self.head_dim, past_len + L, x.device)
|
| 125 |
+
q = _apply_rope(q, q_cos[past_len:, :], q_sin[past_len:, :])
|
| 126 |
+
k = _apply_rope(k, q_cos[past_len:, :], q_sin[past_len:, :])
|
| 127 |
+
|
| 128 |
+
k = torch.cat([past_k, k], dim=2)
|
| 129 |
+
v = torch.cat([past_v, v], dim=2)
|
| 130 |
+
else:
|
| 131 |
+
cos, sin = _precompute_rope_freqs(self.head_dim, L, x.device)
|
| 132 |
+
q = _apply_rope(q, cos, sin)
|
| 133 |
+
k = _apply_rope(k, cos, sin)
|
| 134 |
+
|
| 135 |
+
L_kv = k.size(2)
|
| 136 |
+
scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(self.head_dim)
|
| 137 |
+
|
| 138 |
+
if bidirectional:
|
| 139 |
+
if self.window_size is not None:
|
| 140 |
+
past_len = L_kv - L
|
| 141 |
+
pos_i = (past_len + torch.arange(L, device=x.device)).unsqueeze(1)
|
| 142 |
+
pos_j = torch.arange(L_kv, device=x.device).unsqueeze(0)
|
| 143 |
+
dist = torch.abs(pos_i - pos_j)
|
| 144 |
+
win_mask = dist < self.window_size
|
| 145 |
+
scores = scores.masked_fill(
|
| 146 |
+
~win_mask.unsqueeze(0).unsqueeze(0), float('-inf')
|
| 147 |
+
)
|
| 148 |
+
else:
|
| 149 |
+
past_len = L_kv - L
|
| 150 |
+
pos_i = (past_len + torch.arange(L, device=x.device)).unsqueeze(1)
|
| 151 |
+
pos_j = torch.arange(L_kv, device=x.device).unsqueeze(0)
|
| 152 |
+
dist = pos_i - pos_j
|
| 153 |
+
|
| 154 |
+
causal_mask = dist >= 0
|
| 155 |
+
if self.window_size is not None:
|
| 156 |
+
causal_mask = causal_mask & (dist < self.window_size)
|
| 157 |
+
|
| 158 |
+
scores = scores.masked_fill(
|
| 159 |
+
~causal_mask.unsqueeze(0).unsqueeze(0), float('-inf')
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
attn = torch.softmax(scores, dim=-1)
|
| 163 |
+
out = torch.matmul(attn, v)
|
| 164 |
+
out = out.transpose(1, 2).contiguous().view(B, L, D)
|
| 165 |
+
out = self.o_proj(out)
|
| 166 |
+
|
| 167 |
+
if use_cache:
|
| 168 |
+
if self.window_size is not None:
|
| 169 |
+
present_kv = (
|
| 170 |
+
k[:, :, -self.window_size:, :],
|
| 171 |
+
v[:, :, -self.window_size:, :]
|
| 172 |
+
)
|
| 173 |
+
else:
|
| 174 |
+
present_kv = (k, v)
|
| 175 |
+
else:
|
| 176 |
+
present_kv = None
|
| 177 |
+
|
| 178 |
+
return out, present_kv
|
| 179 |
+
|
| 180 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 181 |
+
# 2. MSIT BRANCH BLOCK (Pre-Norm)
|
| 182 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 183 |
+
|
| 184 |
+
class SwiGLU(nn.Module):
|
| 185 |
+
def __init__(self, dim: int):
|
| 186 |
+
super().__init__()
|
| 187 |
+
# Keep parameter count comparable to regular FFN with dim * 4:
|
| 188 |
+
# 3 * dim * hidden_dim ~= 8 * dim^2 => hidden_dim = 8/3 * dim
|
| 189 |
+
hidden_dim = int(dim * 8 / 3)
|
| 190 |
+
hidden_dim = ((hidden_dim + 7) // 8) * 8
|
| 191 |
+
self.fc1 = nn.Linear(dim, hidden_dim, bias=False)
|
| 192 |
+
self.fc2 = nn.Linear(dim, hidden_dim, bias=False)
|
| 193 |
+
self.fc3 = nn.Linear(hidden_dim, dim, bias=False)
|
| 194 |
+
|
| 195 |
+
def forward(self, x):
|
| 196 |
+
return self.fc3(F.silu(self.fc1(x)) * self.fc2(x))
|
| 197 |
+
|
| 198 |
+
class MSITBranchBlock(nn.Module):
|
| 199 |
+
def __init__(self, dim: int, num_heads: int, window_size):
|
| 200 |
+
super().__init__()
|
| 201 |
+
self.ln1 = nn.LayerNorm(dim)
|
| 202 |
+
self.attn = SlidingWindowAttention(dim, num_heads, window_size)
|
| 203 |
+
self.ln2 = nn.LayerNorm(dim)
|
| 204 |
+
self.ffn = SwiGLU(dim)
|
| 205 |
+
self.ln3 = nn.LayerNorm(dim)
|
| 206 |
+
|
| 207 |
+
def forward(self, x: torch.Tensor,
|
| 208 |
+
past_kv=None,
|
| 209 |
+
use_cache: bool = False,
|
| 210 |
+
bidirectional: bool = False):
|
| 211 |
+
attn_out, present_kv = self.attn(
|
| 212 |
+
self.ln1(x), past_kv, use_cache, bidirectional
|
| 213 |
+
)
|
| 214 |
+
x = x + attn_out
|
| 215 |
+
x = x + self.ffn(self.ln2(x))
|
| 216 |
+
x = self.ln3(x)
|
| 217 |
+
return x, present_kv
|
| 218 |
+
|
| 219 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 220 |
+
# 3. MoEP-MSIT ARCHITECTURE BLOCK (Expert Choice routing)
|
| 221 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 222 |
+
|
| 223 |
+
class MoEPMSITBlock(nn.Module):
|
| 224 |
+
def __init__(self, d_model: int = 512, d_thin: int = 192, num_blocks: int = 14,
|
| 225 |
+
capacity_factor: float = 0.5):
|
| 226 |
+
super().__init__()
|
| 227 |
+
self.d_model = d_model
|
| 228 |
+
self.d_thin = d_thin
|
| 229 |
+
self.num_blocks = num_blocks
|
| 230 |
+
self.capacity_factor = capacity_factor
|
| 231 |
+
|
| 232 |
+
# 1. Global Block (Dense, d_model)
|
| 233 |
+
num_heads_global = max(1, d_model // 64)
|
| 234 |
+
self.global_block = MSITBranchBlock(d_model, num_heads_global, window_size=None)
|
| 235 |
+
|
| 236 |
+
# 2. Router
|
| 237 |
+
self.router_ln = nn.LayerNorm(d_model)
|
| 238 |
+
self.w_router = nn.Linear(d_model, num_blocks, bias=False)
|
| 239 |
+
|
| 240 |
+
# 3. Shrink Projection
|
| 241 |
+
self.w_down = nn.Linear(d_model, d_thin, bias=False)
|
| 242 |
+
|
| 243 |
+
# 4. Thin Parallel Blocks (d_thin)
|
| 244 |
+
self.windows = [64, 16, 8, 4] + [None] * (num_blocks - 4)
|
| 245 |
+
self.heads = [max(1, d_thin // 64)] * num_blocks
|
| 246 |
+
|
| 247 |
+
self.thin_blocks = nn.ModuleList([
|
| 248 |
+
MSITBranchBlock(d_thin, self.heads[i], self.windows[i])
|
| 249 |
+
for i in range(num_blocks)
|
| 250 |
+
])
|
| 251 |
+
|
| 252 |
+
# 6. Grow Projection
|
| 253 |
+
self.w_up = nn.Linear(d_thin, d_model, bias=False)
|
| 254 |
+
self.last_topk_indices = None
|
| 255 |
+
self.ln_post_moe = nn.LayerNorm(d_model)
|
| 256 |
+
|
| 257 |
+
def forward(self, x_0: torch.Tensor, past_kvs=None, use_cache: bool = False, bidirectional: bool = False):
|
| 258 |
+
B, T, D = x_0.size()
|
| 259 |
+
n_tokens = B * T
|
| 260 |
+
|
| 261 |
+
# Step 1: Global Block
|
| 262 |
+
pkv_g = past_kvs[0] if past_kvs else None
|
| 263 |
+
x_1, nkv_g = self.global_block(x_0, pkv_g, use_cache, bidirectional)
|
| 264 |
+
|
| 265 |
+
# Step 2: Gated input stream
|
| 266 |
+
x_2 = x_1
|
| 267 |
+
|
| 268 |
+
# Router scores
|
| 269 |
+
r_logits = self.w_router(self.router_ln(x_2)).view(n_tokens, self.num_blocks)
|
| 270 |
+
r_probs = F.softmax(r_logits, dim=-1)
|
| 271 |
+
|
| 272 |
+
# Per-expert capacity: k = (n * c) / e
|
| 273 |
+
k_capacity = max(1, int(round(n_tokens * self.capacity_factor / self.num_blocks)))
|
| 274 |
+
k_capacity = min(k_capacity, n_tokens)
|
| 275 |
+
|
| 276 |
+
# Expert Choice routing: topk over the token axis for each expert
|
| 277 |
+
expert_token_scores = r_probs.transpose(0, 1) # (num_blocks, n_tokens)
|
| 278 |
+
topk_scores, topk_token_idx = torch.topk(expert_token_scores, k_capacity, dim=-1)
|
| 279 |
+
self.last_topk_indices = topk_token_idx
|
| 280 |
+
|
| 281 |
+
# Load balancing is guaranteed by construction in Expert Choice
|
| 282 |
+
layer_aux_loss = x_2.new_zeros(())
|
| 283 |
+
|
| 284 |
+
# Shrink projection
|
| 285 |
+
x_2_thin = self.w_down(x_2) # (B, T, d_thin)
|
| 286 |
+
x_2_thin_flat = x_2_thin.view(n_tokens, self.d_thin)
|
| 287 |
+
|
| 288 |
+
# Expert computations
|
| 289 |
+
new_kvs = [nkv_g]
|
| 290 |
+
expert_outputs_flat = torch.zeros(n_tokens, self.d_model, device=x_2.device, dtype=x_2.dtype)
|
| 291 |
+
|
| 292 |
+
for i, block in enumerate(self.thin_blocks):
|
| 293 |
+
sel_idx = topk_token_idx[i]
|
| 294 |
+
bucket_in = x_2_thin_flat[sel_idx].unsqueeze(0) # (1, k_capacity, d_thin)
|
| 295 |
+
|
| 296 |
+
pkv_i = past_kvs[i + 1] if past_kvs else None
|
| 297 |
+
bucket_out, nkv_i = block(bucket_in, pkv_i, use_cache, bidirectional)
|
| 298 |
+
if use_cache:
|
| 299 |
+
new_kvs.append(nkv_i)
|
| 300 |
+
|
| 301 |
+
bucket_out = bucket_out.squeeze(0) # (k_capacity, d_thin)
|
| 302 |
+
bucket_out_full = self.w_up(bucket_out) # (k_capacity, d_model)
|
| 303 |
+
|
| 304 |
+
gate = topk_scores[i].unsqueeze(-1) # (k_capacity, 1)
|
| 305 |
+
expert_outputs_flat.index_add_(0, sel_idx, bucket_out_full * gate)
|
| 306 |
+
|
| 307 |
+
x_3_full = expert_outputs_flat.view(B, T, self.d_model)
|
| 308 |
+
out = x_2 + x_3_full
|
| 309 |
+
out = self.ln_post_moe(out)
|
| 310 |
+
|
| 311 |
+
present_kvs = tuple(new_kvs) if use_cache else None
|
| 312 |
+
return out, present_kvs, layer_aux_loss
|
| 313 |
+
|
| 314 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 315 |
+
# 4. RAW XpertGPT MODEL
|
| 316 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 317 |
+
|
| 318 |
+
class XpertGPTModel(nn.Module):
|
| 319 |
+
def __init__(self, cfg):
|
| 320 |
+
super().__init__()
|
| 321 |
+
self.cfg = cfg
|
| 322 |
+
self.wte = nn.Embedding(cfg.vocab_size, cfg.d_model)
|
| 323 |
+
self.drop_emb = nn.Dropout(cfg.dropout)
|
| 324 |
+
self.blocks = nn.ModuleList([
|
| 325 |
+
MoEPMSITBlock(
|
| 326 |
+
d_model=cfg.d_model,
|
| 327 |
+
d_thin=cfg.d_thin,
|
| 328 |
+
num_blocks=cfg.num_blocks,
|
| 329 |
+
capacity_factor=cfg.capacity_factor
|
| 330 |
+
)
|
| 331 |
+
for _ in range(cfg.num_layers)
|
| 332 |
+
])
|
| 333 |
+
self.ln_f = nn.LayerNorm(cfg.d_model)
|
| 334 |
+
self.lm_head = nn.Linear(cfg.d_model, cfg.vocab_size, bias=False)
|
| 335 |
+
self.wte.weight = self.lm_head.weight
|
| 336 |
+
|
| 337 |
+
def forward(self, input_ids: torch.Tensor, targets: torch.Tensor = None, bidirectional: bool = False):
|
| 338 |
+
x = self.drop_emb(self.wte(input_ids))
|
| 339 |
+
total_aux_loss = 0.0
|
| 340 |
+
|
| 341 |
+
for block in self.blocks:
|
| 342 |
+
x, _, layer_aux = block(x, past_kvs=None, use_cache=False, bidirectional=bidirectional)
|
| 343 |
+
total_aux_loss += layer_aux
|
| 344 |
+
|
| 345 |
+
x = self.ln_f(x)
|
| 346 |
+
logits = self.lm_head(x)
|
| 347 |
+
|
| 348 |
+
loss = None
|
| 349 |
+
if targets is not None:
|
| 350 |
+
ce_loss = F.cross_entropy(logits.view(-1, self.cfg.vocab_size), targets.view(-1), ignore_index=-100)
|
| 351 |
+
avg_aux_loss = total_aux_loss / self.cfg.num_layers
|
| 352 |
+
loss = ce_loss + (0.01 * avg_aux_loss)
|
| 353 |
+
|
| 354 |
+
return logits, loss
|
| 355 |
+
|
| 356 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 357 |
+
# 5. HUGGING FACE MODEL WRAPPERS
|
| 358 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 359 |
+
|
| 360 |
+
class XpertGPTModelWrapper(PreTrainedModel):
|
| 361 |
+
config_class = XpertGPTConfig
|
| 362 |
+
base_model_prefix = "transformer"
|
| 363 |
+
|
| 364 |
+
def __init__(self, config: XpertGPTConfig):
|
| 365 |
+
super().__init__(config)
|
| 366 |
+
self.wte = nn.Embedding(config.vocab_size, config.d_model)
|
| 367 |
+
self.drop_emb = nn.Dropout(config.dropout)
|
| 368 |
+
self.blocks = nn.ModuleList([
|
| 369 |
+
MoEPMSITBlock(config.d_model, config.d_thin, config.num_blocks, config.capacity_factor)
|
| 370 |
+
for _ in range(config.num_layers)
|
| 371 |
+
])
|
| 372 |
+
self.ln_f = nn.LayerNorm(config.d_model)
|
| 373 |
+
self.post_init()
|
| 374 |
+
|
| 375 |
+
def forward(self, input_ids, **kwargs):
|
| 376 |
+
x = self.drop_emb(self.wte(input_ids))
|
| 377 |
+
for block in self.blocks:
|
| 378 |
+
x, _, _ = block(x, past_kvs=None, use_cache=False, bidirectional=False)
|
| 379 |
+
x = self.ln_f(x)
|
| 380 |
+
return BaseModelOutputWithPast(last_hidden_state=x)
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
class XpertGPTForCausalLM(PreTrainedModel, GenerationMixin):
|
| 384 |
+
config_class = XpertGPTConfig
|
| 385 |
+
base_model_prefix = "transformer"
|
| 386 |
+
_no_split_modules = ["MoEPMSITBlock"]
|
| 387 |
+
_tied_weights_keys = {"transformer.lm_head.weight": "transformer.wte.weight"}
|
| 388 |
+
|
| 389 |
+
def __init__(self, config: XpertGPTConfig):
|
| 390 |
+
super().__init__(config)
|
| 391 |
+
self.transformer = XpertGPTModelWrapper(config)
|
| 392 |
+
self.lm_head = nn.Linear(config.d_model, config.vocab_size, bias=False)
|
| 393 |
+
self.post_init()
|
| 394 |
+
|
| 395 |
+
# State-dict pre-hook for backwards compatibility with checkpoint key naming
|
| 396 |
+
def _prefix_cleaner(state_dict, prefix, local_metadata, Moore, missing_keys, unexpected_keys, error_msgs):
|
| 397 |
+
keys = list(state_dict.keys())
|
| 398 |
+
for k in keys:
|
| 399 |
+
if k.startswith("transformer."):
|
| 400 |
+
state_dict[k.replace("transformer.", "", 1)] = state_dict.pop(k)
|
| 401 |
+
elif f"{prefix}transformer." in k:
|
| 402 |
+
state_dict[k.replace("transformer.", "", 1)] = state_dict.pop(k)
|
| 403 |
+
|
| 404 |
+
self._register_load_state_dict_pre_hook(_prefix_cleaner)
|
| 405 |
+
|
| 406 |
+
def tie_weights(self, **kwargs):
|
| 407 |
+
if hasattr(self, "transformer") and hasattr(self.transformer, "wte") and hasattr(self.transformer, "lm_head"):
|
| 408 |
+
self.transformer.wte.weight = self.lm_head.weight
|
| 409 |
+
|
| 410 |
+
def get_input_embeddings(self):
|
| 411 |
+
return self.transformer.wte
|
| 412 |
+
|
| 413 |
+
def set_input_embeddings(self, new_embeddings):
|
| 414 |
+
self.transformer.wte = new_embeddings
|
| 415 |
+
|
| 416 |
+
def get_output_embeddings(self):
|
| 417 |
+
return self.lm_head
|
| 418 |
+
|
| 419 |
+
def set_output_embeddings(self, new_embeddings):
|
| 420 |
+
self.lm_head = new_embeddings
|
| 421 |
+
|
| 422 |
+
def forward(self,
|
| 423 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 424 |
+
attention_mask: Optional[torch.FloatTensor] = None,
|
| 425 |
+
labels: Optional[torch.LongTensor] = None,
|
| 426 |
+
**kwargs) -> CausalLMOutputWithPast:
|
| 427 |
+
outputs = self.transformer(input_ids)
|
| 428 |
+
hidden_states = outputs.last_hidden_state
|
| 429 |
+
logits = self.lm_head(hidden_states)
|
| 430 |
+
|
| 431 |
+
loss = None
|
| 432 |
+
if labels is not None:
|
| 433 |
+
shift_logits = logits[:, :-1, :].contiguous()
|
| 434 |
+
shift_labels = labels[:, 1:].contiguous()
|
| 435 |
+
loss = F.cross_entropy(
|
| 436 |
+
shift_logits.view(-1, self.config.vocab_size),
|
| 437 |
+
shift_labels.view(-1),
|
| 438 |
+
ignore_index=-100
|
| 439 |
+
)
|
| 440 |
+
|
| 441 |
+
return CausalLMOutputWithPast(
|
| 442 |
+
loss=loss,
|
| 443 |
+
logits=logits,
|
| 444 |
+
past_key_values=None,
|
| 445 |
+
hidden_states=None,
|
| 446 |
+
attentions=None,
|
| 447 |
+
)
|
| 448 |
+
|
| 449 |
+
def prepare_inputs_for_generation(self, input_ids, **kwargs):
|
| 450 |
+
return {"input_ids": input_ids}
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
# Register with auto-mapping
|
| 454 |
+
AutoConfig.register("xpertgpt", XpertGPTConfig)
|
| 455 |
+
AutoModel.register(XpertGPTConfig, XpertGPTModelWrapper)
|
| 456 |
+
AutoModelForCausalLM.register(XpertGPTConfig, XpertGPTForCausalLM)
|
checkpoints/xpertgpt_fresh/chck_20M/pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4e9078c28108f48e47eb7600fd1dfbf7ef616cf8def294f34e3d82d22b1f0838
|
| 3 |
+
size 210797423
|
checkpoints/xpertgpt_fresh/chck_20M/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|