Add files using upload-large-folder tool
Browse files- LTA_openwebtext_dualt/logs/lm1b_len128_lognormal_atoms_sde_watch/infer_lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522_step_0017000_logistic_normal_t1p45.log +76 -0
- LTA_openwebtext_dualt/logs/lm1b_len128_lognormal_atoms_sde_watch/infer_lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522_step_0045000_logistic_normal_t1p45.log +76 -0
- LTA_openwebtext_dualt/logs/lm1b_len128_lognormal_atoms_sde_watch/infer_lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522_step_0080000_logistic_normal_t1p45.log +76 -0
- LTA_openwebtext_dualt/logs/lm1b_len128_lognormal_atoms_sde_watch/infer_lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522_step_0095000_logistic_normal_t1p45.log +76 -0
- LTA_openwebtext_dualt/logs/lm1b_len128_lognormal_atoms_sde_watch/infer_lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522_step_0115000_logistic_normal_t1p45.log +76 -0
- LTA_openwebtext_dualt/logs/lm1b_len128_lognormal_atoms_sde_watch/infer_lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522_step_0119000_logistic_normal_t1p45.log +76 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.deps/muon_optimizer-0.1.0.dist-info/INSTALLER +1 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.deps/muon_optimizer-0.1.0.dist-info/METADATA +105 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.deps/muon_optimizer-0.1.0.dist-info/RECORD +9 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.deps/muon_optimizer-0.1.0.dist-info/REQUESTED +0 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.deps/muon_optimizer-0.1.0.dist-info/WHEEL +5 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.deps/muon_optimizer-0.1.0.dist-info/licenses/LICENSE +21 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.deps/muon_optimizer-0.1.0.dist-info/top_level.txt +1 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/bloom/configuration_bloom.py +82 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/got_ocr2/image_processing_pil_got_ocr2.py +310 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/got_ocr2/modular_got_ocr2.py +388 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/got_ocr2/processing_got_ocr2.py +231 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/moonshine/__init__.py +27 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/runs/dirichlet_numeric_sim_old_vs_log_v32100_s128.csv +13 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/runs/dirichlet_numeric_sim_v32100_s128.csv +13 -0
LTA_openwebtext_dualt/logs/lm1b_len128_lognormal_atoms_sde_watch/infer_lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522_step_0017000_logistic_normal_t1p45.log
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[watch-lognormal-sde] 2026-05-23_00:08:31 infer runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0017000.pt -> docs/lta_samples/metrics_20260522/lm1b_len128_lognormal_atoms_every1k_logistic_normal_sde_t1p45_steps128_n256/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0017000
|
| 2 |
+
[load] runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0017000.pt
|
| 3 |
+
[ckpt] step=17000
|
| 4 |
+
[sde] generated 16/256
|
| 5 |
+
[sde] generated 32/256
|
| 6 |
+
[sde] generated 48/256
|
| 7 |
+
[sde] generated 64/256
|
| 8 |
+
[sde] generated 80/256
|
| 9 |
+
[sde] generated 96/256
|
| 10 |
+
[sde] generated 112/256
|
| 11 |
+
[sde] generated 128/256
|
| 12 |
+
[sde] generated 144/256
|
| 13 |
+
[sde] generated 160/256
|
| 14 |
+
[sde] generated 176/256
|
| 15 |
+
[sde] generated 192/256
|
| 16 |
+
[sde] generated 208/256
|
| 17 |
+
[sde] generated 224/256
|
| 18 |
+
[sde] generated 240/256
|
| 19 |
+
[sde] generated 256/256
|
| 20 |
+
[score] loading scorer: /e2e-data/evad-tech-vla/wanghan58/models/flowtext_scorers/gpt2-large-standard
|
| 21 |
+
[summary] {
|
| 22 |
+
"type": "summary",
|
| 23 |
+
"checkpoint": "runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0017000.pt",
|
| 24 |
+
"step": 17000,
|
| 25 |
+
"decode": {
|
| 26 |
+
"decode_rule": "logistic_normal_resample_sde",
|
| 27 |
+
"steps": 128,
|
| 28 |
+
"model_t_mode": "const0.5",
|
| 29 |
+
"mean_mode": "anchor_semantic",
|
| 30 |
+
"endpoint_floor": 0.0,
|
| 31 |
+
"concentration_min": 1.0,
|
| 32 |
+
"concentration_max": 1024.0,
|
| 33 |
+
"endpoint_temp": 1.45,
|
| 34 |
+
"support_power": 1.0,
|
| 35 |
+
"semantic_power": 1.0,
|
| 36 |
+
"noise_init": "logistic_normal",
|
| 37 |
+
"noise_sigma": 3.0,
|
| 38 |
+
"noise_dirichlet_concentration": 1.0,
|
| 39 |
+
"sde_resample": "logistic_normal",
|
| 40 |
+
"logistic_normal_sigma_min": 0.18,
|
| 41 |
+
"logistic_normal_sigma_max": 3.0,
|
| 42 |
+
"logistic_normal_tau_min": 0.65,
|
| 43 |
+
"logistic_normal_tau_max": 1.0,
|
| 44 |
+
"final_from": "blend_0.5",
|
| 45 |
+
"n_samples": 256,
|
| 46 |
+
"seed": 20260522
|
| 47 |
+
},
|
| 48 |
+
"raw_genppl": {
|
| 49 |
+
"ppl": 32.96868844968726,
|
| 50 |
+
"nll_per_token": 3.4955582761797803,
|
| 51 |
+
"tokens": 34392,
|
| 52 |
+
"kept_samples": 256,
|
| 53 |
+
"total_samples": 256,
|
| 54 |
+
"empty_rate": 0.0,
|
| 55 |
+
"skipped_samples": 0
|
| 56 |
+
},
|
| 57 |
+
"stripped_genppl": {
|
| 58 |
+
"ppl": 44.511234516933115,
|
| 59 |
+
"nll_per_token": 3.795741618363942,
|
| 60 |
+
"tokens": 28655,
|
| 61 |
+
"kept_samples": 256,
|
| 62 |
+
"total_samples": 256,
|
| 63 |
+
"empty_rate": 0.0,
|
| 64 |
+
"skipped_samples": 0
|
| 65 |
+
},
|
| 66 |
+
"diversity": {
|
| 67 |
+
"sample_entropy": 3.516973326930281,
|
| 68 |
+
"unique_tokens": 1775,
|
| 69 |
+
"token_count": 32768,
|
| 70 |
+
"distinct_1": 0.054168701171875,
|
| 71 |
+
"distinct_2": 0.27303764763779526,
|
| 72 |
+
"top_token_mass": 0.1605224609375
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
[done] docs/lta_samples/metrics_20260522/lm1b_len128_lognormal_atoms_every1k_logistic_normal_sde_t1p45_steps128_n256/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0017000/sde_steps128_samples256_scored.jsonl
|
| 76 |
+
[watch-lognormal-sde] 2026-05-23_00:09:58 done step_0017000
|
LTA_openwebtext_dualt/logs/lm1b_len128_lognormal_atoms_sde_watch/infer_lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522_step_0045000_logistic_normal_t1p45.log
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[watch-lognormal-sde] 2026-05-23_02:45:03 infer runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0045000.pt -> docs/lta_samples/metrics_20260522/lm1b_len128_lognormal_atoms_every1k_logistic_normal_sde_t1p45_steps128_n256/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0045000
|
| 2 |
+
[load] runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0045000.pt
|
| 3 |
+
[ckpt] step=45000
|
| 4 |
+
[sde] generated 16/256
|
| 5 |
+
[sde] generated 32/256
|
| 6 |
+
[sde] generated 48/256
|
| 7 |
+
[sde] generated 64/256
|
| 8 |
+
[sde] generated 80/256
|
| 9 |
+
[sde] generated 96/256
|
| 10 |
+
[sde] generated 112/256
|
| 11 |
+
[sde] generated 128/256
|
| 12 |
+
[sde] generated 144/256
|
| 13 |
+
[sde] generated 160/256
|
| 14 |
+
[sde] generated 176/256
|
| 15 |
+
[sde] generated 192/256
|
| 16 |
+
[sde] generated 208/256
|
| 17 |
+
[sde] generated 224/256
|
| 18 |
+
[sde] generated 240/256
|
| 19 |
+
[sde] generated 256/256
|
| 20 |
+
[score] loading scorer: /e2e-data/evad-tech-vla/wanghan58/models/flowtext_scorers/gpt2-large-standard
|
| 21 |
+
[summary] {
|
| 22 |
+
"type": "summary",
|
| 23 |
+
"checkpoint": "runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0045000.pt",
|
| 24 |
+
"step": 45000,
|
| 25 |
+
"decode": {
|
| 26 |
+
"decode_rule": "logistic_normal_resample_sde",
|
| 27 |
+
"steps": 128,
|
| 28 |
+
"model_t_mode": "const0.5",
|
| 29 |
+
"mean_mode": "anchor_semantic",
|
| 30 |
+
"endpoint_floor": 0.0,
|
| 31 |
+
"concentration_min": 1.0,
|
| 32 |
+
"concentration_max": 1024.0,
|
| 33 |
+
"endpoint_temp": 1.45,
|
| 34 |
+
"support_power": 1.0,
|
| 35 |
+
"semantic_power": 1.0,
|
| 36 |
+
"noise_init": "logistic_normal",
|
| 37 |
+
"noise_sigma": 3.0,
|
| 38 |
+
"noise_dirichlet_concentration": 1.0,
|
| 39 |
+
"sde_resample": "logistic_normal",
|
| 40 |
+
"logistic_normal_sigma_min": 0.18,
|
| 41 |
+
"logistic_normal_sigma_max": 3.0,
|
| 42 |
+
"logistic_normal_tau_min": 0.65,
|
| 43 |
+
"logistic_normal_tau_max": 1.0,
|
| 44 |
+
"final_from": "blend_0.5",
|
| 45 |
+
"n_samples": 256,
|
| 46 |
+
"seed": 20260522
|
| 47 |
+
},
|
| 48 |
+
"raw_genppl": {
|
| 49 |
+
"ppl": 30.422828271197886,
|
| 50 |
+
"nll_per_token": 3.4151932565789473,
|
| 51 |
+
"tokens": 36974,
|
| 52 |
+
"kept_samples": 256,
|
| 53 |
+
"total_samples": 256,
|
| 54 |
+
"empty_rate": 0.0,
|
| 55 |
+
"skipped_samples": 0
|
| 56 |
+
},
|
| 57 |
+
"stripped_genppl": {
|
| 58 |
+
"ppl": 43.95881792699332,
|
| 59 |
+
"nll_per_token": 3.78325323943306,
|
| 60 |
+
"tokens": 30292,
|
| 61 |
+
"kept_samples": 256,
|
| 62 |
+
"total_samples": 256,
|
| 63 |
+
"empty_rate": 0.0,
|
| 64 |
+
"skipped_samples": 0
|
| 65 |
+
},
|
| 66 |
+
"diversity": {
|
| 67 |
+
"sample_entropy": 3.7343144847775447,
|
| 68 |
+
"unique_tokens": 1830,
|
| 69 |
+
"token_count": 32768,
|
| 70 |
+
"distinct_1": 0.05584716796875,
|
| 71 |
+
"distinct_2": 0.30164247047244097,
|
| 72 |
+
"top_token_mass": 0.089263916015625
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
[done] docs/lta_samples/metrics_20260522/lm1b_len128_lognormal_atoms_every1k_logistic_normal_sde_t1p45_steps128_n256/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0045000/sde_steps128_samples256_scored.jsonl
|
| 76 |
+
[watch-lognormal-sde] 2026-05-23_02:46:31 done step_0045000
|
LTA_openwebtext_dualt/logs/lm1b_len128_lognormal_atoms_sde_watch/infer_lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522_step_0080000_logistic_normal_t1p45.log
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[watch-lognormal-sde] 2026-05-23_06:00:36 infer runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0080000.pt -> docs/lta_samples/metrics_20260522/lm1b_len128_lognormal_atoms_every1k_logistic_normal_sde_t1p45_steps128_n256/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0080000
|
| 2 |
+
[load] runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0080000.pt
|
| 3 |
+
[ckpt] step=80000
|
| 4 |
+
[sde] generated 16/256
|
| 5 |
+
[sde] generated 32/256
|
| 6 |
+
[sde] generated 48/256
|
| 7 |
+
[sde] generated 64/256
|
| 8 |
+
[sde] generated 80/256
|
| 9 |
+
[sde] generated 96/256
|
| 10 |
+
[sde] generated 112/256
|
| 11 |
+
[sde] generated 128/256
|
| 12 |
+
[sde] generated 144/256
|
| 13 |
+
[sde] generated 160/256
|
| 14 |
+
[sde] generated 176/256
|
| 15 |
+
[sde] generated 192/256
|
| 16 |
+
[sde] generated 208/256
|
| 17 |
+
[sde] generated 224/256
|
| 18 |
+
[sde] generated 240/256
|
| 19 |
+
[sde] generated 256/256
|
| 20 |
+
[score] loading scorer: /e2e-data/evad-tech-vla/wanghan58/models/flowtext_scorers/gpt2-large-standard
|
| 21 |
+
[summary] {
|
| 22 |
+
"type": "summary",
|
| 23 |
+
"checkpoint": "runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0080000.pt",
|
| 24 |
+
"step": 80000,
|
| 25 |
+
"decode": {
|
| 26 |
+
"decode_rule": "logistic_normal_resample_sde",
|
| 27 |
+
"steps": 128,
|
| 28 |
+
"model_t_mode": "const0.5",
|
| 29 |
+
"mean_mode": "anchor_semantic",
|
| 30 |
+
"endpoint_floor": 0.0,
|
| 31 |
+
"concentration_min": 1.0,
|
| 32 |
+
"concentration_max": 1024.0,
|
| 33 |
+
"endpoint_temp": 1.45,
|
| 34 |
+
"support_power": 1.0,
|
| 35 |
+
"semantic_power": 1.0,
|
| 36 |
+
"noise_init": "logistic_normal",
|
| 37 |
+
"noise_sigma": 3.0,
|
| 38 |
+
"noise_dirichlet_concentration": 1.0,
|
| 39 |
+
"sde_resample": "logistic_normal",
|
| 40 |
+
"logistic_normal_sigma_min": 0.18,
|
| 41 |
+
"logistic_normal_sigma_max": 3.0,
|
| 42 |
+
"logistic_normal_tau_min": 0.65,
|
| 43 |
+
"logistic_normal_tau_max": 1.0,
|
| 44 |
+
"final_from": "blend_0.5",
|
| 45 |
+
"n_samples": 256,
|
| 46 |
+
"seed": 20260522
|
| 47 |
+
},
|
| 48 |
+
"raw_genppl": {
|
| 49 |
+
"ppl": 31.097837718960108,
|
| 50 |
+
"nll_per_token": 3.437138290046554,
|
| 51 |
+
"tokens": 36369,
|
| 52 |
+
"kept_samples": 256,
|
| 53 |
+
"total_samples": 256,
|
| 54 |
+
"empty_rate": 0.0,
|
| 55 |
+
"skipped_samples": 0
|
| 56 |
+
},
|
| 57 |
+
"stripped_genppl": {
|
| 58 |
+
"ppl": 44.05213155429666,
|
| 59 |
+
"nll_per_token": 3.785373740639305,
|
| 60 |
+
"tokens": 29929,
|
| 61 |
+
"kept_samples": 256,
|
| 62 |
+
"total_samples": 256,
|
| 63 |
+
"empty_rate": 0.0,
|
| 64 |
+
"skipped_samples": 0
|
| 65 |
+
},
|
| 66 |
+
"diversity": {
|
| 67 |
+
"sample_entropy": 3.7593508905065947,
|
| 68 |
+
"unique_tokens": 1830,
|
| 69 |
+
"token_count": 32768,
|
| 70 |
+
"distinct_1": 0.05584716796875,
|
| 71 |
+
"distinct_2": 0.3041031003937008,
|
| 72 |
+
"top_token_mass": 0.090576171875
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
[done] docs/lta_samples/metrics_20260522/lm1b_len128_lognormal_atoms_every1k_logistic_normal_sde_t1p45_steps128_n256/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0080000/sde_steps128_samples256_scored.jsonl
|
| 76 |
+
[watch-lognormal-sde] 2026-05-23_06:02:04 done step_0080000
|
LTA_openwebtext_dualt/logs/lm1b_len128_lognormal_atoms_sde_watch/infer_lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522_step_0095000_logistic_normal_t1p45.log
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[watch-lognormal-sde] 2026-05-23_07:24:16 infer runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0095000.pt -> docs/lta_samples/metrics_20260522/lm1b_len128_lognormal_atoms_every1k_logistic_normal_sde_t1p45_steps128_n256/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0095000
|
| 2 |
+
[load] runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0095000.pt
|
| 3 |
+
[ckpt] step=95000
|
| 4 |
+
[sde] generated 16/256
|
| 5 |
+
[sde] generated 32/256
|
| 6 |
+
[sde] generated 48/256
|
| 7 |
+
[sde] generated 64/256
|
| 8 |
+
[sde] generated 80/256
|
| 9 |
+
[sde] generated 96/256
|
| 10 |
+
[sde] generated 112/256
|
| 11 |
+
[sde] generated 128/256
|
| 12 |
+
[sde] generated 144/256
|
| 13 |
+
[sde] generated 160/256
|
| 14 |
+
[sde] generated 176/256
|
| 15 |
+
[sde] generated 192/256
|
| 16 |
+
[sde] generated 208/256
|
| 17 |
+
[sde] generated 224/256
|
| 18 |
+
[sde] generated 240/256
|
| 19 |
+
[sde] generated 256/256
|
| 20 |
+
[score] loading scorer: /e2e-data/evad-tech-vla/wanghan58/models/flowtext_scorers/gpt2-large-standard
|
| 21 |
+
[summary] {
|
| 22 |
+
"type": "summary",
|
| 23 |
+
"checkpoint": "runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0095000.pt",
|
| 24 |
+
"step": 95000,
|
| 25 |
+
"decode": {
|
| 26 |
+
"decode_rule": "logistic_normal_resample_sde",
|
| 27 |
+
"steps": 128,
|
| 28 |
+
"model_t_mode": "const0.5",
|
| 29 |
+
"mean_mode": "anchor_semantic",
|
| 30 |
+
"endpoint_floor": 0.0,
|
| 31 |
+
"concentration_min": 1.0,
|
| 32 |
+
"concentration_max": 1024.0,
|
| 33 |
+
"endpoint_temp": 1.45,
|
| 34 |
+
"support_power": 1.0,
|
| 35 |
+
"semantic_power": 1.0,
|
| 36 |
+
"noise_init": "logistic_normal",
|
| 37 |
+
"noise_sigma": 3.0,
|
| 38 |
+
"noise_dirichlet_concentration": 1.0,
|
| 39 |
+
"sde_resample": "logistic_normal",
|
| 40 |
+
"logistic_normal_sigma_min": 0.18,
|
| 41 |
+
"logistic_normal_sigma_max": 3.0,
|
| 42 |
+
"logistic_normal_tau_min": 0.65,
|
| 43 |
+
"logistic_normal_tau_max": 1.0,
|
| 44 |
+
"final_from": "blend_0.5",
|
| 45 |
+
"n_samples": 256,
|
| 46 |
+
"seed": 20260522
|
| 47 |
+
},
|
| 48 |
+
"raw_genppl": {
|
| 49 |
+
"ppl": 35.29678225364393,
|
| 50 |
+
"nll_per_token": 3.5637918054967392,
|
| 51 |
+
"tokens": 34388,
|
| 52 |
+
"kept_samples": 256,
|
| 53 |
+
"total_samples": 256,
|
| 54 |
+
"empty_rate": 0.0,
|
| 55 |
+
"skipped_samples": 0
|
| 56 |
+
},
|
| 57 |
+
"stripped_genppl": {
|
| 58 |
+
"ppl": 45.884026994283424,
|
| 59 |
+
"nll_per_token": 3.8261170607346755,
|
| 60 |
+
"tokens": 29120,
|
| 61 |
+
"kept_samples": 256,
|
| 62 |
+
"total_samples": 256,
|
| 63 |
+
"empty_rate": 0.0,
|
| 64 |
+
"skipped_samples": 0
|
| 65 |
+
},
|
| 66 |
+
"diversity": {
|
| 67 |
+
"sample_entropy": 3.5066169703973267,
|
| 68 |
+
"unique_tokens": 2268,
|
| 69 |
+
"token_count": 32768,
|
| 70 |
+
"distinct_1": 0.0692138671875,
|
| 71 |
+
"distinct_2": 0.34639517716535434,
|
| 72 |
+
"top_token_mass": 0.137786865234375
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
[done] docs/lta_samples/metrics_20260522/lm1b_len128_lognormal_atoms_every1k_logistic_normal_sde_t1p45_steps128_n256/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0095000/sde_steps128_samples256_scored.jsonl
|
| 76 |
+
[watch-lognormal-sde] 2026-05-23_07:25:43 done step_0095000
|
LTA_openwebtext_dualt/logs/lm1b_len128_lognormal_atoms_sde_watch/infer_lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522_step_0115000_logistic_normal_t1p45.log
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[watch-lognormal-sde] 2026-05-23_09:15:41 infer runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0115000.pt -> docs/lta_samples/metrics_20260522/lm1b_len128_lognormal_atoms_every1k_logistic_normal_sde_t1p45_steps128_n256/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0115000
|
| 2 |
+
[load] runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0115000.pt
|
| 3 |
+
[ckpt] step=115000
|
| 4 |
+
[sde] generated 16/256
|
| 5 |
+
[sde] generated 32/256
|
| 6 |
+
[sde] generated 48/256
|
| 7 |
+
[sde] generated 64/256
|
| 8 |
+
[sde] generated 80/256
|
| 9 |
+
[sde] generated 96/256
|
| 10 |
+
[sde] generated 112/256
|
| 11 |
+
[sde] generated 128/256
|
| 12 |
+
[sde] generated 144/256
|
| 13 |
+
[sde] generated 160/256
|
| 14 |
+
[sde] generated 176/256
|
| 15 |
+
[sde] generated 192/256
|
| 16 |
+
[sde] generated 208/256
|
| 17 |
+
[sde] generated 224/256
|
| 18 |
+
[sde] generated 240/256
|
| 19 |
+
[sde] generated 256/256
|
| 20 |
+
[score] loading scorer: /e2e-data/evad-tech-vla/wanghan58/models/flowtext_scorers/gpt2-large-standard
|
| 21 |
+
[summary] {
|
| 22 |
+
"type": "summary",
|
| 23 |
+
"checkpoint": "runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0115000.pt",
|
| 24 |
+
"step": 115000,
|
| 25 |
+
"decode": {
|
| 26 |
+
"decode_rule": "logistic_normal_resample_sde",
|
| 27 |
+
"steps": 128,
|
| 28 |
+
"model_t_mode": "const0.5",
|
| 29 |
+
"mean_mode": "anchor_semantic",
|
| 30 |
+
"endpoint_floor": 0.0,
|
| 31 |
+
"concentration_min": 1.0,
|
| 32 |
+
"concentration_max": 1024.0,
|
| 33 |
+
"endpoint_temp": 1.45,
|
| 34 |
+
"support_power": 1.0,
|
| 35 |
+
"semantic_power": 1.0,
|
| 36 |
+
"noise_init": "logistic_normal",
|
| 37 |
+
"noise_sigma": 3.0,
|
| 38 |
+
"noise_dirichlet_concentration": 1.0,
|
| 39 |
+
"sde_resample": "logistic_normal",
|
| 40 |
+
"logistic_normal_sigma_min": 0.18,
|
| 41 |
+
"logistic_normal_sigma_max": 3.0,
|
| 42 |
+
"logistic_normal_tau_min": 0.65,
|
| 43 |
+
"logistic_normal_tau_max": 1.0,
|
| 44 |
+
"final_from": "blend_0.5",
|
| 45 |
+
"n_samples": 256,
|
| 46 |
+
"seed": 20260522
|
| 47 |
+
},
|
| 48 |
+
"raw_genppl": {
|
| 49 |
+
"ppl": 31.88784973151671,
|
| 50 |
+
"nll_per_token": 3.4622250510758907,
|
| 51 |
+
"tokens": 37559,
|
| 52 |
+
"kept_samples": 256,
|
| 53 |
+
"total_samples": 256,
|
| 54 |
+
"empty_rate": 0.0,
|
| 55 |
+
"skipped_samples": 0
|
| 56 |
+
},
|
| 57 |
+
"stripped_genppl": {
|
| 58 |
+
"ppl": 44.994357822922595,
|
| 59 |
+
"nll_per_token": 3.8065371001965445,
|
| 60 |
+
"tokens": 31068,
|
| 61 |
+
"kept_samples": 256,
|
| 62 |
+
"total_samples": 256,
|
| 63 |
+
"empty_rate": 0.0,
|
| 64 |
+
"skipped_samples": 0
|
| 65 |
+
},
|
| 66 |
+
"diversity": {
|
| 67 |
+
"sample_entropy": 3.9007762593098327,
|
| 68 |
+
"unique_tokens": 2532,
|
| 69 |
+
"token_count": 32768,
|
| 70 |
+
"distinct_1": 0.0772705078125,
|
| 71 |
+
"distinct_2": 0.3822896161417323,
|
| 72 |
+
"top_token_mass": 0.07061767578125
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
[done] docs/lta_samples/metrics_20260522/lm1b_len128_lognormal_atoms_every1k_logistic_normal_sde_t1p45_steps128_n256/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0115000/sde_steps128_samples256_scored.jsonl
|
| 76 |
+
[watch-lognormal-sde] 2026-05-23_09:17:09 done step_0115000
|
LTA_openwebtext_dualt/logs/lm1b_len128_lognormal_atoms_sde_watch/infer_lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522_step_0119000_logistic_normal_t1p45.log
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[watch-lognormal-sde] 2026-05-23_09:38:06 infer runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0119000.pt -> docs/lta_samples/metrics_20260522/lm1b_len128_lognormal_atoms_every1k_logistic_normal_sde_t1p45_steps128_n256/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0119000
|
| 2 |
+
[load] runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0119000.pt
|
| 3 |
+
[ckpt] step=119000
|
| 4 |
+
[sde] generated 16/256
|
| 5 |
+
[sde] generated 32/256
|
| 6 |
+
[sde] generated 48/256
|
| 7 |
+
[sde] generated 64/256
|
| 8 |
+
[sde] generated 80/256
|
| 9 |
+
[sde] generated 96/256
|
| 10 |
+
[sde] generated 112/256
|
| 11 |
+
[sde] generated 128/256
|
| 12 |
+
[sde] generated 144/256
|
| 13 |
+
[sde] generated 160/256
|
| 14 |
+
[sde] generated 176/256
|
| 15 |
+
[sde] generated 192/256
|
| 16 |
+
[sde] generated 208/256
|
| 17 |
+
[sde] generated 224/256
|
| 18 |
+
[sde] generated 240/256
|
| 19 |
+
[sde] generated 256/256
|
| 20 |
+
[score] loading scorer: /e2e-data/evad-tech-vla/wanghan58/models/flowtext_scorers/gpt2-large-standard
|
| 21 |
+
[summary] {
|
| 22 |
+
"type": "summary",
|
| 23 |
+
"checkpoint": "runs/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0119000.pt",
|
| 24 |
+
"step": 119000,
|
| 25 |
+
"decode": {
|
| 26 |
+
"decode_rule": "logistic_normal_resample_sde",
|
| 27 |
+
"steps": 128,
|
| 28 |
+
"model_t_mode": "const0.5",
|
| 29 |
+
"mean_mode": "anchor_semantic",
|
| 30 |
+
"endpoint_floor": 0.0,
|
| 31 |
+
"concentration_min": 1.0,
|
| 32 |
+
"concentration_max": 1024.0,
|
| 33 |
+
"endpoint_temp": 1.45,
|
| 34 |
+
"support_power": 1.0,
|
| 35 |
+
"semantic_power": 1.0,
|
| 36 |
+
"noise_init": "logistic_normal",
|
| 37 |
+
"noise_sigma": 3.0,
|
| 38 |
+
"noise_dirichlet_concentration": 1.0,
|
| 39 |
+
"sde_resample": "logistic_normal",
|
| 40 |
+
"logistic_normal_sigma_min": 0.18,
|
| 41 |
+
"logistic_normal_sigma_max": 3.0,
|
| 42 |
+
"logistic_normal_tau_min": 0.65,
|
| 43 |
+
"logistic_normal_tau_max": 1.0,
|
| 44 |
+
"final_from": "blend_0.5",
|
| 45 |
+
"n_samples": 256,
|
| 46 |
+
"seed": 20260522
|
| 47 |
+
},
|
| 48 |
+
"raw_genppl": {
|
| 49 |
+
"ppl": 35.481425020285705,
|
| 50 |
+
"nll_per_token": 3.5690093206789544,
|
| 51 |
+
"tokens": 32597,
|
| 52 |
+
"kept_samples": 256,
|
| 53 |
+
"total_samples": 256,
|
| 54 |
+
"empty_rate": 0.0,
|
| 55 |
+
"skipped_samples": 0
|
| 56 |
+
},
|
| 57 |
+
"stripped_genppl": {
|
| 58 |
+
"ppl": 48.60573987367665,
|
| 59 |
+
"nll_per_token": 3.883741628329312,
|
| 60 |
+
"tokens": 27042,
|
| 61 |
+
"kept_samples": 256,
|
| 62 |
+
"total_samples": 256,
|
| 63 |
+
"empty_rate": 0.0,
|
| 64 |
+
"skipped_samples": 0
|
| 65 |
+
},
|
| 66 |
+
"diversity": {
|
| 67 |
+
"sample_entropy": 3.401137109533905,
|
| 68 |
+
"unique_tokens": 2040,
|
| 69 |
+
"token_count": 32768,
|
| 70 |
+
"distinct_1": 0.062255859375,
|
| 71 |
+
"distinct_2": 0.3155142716535433,
|
| 72 |
+
"top_token_mass": 0.198883056640625
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
[done] docs/lta_samples/metrics_20260522/lm1b_len128_lognormal_atoms_every1k_logistic_normal_sde_t1p45_steps128_n256/lta_lm1b_classic_c1024_len128_lognormalatoms_gbs512_4gpu_20260522/step_0119000/sde_steps128_samples256_scored.jsonl
|
| 76 |
+
[watch-lognormal-sde] 2026-05-23_09:39:33 done step_0119000
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.deps/muon_optimizer-0.1.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.deps/muon_optimizer-0.1.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: muon-optimizer
|
| 3 |
+
Version: 0.1.0
|
| 4 |
+
Summary: Muon opimizer
|
| 5 |
+
Home-page: https://github.com/KellerJordan/Muon
|
| 6 |
+
Author: Keller Jordan
|
| 7 |
+
Author-email: kjordan4077@gmail.com
|
| 8 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 9 |
+
Classifier: Intended Audience :: Developers
|
| 10 |
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
| 11 |
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
| 12 |
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
| 13 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 14 |
+
Classifier: Programming Language :: Python :: 3
|
| 15 |
+
Classifier: Programming Language :: Python :: 3.7
|
| 16 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 17 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 20 |
+
Description-Content-Type: text/markdown
|
| 21 |
+
License-File: LICENSE
|
| 22 |
+
Dynamic: author
|
| 23 |
+
Dynamic: author-email
|
| 24 |
+
Dynamic: classifier
|
| 25 |
+
Dynamic: description
|
| 26 |
+
Dynamic: description-content-type
|
| 27 |
+
Dynamic: home-page
|
| 28 |
+
Dynamic: license-file
|
| 29 |
+
Dynamic: summary
|
| 30 |
+
|
| 31 |
+
# Muon: An optimizer for the hidden layers of neural networks
|
| 32 |
+
|
| 33 |
+
This repo contains an implementation of the `Muon` optimizer originally described in [this thread](https://x.com/kellerjordan0/status/1842300916864844014) and [this writeup](https://kellerjordan.github.io/posts/muon/).
|
| 34 |
+
|
| 35 |
+
## Installation
|
| 36 |
+
|
| 37 |
+
```
|
| 38 |
+
pip install git+https://github.com/KellerJordan/Muon
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
## Usage
|
| 42 |
+
|
| 43 |
+
Muon is intended to optimize only the internal ≥2D parameters of a network.
|
| 44 |
+
Embeddings, classifier heads, and internal gains/biases should be optimized using AdamW.
|
| 45 |
+
|
| 46 |
+
```python
|
| 47 |
+
# optimizer = torch.optim.AdamW(model.parameters(), lr=3e-4, betas=(0.90, 0.95), weight_decay=0.01)
|
| 48 |
+
|
| 49 |
+
from muon import MuonWithAuxAdam
|
| 50 |
+
# Find ≥2D parameters in the body of the network -- these should be optimized by Muon
|
| 51 |
+
hidden_weights = [p for p in model.body.parameters() if p.ndim >= 2]
|
| 52 |
+
# Find everything else -- these should be optimized by AdamW
|
| 53 |
+
hidden_gains_biases = [p for p in model.body.parameters() if p.ndim < 2]
|
| 54 |
+
exterior_weights = [*model.head.parameters(), *model.embed.parameters()])
|
| 55 |
+
# Create the optimizer
|
| 56 |
+
# Note: you can also use multiple groups of each type with different hparams if you want.
|
| 57 |
+
muon_group = dict(params=hidden_weights, lr=0.02, weight_decay=0.01, use_muon=True)
|
| 58 |
+
adam_group = dict(params=hidden_gains_biases+exterior_weights, lr=3e-4,
|
| 59 |
+
betas=(0.9, 0.95), weight_decay=0.01, use_muon=False)
|
| 60 |
+
optimizer = MuonWithAuxAdam([muon_group, adam_group])
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
You'll have to replace `model.body`, `model.head`, and `model.embed` with whatever subset is appropriate for your model.
|
| 64 |
+
E.g., for a ConvNet, Muon should optimize all the convolutional filters except the first one, and AdamW should optimize everything else.
|
| 65 |
+
|
| 66 |
+
## Example usage
|
| 67 |
+
|
| 68 |
+
[Example use in the NanoGPT speedrun](https://github.com/KellerJordan/modded-nanogpt/blob/master/records/052525_MuonWithAuxAdamExample/b01550f9-03d8-4a9c-86fe-4ab434f1c5e0.txt#L470)
|
| 69 |
+
|
| 70 |
+
[Example use in the CIFAR-10 speedrun](https://github.com/KellerJordan/cifar10-airbench/blob/28bff5f5b31e95aa45b5b20e1f48baf1ed98d5f6/airbench94_muon.py#L362)
|
| 71 |
+
|
| 72 |
+
## Hyperparameter tuning
|
| 73 |
+
|
| 74 |
+
Typically, the default values of momentum (0.95), nesterov (True), and ns_steps (5) work well. The only hyperparameter which must be tuned is the learning rate.
|
| 75 |
+
It should have constant muP scaling, that is, as you scale up the model size, you shouldn't need to retune the learning rate.
|
| 76 |
+
|
| 77 |
+
## Benchmarks
|
| 78 |
+
|
| 79 |
+
For a comparison between AdamW, Shampoo, SOAP, and Muon for training a 124M-parameter transformer, see [here](https://github.com/KellerJordan/modded-nanogpt/tree/master/records/102924_Optimizers).
|
| 80 |
+
|
| 81 |
+
## Accomplishments
|
| 82 |
+
|
| 83 |
+
* [Lowered the record for training to 94% on CIFAR-10 from 3.3 A100-seconds to 2.6 A100-seconds](https://github.com/KellerJordan/cifar10-airbench)
|
| 84 |
+
* [Used to train a transformer to GPT-2 (XL) performance in $175 of compute](https://x.com/kellerjordan0/status/1850995958697308307)
|
| 85 |
+
* [Improved the training speed record for attaining GPT-2 (small) performance by a factor of 1.35x](https://x.com/kellerjordan0/status/1842300916864844014)
|
| 86 |
+
* [Used by the Kimi.ai frontier lab for scaled LLM training](https://x.com/Kimi_Moonshot/status/1893379158472044623)
|
| 87 |
+
|
| 88 |
+
## More learning resources and results about Muon
|
| 89 |
+
|
| 90 |
+
* [Blog post on Muon by Jialin Su (the creator of RoPE)](https://kexue.fm/archives/10592)
|
| 91 |
+
* [Blog post by Jeremy Bernstein on theoretical background of Muon](https://jeremybernste.in/writing/deriving-muon)
|
| 92 |
+
* [Tech report by Kimi.ai on using Muon for scaled training](https://arxiv.org/abs/2502.16982v1)
|
| 93 |
+
* [Why we chose Muon: Our chain of thought (by Jianlin Su at Kimi.ai)](https://x.com/Kimi_Moonshot/status/1897929976948965870)
|
| 94 |
+
|
| 95 |
+
## Citation
|
| 96 |
+
|
| 97 |
+
```bibtex
|
| 98 |
+
@misc{jordan2024muon,
|
| 99 |
+
author = {Keller Jordan and Yuchen Jin and Vlado Boza and You Jiacheng and
|
| 100 |
+
Franz Cesista and Laker Newhouse and Jeremy Bernstein},
|
| 101 |
+
title = {Muon: An optimizer for hidden layers in neural networks},
|
| 102 |
+
year = {2024},
|
| 103 |
+
url = {https://kellerjordan.github.io/posts/muon/}
|
| 104 |
+
}
|
| 105 |
+
```
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.deps/muon_optimizer-0.1.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/muon.cpython-312.pyc,,
|
| 2 |
+
muon.py,sha256=xxTO43XZxzFcsN_g1yPPNX0xJNPGboRGwVDrsGhutIw,11624
|
| 3 |
+
muon_optimizer-0.1.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 4 |
+
muon_optimizer-0.1.0.dist-info/METADATA,sha256=EIFIEtZFlCwJomkFsjDfIJol-VW5vsf6z7lMMDRBfa4,5099
|
| 5 |
+
muon_optimizer-0.1.0.dist-info/RECORD,,
|
| 6 |
+
muon_optimizer-0.1.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 7 |
+
muon_optimizer-0.1.0.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
| 8 |
+
muon_optimizer-0.1.0.dist-info/licenses/LICENSE,sha256=jI0XOY7M490_yxu3e10mikJ_glDzZKxlXJs431tpP2s,1070
|
| 9 |
+
muon_optimizer-0.1.0.dist-info/top_level.txt,sha256=HwisYzr2fexMeo6u2BZYrJruXGC9r7Bw4v7p2GE1z0I,5
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.deps/muon_optimizer-0.1.0.dist-info/REQUESTED
ADDED
|
File without changes
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.deps/muon_optimizer-0.1.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (80.8.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.deps/muon_optimizer-0.1.0.dist-info/licenses/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2024 Keller Jordan
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.deps/muon_optimizer-0.1.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
muon
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/bloom/configuration_bloom.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2022 the Big Science Workshop and HuggingFace Inc. team. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""Bloom configuration"""
|
| 15 |
+
|
| 16 |
+
from huggingface_hub.dataclasses import strict
|
| 17 |
+
|
| 18 |
+
from ...configuration_utils import PreTrainedConfig
|
| 19 |
+
from ...utils import auto_docstring
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@auto_docstring(checkpoint="bigscience/bloom")
|
| 23 |
+
@strict
|
| 24 |
+
class BloomConfig(PreTrainedConfig):
|
| 25 |
+
r"""
|
| 26 |
+
apply_residual_connection_post_layernorm (`bool`, *optional*, defaults to `False`):
|
| 27 |
+
If enabled, use the layer norm of the hidden states as the residual in the transformer blocks
|
| 28 |
+
slow_but_exact (`bool`, *optional*, defaults to `False`):
|
| 29 |
+
Experimental feature. Whether to use slow but exact implementation of the attention mechanism. While
|
| 30 |
+
merging the TP rank tensors, due to slicing operations the results may be slightly different between the
|
| 31 |
+
model trained on Megatron and our model. Please refer to [this
|
| 32 |
+
issue](https://github.com/pytorch/pytorch/issues/76232). A solution to obtain more accurate results is to
|
| 33 |
+
enable this feature. Enabling this will hurt the computational time of the inference. Will be probably
|
| 34 |
+
resolved in the future once the main model has been fine-tuned with TP_rank=1.
|
| 35 |
+
|
| 36 |
+
Example:
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
>>> from transformers import BloomConfig, BloomModel
|
| 40 |
+
|
| 41 |
+
>>> # Initializing a Bloom configuration
|
| 42 |
+
>>> configuration = BloomConfig()
|
| 43 |
+
|
| 44 |
+
>>> # Initializing a model (with random weights) from the configuration
|
| 45 |
+
>>> model = BloomModel(configuration)
|
| 46 |
+
|
| 47 |
+
>>> # Accessing the model configuration
|
| 48 |
+
>>> configuration = model.config
|
| 49 |
+
```"""
|
| 50 |
+
|
| 51 |
+
model_type = "bloom"
|
| 52 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 53 |
+
attribute_map = {
|
| 54 |
+
"num_hidden_layers": "n_layer",
|
| 55 |
+
"num_attention_heads": "n_head",
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
vocab_size: int = 250880
|
| 59 |
+
hidden_size: int = 64
|
| 60 |
+
n_layer: int = 2
|
| 61 |
+
n_head: int = 8
|
| 62 |
+
layer_norm_epsilon: float = 1e-5
|
| 63 |
+
initializer_range: float = 0.02
|
| 64 |
+
use_cache: bool = True
|
| 65 |
+
bos_token_id: int | None = 1
|
| 66 |
+
eos_token_id: int | list[int] | None = 2
|
| 67 |
+
pad_token_id: int | None = None
|
| 68 |
+
apply_residual_connection_post_layernorm: bool = False
|
| 69 |
+
hidden_dropout: float | int = 0.0
|
| 70 |
+
attention_dropout: float | int = 0.0
|
| 71 |
+
pretraining_tp: int = 1 # TP rank used when training with megatro
|
| 72 |
+
slow_but_exact: bool = False
|
| 73 |
+
tie_word_embeddings: bool = True
|
| 74 |
+
|
| 75 |
+
def __post_init__(self, **kwargs):
|
| 76 |
+
# Backward compatibility with n_embed kwarg
|
| 77 |
+
n_embed = kwargs.pop("n_embed", None)
|
| 78 |
+
self.hidden_size = self.hidden_size if n_embed is None else n_embed
|
| 79 |
+
super().__post_init__(**kwargs)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
__all__ = ["BloomConfig"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/got_ocr2/image_processing_pil_got_ocr2.py
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2025 HuggingFace Inc. team. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""Image processor class for Got-OCR-2."""
|
| 15 |
+
|
| 16 |
+
from functools import lru_cache
|
| 17 |
+
|
| 18 |
+
import numpy as np
|
| 19 |
+
|
| 20 |
+
from ...image_processing_backends import PilBackend
|
| 21 |
+
from ...image_processing_utils import BatchFeature
|
| 22 |
+
from ...image_transforms import to_channel_dimension_format
|
| 23 |
+
from ...image_utils import (
|
| 24 |
+
OPENAI_CLIP_MEAN,
|
| 25 |
+
OPENAI_CLIP_STD,
|
| 26 |
+
ChannelDimension,
|
| 27 |
+
PILImageResampling,
|
| 28 |
+
SizeDict,
|
| 29 |
+
get_image_size,
|
| 30 |
+
infer_channel_dimension_format,
|
| 31 |
+
)
|
| 32 |
+
from ...processing_utils import ImagesKwargs, Unpack
|
| 33 |
+
from ...utils import (
|
| 34 |
+
TensorType,
|
| 35 |
+
auto_docstring,
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
# Adapted from transformers.models.got_ocr2.image_processing_got_ocr2.GotOcr2ImageProcessorKwargs
|
| 40 |
+
class GotOcr2ImageProcessorKwargs(ImagesKwargs, total=False):
|
| 41 |
+
r"""
|
| 42 |
+
crop_to_patches (`bool`, *optional*, defaults to `self.crop_to_patches`):
|
| 43 |
+
Whether to crop the image to patches. Can be overridden by the `crop_to_patches` parameter in the
|
| 44 |
+
`preprocess` method.
|
| 45 |
+
min_patches (`int`, *optional*, defaults to `self.min_patches`):
|
| 46 |
+
The minimum number of patches to be extracted from the image. Only has an effect if `crop_to_patches` is
|
| 47 |
+
set to `True`. Can be overridden by the `min_patches` parameter in the `preprocess` method.
|
| 48 |
+
max_patches (`int`, *optional*, defaults to `self.max_patches`):
|
| 49 |
+
The maximum number of patches to be extracted from the image. Only has an effect if `crop_to_patches` is
|
| 50 |
+
set to `True`. Can be overridden by the `max_patches` parameter in the `preprocess` method.
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
crop_to_patches: bool
|
| 54 |
+
min_patches: int
|
| 55 |
+
max_patches: int
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
# Adapted from transformers.models.got_ocr2.image_processing_got_ocr2.get_all_supported_aspect_ratios
|
| 59 |
+
@lru_cache(maxsize=10)
|
| 60 |
+
def get_all_supported_aspect_ratios(min_image_tiles: int, max_image_tiles: int) -> list[tuple[int, int]]:
|
| 61 |
+
"""
|
| 62 |
+
Computes all allowed aspect ratios for a given minimum and maximum number of input tiles.
|
| 63 |
+
|
| 64 |
+
This function calculates all possible arrangements of tiles that can be formed
|
| 65 |
+
within the constraint of the minimum and maximum number of tiles. Each arrangement is
|
| 66 |
+
represented by its aspect ratio (width/height) and the corresponding tile configuration.
|
| 67 |
+
|
| 68 |
+
Args:
|
| 69 |
+
min_image_tiles (`int`):
|
| 70 |
+
The minimum number of tiles allowed.
|
| 71 |
+
max_image_tiles (`int`):
|
| 72 |
+
The maximum number of tiles allowed.
|
| 73 |
+
|
| 74 |
+
Returns:
|
| 75 |
+
`list[tuple[int, int]]`: A list of tuples, each tuple representing a valid (width, height)
|
| 76 |
+
configuration in terms of number of tiles.
|
| 77 |
+
|
| 78 |
+
Example:
|
| 79 |
+
>>> get_all_supported_aspect_ratios(1, 4)
|
| 80 |
+
[(1, 1), (1, 2), (2, 1), (1, 3), (3, 1), (1, 4), (2, 2), (4, 1)]
|
| 81 |
+
|
| 82 |
+
"""
|
| 83 |
+
aspect_ratios = []
|
| 84 |
+
for width in range(1, max_image_tiles + 1):
|
| 85 |
+
for height in range(1, max_image_tiles + 1):
|
| 86 |
+
if width * height <= max_image_tiles and width * height >= min_image_tiles:
|
| 87 |
+
aspect_ratios.append((width, height))
|
| 88 |
+
|
| 89 |
+
aspect_ratios = sorted(aspect_ratios, key=lambda x: x[0] * x[1])
|
| 90 |
+
|
| 91 |
+
return aspect_ratios
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
# Adapted from transformers.models.got_ocr2.image_processing_got_ocr2.get_optimal_tiled_canvas
|
| 95 |
+
@lru_cache(maxsize=100)
|
| 96 |
+
def get_optimal_tiled_canvas(
|
| 97 |
+
original_image_size: tuple[int, int],
|
| 98 |
+
target_tile_size: tuple[int, int],
|
| 99 |
+
min_image_tiles: int,
|
| 100 |
+
max_image_tiles: int,
|
| 101 |
+
) -> tuple[int, int]:
|
| 102 |
+
"""
|
| 103 |
+
Given a minimum and maximum number of tiles, find the canvas with the closest aspect ratio to the
|
| 104 |
+
original image aspect ratio.
|
| 105 |
+
In case of tie-breaking condition when two canvases have the same aspect ratio difference, we favor the canvas with
|
| 106 |
+
more tiles, until the area covered by the tiles is more than twice the target area, in order to avoid unnecessarily
|
| 107 |
+
excessive tiling.
|
| 108 |
+
"""
|
| 109 |
+
possible_tile_arrangements = get_all_supported_aspect_ratios(min_image_tiles, max_image_tiles)
|
| 110 |
+
|
| 111 |
+
original_height, original_width = original_image_size
|
| 112 |
+
target_tile_height, target_tile_width = target_tile_size
|
| 113 |
+
aspect_ratio = original_width / original_height
|
| 114 |
+
area = original_width * original_height
|
| 115 |
+
|
| 116 |
+
# find the grid with the best aspect ratio
|
| 117 |
+
best_ratio_diff = float("inf")
|
| 118 |
+
best_grid = (1, 1)
|
| 119 |
+
for grid in possible_tile_arrangements:
|
| 120 |
+
grid_aspect_ratio = grid[0] / grid[1]
|
| 121 |
+
ratio_diff = abs(aspect_ratio - grid_aspect_ratio)
|
| 122 |
+
if ratio_diff < best_ratio_diff:
|
| 123 |
+
best_ratio_diff = ratio_diff
|
| 124 |
+
best_grid = grid
|
| 125 |
+
elif ratio_diff == best_ratio_diff:
|
| 126 |
+
# if the aspect ratio difference is the same, we favor the grid with more patches
|
| 127 |
+
# until the area covered by the patches is more than twice the original image area
|
| 128 |
+
if area > 0.5 * target_tile_height * target_tile_width * grid[0] * grid[1]:
|
| 129 |
+
best_grid = grid
|
| 130 |
+
|
| 131 |
+
return best_grid
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
@auto_docstring
|
| 135 |
+
class GotOcr2ImageProcessorPil(PilBackend):
|
| 136 |
+
valid_kwargs = GotOcr2ImageProcessorKwargs
|
| 137 |
+
resample = PILImageResampling.BICUBIC
|
| 138 |
+
image_mean = OPENAI_CLIP_MEAN
|
| 139 |
+
image_std = OPENAI_CLIP_STD
|
| 140 |
+
size = {"height": 384, "width": 384}
|
| 141 |
+
do_resize = True
|
| 142 |
+
do_rescale = True
|
| 143 |
+
do_normalize = True
|
| 144 |
+
do_convert_rgb = True
|
| 145 |
+
crop_to_patches = False
|
| 146 |
+
min_patches = 1
|
| 147 |
+
max_patches = 12
|
| 148 |
+
|
| 149 |
+
def __init__(self, **kwargs: Unpack[GotOcr2ImageProcessorKwargs]):
|
| 150 |
+
super().__init__(**kwargs)
|
| 151 |
+
|
| 152 |
+
def crop_image_to_patches(
|
| 153 |
+
self,
|
| 154 |
+
image: np.ndarray,
|
| 155 |
+
min_patches: int,
|
| 156 |
+
max_patches: int,
|
| 157 |
+
use_thumbnail: bool = True,
|
| 158 |
+
patch_size: SizeDict | None = None,
|
| 159 |
+
resample: "PILImageResampling | None" = None,
|
| 160 |
+
):
|
| 161 |
+
"""
|
| 162 |
+
Crop the image to patches and return a list of cropped images.
|
| 163 |
+
The number of patches and their grid arrangement are determined by the original image size,
|
| 164 |
+
the target patch size and the minimum and maximum number of patches.
|
| 165 |
+
The aspect ratio of the patches grid is chosen to be the closest to the original image aspect ratio.
|
| 166 |
+
|
| 167 |
+
Args:
|
| 168 |
+
image (`np.ndarray`):
|
| 169 |
+
The image to be cropped.
|
| 170 |
+
min_patches (`int`):
|
| 171 |
+
The minimum number of patches to be extracted from the image.
|
| 172 |
+
max_patches (`int`):
|
| 173 |
+
The maximum number of patches to be extracted from the image.
|
| 174 |
+
use_thumbnail (`bool`, *optional*, defaults to `True`):
|
| 175 |
+
Whether to add a thumbnail image to the list of cropped patches.
|
| 176 |
+
patch_size (`SizeDict`, *optional*):
|
| 177 |
+
The size of the output patches.
|
| 178 |
+
resample (`PILImageResampling | int | None`, *optional*):
|
| 179 |
+
Resampling filter to use when resizing.
|
| 180 |
+
"""
|
| 181 |
+
# Ensure image is in CHW format for processing
|
| 182 |
+
input_data_format = infer_channel_dimension_format(image)
|
| 183 |
+
image = to_channel_dimension_format(image, ChannelDimension.FIRST, input_data_format)
|
| 184 |
+
|
| 185 |
+
patch_size_height, patch_size_width = patch_size.height, patch_size.width
|
| 186 |
+
original_height, original_width = get_image_size(image, channel_dim=ChannelDimension.FIRST)
|
| 187 |
+
# find the closest aspect ratio to the target
|
| 188 |
+
num_columns, num_rows = get_optimal_tiled_canvas(
|
| 189 |
+
(original_height, original_width), (patch_size_height, patch_size_width), min_patches, max_patches
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
# calculate the target width and height
|
| 193 |
+
target_width = patch_size_width * num_columns
|
| 194 |
+
target_height = patch_size_height * num_rows
|
| 195 |
+
num_blocks = num_columns * num_rows
|
| 196 |
+
|
| 197 |
+
# resize the image so that each patch is of patch_size
|
| 198 |
+
resized_image = self.resize(image, SizeDict(height=target_height, width=target_width), resample=resample)
|
| 199 |
+
# split the image into patches
|
| 200 |
+
processed_images = []
|
| 201 |
+
for i in range(num_blocks):
|
| 202 |
+
column = i % num_columns
|
| 203 |
+
row = i // num_columns
|
| 204 |
+
box = (
|
| 205 |
+
column * patch_size_width,
|
| 206 |
+
row * patch_size_height,
|
| 207 |
+
(column + 1) * patch_size_width,
|
| 208 |
+
(row + 1) * patch_size_height,
|
| 209 |
+
)
|
| 210 |
+
# split the image (images are CHW format)
|
| 211 |
+
patch_image = resized_image[..., box[1] : box[3], box[0] : box[2]]
|
| 212 |
+
# Convert back to original format
|
| 213 |
+
patch_image = to_channel_dimension_format(patch_image, input_data_format, ChannelDimension.FIRST)
|
| 214 |
+
processed_images.append(patch_image)
|
| 215 |
+
|
| 216 |
+
if use_thumbnail and len(processed_images) != 1:
|
| 217 |
+
thumbnail_img = self.resize(image, patch_size, resample=resample)
|
| 218 |
+
thumbnail_img = to_channel_dimension_format(thumbnail_img, input_data_format, ChannelDimension.FIRST)
|
| 219 |
+
processed_images.append(thumbnail_img)
|
| 220 |
+
|
| 221 |
+
return processed_images
|
| 222 |
+
|
| 223 |
+
def _preprocess(
|
| 224 |
+
self,
|
| 225 |
+
images: list[np.ndarray],
|
| 226 |
+
do_resize: bool,
|
| 227 |
+
size: SizeDict,
|
| 228 |
+
resample: "PILImageResampling | None",
|
| 229 |
+
do_rescale: bool,
|
| 230 |
+
rescale_factor: float,
|
| 231 |
+
do_normalize: bool,
|
| 232 |
+
image_mean: float | list[float] | None,
|
| 233 |
+
image_std: float | list[float] | None,
|
| 234 |
+
return_tensors: str | TensorType | None,
|
| 235 |
+
crop_to_patches: bool = False,
|
| 236 |
+
min_patches: int = 1,
|
| 237 |
+
max_patches: int = 12,
|
| 238 |
+
**kwargs,
|
| 239 |
+
) -> BatchFeature:
|
| 240 |
+
num_patches = []
|
| 241 |
+
processed_images = []
|
| 242 |
+
|
| 243 |
+
for image in images:
|
| 244 |
+
if crop_to_patches and max_patches > 1:
|
| 245 |
+
patches = self.crop_image_to_patches(
|
| 246 |
+
image,
|
| 247 |
+
min_patches,
|
| 248 |
+
max_patches,
|
| 249 |
+
patch_size=size,
|
| 250 |
+
resample=resample,
|
| 251 |
+
)
|
| 252 |
+
num_patches.append(len(patches))
|
| 253 |
+
# Normalize and rescale patches
|
| 254 |
+
for patch in patches:
|
| 255 |
+
if do_rescale:
|
| 256 |
+
patch = self.rescale(patch, rescale_factor)
|
| 257 |
+
if do_normalize:
|
| 258 |
+
patch = self.normalize(patch, image_mean, image_std)
|
| 259 |
+
processed_images.append(patch)
|
| 260 |
+
else:
|
| 261 |
+
num_patches.append(1)
|
| 262 |
+
if do_resize:
|
| 263 |
+
image = self.resize(image, size, resample)
|
| 264 |
+
if do_rescale:
|
| 265 |
+
image = self.rescale(image, rescale_factor)
|
| 266 |
+
if do_normalize:
|
| 267 |
+
image = self.normalize(image, image_mean, image_std)
|
| 268 |
+
processed_images.append(image)
|
| 269 |
+
|
| 270 |
+
return BatchFeature(
|
| 271 |
+
data={"pixel_values": processed_images, "num_patches": num_patches}, tensor_type=return_tensors
|
| 272 |
+
)
|
| 273 |
+
|
| 274 |
+
def get_number_of_image_patches(self, height: int, width: int, images_kwargs=None):
|
| 275 |
+
"""
|
| 276 |
+
A utility that returns number patches for a given image size.
|
| 277 |
+
|
| 278 |
+
Args:
|
| 279 |
+
height (`int`):
|
| 280 |
+
Height of the input image.
|
| 281 |
+
width (`int`):
|
| 282 |
+
Width of the input image.
|
| 283 |
+
images_kwargs (`dict`, *optional*)
|
| 284 |
+
Any kwargs to override defaults of the image processor.
|
| 285 |
+
Returns:
|
| 286 |
+
`int`: Number of patches per image.
|
| 287 |
+
"""
|
| 288 |
+
min_patches = images_kwargs.get("min_patches", self.min_patches) if images_kwargs else self.min_patches
|
| 289 |
+
max_patches = images_kwargs.get("max_patches", self.max_patches) if images_kwargs else self.max_patches
|
| 290 |
+
patch_size = images_kwargs.get("patch_size", self.size) if images_kwargs else self.size
|
| 291 |
+
crop_to_patches = (
|
| 292 |
+
images_kwargs.get("crop_to_patches", self.crop_to_patches) if images_kwargs else self.crop_to_patches
|
| 293 |
+
)
|
| 294 |
+
|
| 295 |
+
num_patches = 1
|
| 296 |
+
if crop_to_patches and max_patches > 1:
|
| 297 |
+
if isinstance(patch_size, dict):
|
| 298 |
+
patch_height, patch_width = patch_size["height"], patch_size["width"]
|
| 299 |
+
else:
|
| 300 |
+
patch_height, patch_width = patch_size.height, patch_size.width
|
| 301 |
+
num_columns, num_rows = get_optimal_tiled_canvas(
|
| 302 |
+
(height, width), (patch_height, patch_width), min_patches, max_patches
|
| 303 |
+
)
|
| 304 |
+
if num_columns * num_rows > 1:
|
| 305 |
+
num_patches += num_columns * num_rows
|
| 306 |
+
|
| 307 |
+
return num_patches
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
__all__ = ["GotOcr2ImageProcessorPil"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/got_ocr2/modular_got_ocr2.py
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2024 HuggingFace Inc. team. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
import torch
|
| 17 |
+
import torch.nn as nn
|
| 18 |
+
from huggingface_hub.dataclasses import strict
|
| 19 |
+
|
| 20 |
+
from ... import initialization as init
|
| 21 |
+
from ...cache_utils import Cache
|
| 22 |
+
from ...configuration_utils import PreTrainedConfig
|
| 23 |
+
from ...modeling_outputs import BaseModelOutputWithPooling
|
| 24 |
+
from ...modeling_utils import PreTrainedModel
|
| 25 |
+
from ...processing_utils import Unpack
|
| 26 |
+
from ...utils import TransformersKwargs, auto_docstring, can_return_tuple, logging
|
| 27 |
+
from ..auto import CONFIG_MAPPING, AutoConfig
|
| 28 |
+
from ..llava.modeling_llava import (
|
| 29 |
+
LlavaCausalLMOutputWithPast,
|
| 30 |
+
LlavaForConditionalGeneration,
|
| 31 |
+
LlavaModel,
|
| 32 |
+
LlavaModelOutputWithPast,
|
| 33 |
+
LlavaPreTrainedModel,
|
| 34 |
+
)
|
| 35 |
+
from ..sam.modeling_sam import (
|
| 36 |
+
SamMLPBlock,
|
| 37 |
+
SamPreTrainedModel,
|
| 38 |
+
SamVisionAttention,
|
| 39 |
+
SamVisionEncoder,
|
| 40 |
+
SamVisionLayer,
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
logger = logging.get_logger(__name__)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
@auto_docstring(checkpoint="facebook/sam-vit-huge")
|
| 48 |
+
@strict
|
| 49 |
+
class GotOcr2VisionConfig(PreTrainedConfig):
|
| 50 |
+
r"""
|
| 51 |
+
output_channels (`int`, *optional*, defaults to 256):
|
| 52 |
+
Dimensionality of the output channels in the Patch Encoder.
|
| 53 |
+
use_abs_pos (`bool`, *optional*, defaults to `True`):
|
| 54 |
+
Whether to use absolute position embedding.
|
| 55 |
+
use_rel_pos (`bool`, *optional*, defaults to `True`):
|
| 56 |
+
Whether to use relative position embedding.
|
| 57 |
+
window_size (`int`, *optional*, defaults to 14):
|
| 58 |
+
Window size for relative position.
|
| 59 |
+
global_attn_indexes (`list[int]`, *optional*, defaults to `[2, 5, 8, 11]`):
|
| 60 |
+
The indexes of the global attention layers.
|
| 61 |
+
mlp_dim (`int`, *optional*, defaults to 3072):
|
| 62 |
+
The dimensionality of the MLP layer in the Transformer encoder.
|
| 63 |
+
"""
|
| 64 |
+
|
| 65 |
+
base_config_key = "vision_config"
|
| 66 |
+
hidden_size: int = 768
|
| 67 |
+
output_channels: int = 256
|
| 68 |
+
num_hidden_layers: int = 12
|
| 69 |
+
num_attention_heads: int = 12
|
| 70 |
+
num_channels: int = 3
|
| 71 |
+
image_size: int | list[int] | tuple[int, int] = 1024
|
| 72 |
+
patch_size: int | list[int] | tuple[int, int] = 16
|
| 73 |
+
hidden_act: str = "gelu"
|
| 74 |
+
layer_norm_eps: float = 1e-06
|
| 75 |
+
attention_dropout: float | int = 0.0
|
| 76 |
+
initializer_range: float = 1e-10
|
| 77 |
+
qkv_bias: bool = True
|
| 78 |
+
use_abs_pos: bool = True
|
| 79 |
+
use_rel_pos: bool = True
|
| 80 |
+
window_size: int = 14
|
| 81 |
+
global_attn_indexes: list[int] | tuple[int, ...] = (2, 5, 8, 11)
|
| 82 |
+
mlp_dim: int = 3072
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
@auto_docstring(checkpoint="facebook/sam-vit-huge")
|
| 86 |
+
@strict
|
| 87 |
+
class GotOcr2Config(PreTrainedConfig):
|
| 88 |
+
r"""
|
| 89 |
+
Example:
|
| 90 |
+
|
| 91 |
+
```python
|
| 92 |
+
>>> from transformers import GotOcr2ForConditionalGeneration, GotOcr2Config
|
| 93 |
+
|
| 94 |
+
>>> # Initializing a GotOcr2 style configuration
|
| 95 |
+
>>> configuration = GotOcr2Config()
|
| 96 |
+
|
| 97 |
+
>>> # Initializing a model from the Qwen2-VL-7B style configuration
|
| 98 |
+
>>> model = GotOcr2ForConditionalGeneration(configuration)
|
| 99 |
+
|
| 100 |
+
>>> # Accessing the model configuration
|
| 101 |
+
>>> configuration = model.config
|
| 102 |
+
```"""
|
| 103 |
+
|
| 104 |
+
model_type = "got_ocr2"
|
| 105 |
+
attribute_map = {
|
| 106 |
+
"image_token_id": "image_token_index",
|
| 107 |
+
}
|
| 108 |
+
sub_configs = {"text_config": AutoConfig, "vision_config": GotOcr2VisionConfig}
|
| 109 |
+
|
| 110 |
+
vision_config: dict | PreTrainedConfig | None = None
|
| 111 |
+
text_config: dict | PreTrainedConfig | None = None
|
| 112 |
+
image_token_index: int = 151859
|
| 113 |
+
image_seq_length: int = 576
|
| 114 |
+
tie_word_embeddings: bool = True
|
| 115 |
+
|
| 116 |
+
def __post_init__(self, **kwargs):
|
| 117 |
+
if self.vision_config is None:
|
| 118 |
+
self.vision_config = GotOcr2VisionConfig()
|
| 119 |
+
elif isinstance(self.vision_config, dict):
|
| 120 |
+
self.vision_config = GotOcr2VisionConfig(**self.vision_config)
|
| 121 |
+
|
| 122 |
+
if isinstance(self.text_config, dict):
|
| 123 |
+
self.text_config["model_type"] = self.text_config.get("model_type", "qwen2")
|
| 124 |
+
self.text_config = CONFIG_MAPPING[self.text_config["model_type"]](**self.text_config)
|
| 125 |
+
elif self.text_config is None:
|
| 126 |
+
self.text_config = CONFIG_MAPPING["qwen2"](
|
| 127 |
+
vocab_size=151860,
|
| 128 |
+
hidden_size=1024,
|
| 129 |
+
intermediate_size=2816,
|
| 130 |
+
num_hidden_layers=24,
|
| 131 |
+
num_attention_heads=16,
|
| 132 |
+
num_key_value_heads=16,
|
| 133 |
+
hidden_act="silu",
|
| 134 |
+
max_position_embeddings=32768,
|
| 135 |
+
initializer_range=0.02,
|
| 136 |
+
rms_norm_eps=1e-6,
|
| 137 |
+
use_cache=True,
|
| 138 |
+
tie_word_embeddings=self.tie_word_embeddings,
|
| 139 |
+
rope_theta=1000000.0,
|
| 140 |
+
rope_parameters=None,
|
| 141 |
+
use_sliding_window=False,
|
| 142 |
+
sliding_window=4096,
|
| 143 |
+
max_window_layers=21,
|
| 144 |
+
attention_dropout=0.0,
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
super().__post_init__(**kwargs)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
class GotOcr2MLPBlock(SamMLPBlock):
|
| 151 |
+
pass
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
class GotOcr2VisionAttention(SamVisionAttention):
|
| 155 |
+
pass
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
class GotOcr2VisionLayer(SamVisionLayer):
|
| 159 |
+
def __init__(self, config, window_size):
|
| 160 |
+
super().__init__(config, window_size)
|
| 161 |
+
self.layer_norm1 = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
| 162 |
+
self.attn = GotOcr2VisionAttention(config, window_size)
|
| 163 |
+
self.layer_norm2 = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
| 164 |
+
self.mlp = GotOcr2MLPBlock(config)
|
| 165 |
+
self.window_size = window_size
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
class GotOcr2PreTrainedModel(SamPreTrainedModel):
|
| 169 |
+
input_modalities = ("image", "text")
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
class GotOcr2VisionEncoder(SamVisionEncoder, GotOcr2PreTrainedModel):
|
| 173 |
+
input_modalities = ("image",)
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
class GotOcr2MultiModalProjector(nn.Module):
|
| 177 |
+
def __init__(self, config: GotOcr2Config):
|
| 178 |
+
super().__init__()
|
| 179 |
+
vision_output_channels = config.vision_config.output_channels
|
| 180 |
+
language_hidden_size = config.text_config.hidden_size
|
| 181 |
+
self.conv_upsampler1 = nn.Conv2d(
|
| 182 |
+
vision_output_channels, vision_output_channels * 2, kernel_size=3, stride=2, padding=1, bias=False
|
| 183 |
+
)
|
| 184 |
+
self.conv_upsampler2 = nn.Conv2d(
|
| 185 |
+
vision_output_channels * 2, language_hidden_size, kernel_size=3, stride=2, padding=1, bias=False
|
| 186 |
+
)
|
| 187 |
+
self.multimodal_projector = nn.Linear(language_hidden_size, language_hidden_size)
|
| 188 |
+
|
| 189 |
+
def forward(self, vision_embeddings: torch.Tensor) -> torch.Tensor:
|
| 190 |
+
hidden_state = self.conv_upsampler1(vision_embeddings)
|
| 191 |
+
hidden_state = self.conv_upsampler2(hidden_state)
|
| 192 |
+
hidden_state = hidden_state.flatten(2).permute(0, 2, 1)
|
| 193 |
+
hidden_state = self.multimodal_projector(hidden_state)
|
| 194 |
+
return hidden_state
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
class GotOcr2CausalLMOutputWithPast(LlavaCausalLMOutputWithPast):
|
| 198 |
+
pass
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
class GotOcr2ModelOutputWithPast(LlavaModelOutputWithPast):
|
| 202 |
+
pass
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
class GotOcr2PreTrainedModel(LlavaPreTrainedModel):
|
| 206 |
+
_supports_flash_attn = False
|
| 207 |
+
_supports_sdpa = False
|
| 208 |
+
_supports_flex_attn = False
|
| 209 |
+
|
| 210 |
+
@torch.no_grad()
|
| 211 |
+
def _init_weights(self, module):
|
| 212 |
+
PreTrainedModel._init_weights(self, module)
|
| 213 |
+
if isinstance(module, GotOcr2VisionAttention):
|
| 214 |
+
if module.use_rel_pos:
|
| 215 |
+
init.zeros_(module.rel_pos_h)
|
| 216 |
+
init.zeros_(module.rel_pos_w)
|
| 217 |
+
elif isinstance(module, GotOcr2VisionEncoder):
|
| 218 |
+
if module.pos_embed is not None:
|
| 219 |
+
init.zeros_(module.pos_embed)
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
class GotOcr2Model(LlavaModel):
|
| 223 |
+
def __init__(self, config: GotOcr2Config):
|
| 224 |
+
super().__init__(config)
|
| 225 |
+
self.vision_tower = GotOcr2VisionEncoder(config.vision_config)
|
| 226 |
+
|
| 227 |
+
@can_return_tuple
|
| 228 |
+
@auto_docstring(
|
| 229 |
+
custom_intro="Obtains image last hidden states from the vision tower and apply multimodal projection."
|
| 230 |
+
)
|
| 231 |
+
def get_image_features(
|
| 232 |
+
self,
|
| 233 |
+
pixel_values: torch.FloatTensor,
|
| 234 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 235 |
+
) -> tuple | BaseModelOutputWithPooling:
|
| 236 |
+
image_outputs = self.vision_tower(pixel_values, return_dict=True, **kwargs)
|
| 237 |
+
last_hidden_state = image_outputs.last_hidden_state
|
| 238 |
+
image_outputs.pooler_output = self.multi_modal_projector(last_hidden_state)
|
| 239 |
+
|
| 240 |
+
return image_outputs
|
| 241 |
+
|
| 242 |
+
@can_return_tuple
|
| 243 |
+
@auto_docstring
|
| 244 |
+
def forward(
|
| 245 |
+
self,
|
| 246 |
+
input_ids: torch.LongTensor | None = None,
|
| 247 |
+
pixel_values: torch.FloatTensor | None = None,
|
| 248 |
+
attention_mask: torch.Tensor | None = None,
|
| 249 |
+
position_ids: torch.LongTensor | None = None,
|
| 250 |
+
past_key_values: Cache | None = None,
|
| 251 |
+
inputs_embeds: torch.FloatTensor | None = None,
|
| 252 |
+
use_cache: bool | None = None,
|
| 253 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 254 |
+
) -> tuple | GotOcr2ModelOutputWithPast:
|
| 255 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 256 |
+
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
| 257 |
+
|
| 258 |
+
if inputs_embeds is None:
|
| 259 |
+
inputs_embeds = self.get_input_embeddings()(input_ids)
|
| 260 |
+
|
| 261 |
+
if pixel_values is not None:
|
| 262 |
+
image_features = self.get_image_features(
|
| 263 |
+
pixel_values=pixel_values.to(inputs_embeds.dtype), return_dict=True
|
| 264 |
+
).pooler_output
|
| 265 |
+
image_features = image_features.to(inputs_embeds.device, inputs_embeds.dtype)
|
| 266 |
+
special_image_mask = self.get_placeholder_mask(
|
| 267 |
+
input_ids, inputs_embeds=inputs_embeds, image_features=image_features
|
| 268 |
+
)
|
| 269 |
+
inputs_embeds = inputs_embeds.masked_scatter(special_image_mask, image_features)
|
| 270 |
+
|
| 271 |
+
outputs = self.language_model(
|
| 272 |
+
attention_mask=attention_mask,
|
| 273 |
+
position_ids=position_ids,
|
| 274 |
+
past_key_values=past_key_values,
|
| 275 |
+
inputs_embeds=inputs_embeds,
|
| 276 |
+
use_cache=use_cache,
|
| 277 |
+
return_dict=True,
|
| 278 |
+
**kwargs,
|
| 279 |
+
)
|
| 280 |
+
|
| 281 |
+
return GotOcr2ModelOutputWithPast(
|
| 282 |
+
last_hidden_state=outputs.last_hidden_state,
|
| 283 |
+
past_key_values=outputs.past_key_values,
|
| 284 |
+
hidden_states=outputs.hidden_states,
|
| 285 |
+
attentions=outputs.attentions,
|
| 286 |
+
image_hidden_states=image_features if pixel_values is not None else None,
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
class GotOcr2ForConditionalGeneration(LlavaForConditionalGeneration):
|
| 291 |
+
@can_return_tuple
|
| 292 |
+
@auto_docstring
|
| 293 |
+
def forward(
|
| 294 |
+
self,
|
| 295 |
+
input_ids: torch.LongTensor | None = None,
|
| 296 |
+
pixel_values: torch.FloatTensor | None = None,
|
| 297 |
+
attention_mask: torch.Tensor | None = None,
|
| 298 |
+
position_ids: torch.LongTensor | None = None,
|
| 299 |
+
past_key_values: Cache | None = None,
|
| 300 |
+
inputs_embeds: torch.FloatTensor | None = None,
|
| 301 |
+
labels: torch.LongTensor | None = None,
|
| 302 |
+
use_cache: bool | None = None,
|
| 303 |
+
logits_to_keep: int | torch.Tensor = 0,
|
| 304 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 305 |
+
) -> tuple | GotOcr2CausalLMOutputWithPast:
|
| 306 |
+
r"""
|
| 307 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 308 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
| 309 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
| 310 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
| 311 |
+
|
| 312 |
+
Example:
|
| 313 |
+
|
| 314 |
+
```python
|
| 315 |
+
>>> from PIL import Image
|
| 316 |
+
>>> import httpx
|
| 317 |
+
>>> from io import BytesIO
|
| 318 |
+
>>> from transformers import AutoProcessor, GotOcr2ForConditionalGeneration, TextStreamer
|
| 319 |
+
|
| 320 |
+
>>> model = GotOcr2ForConditionalGeneration.from_pretrained("stepfun-ai/GOT-OCR-2.0-hf").to("cuda")
|
| 321 |
+
>>> processor = AutoProcessor.from_pretrained("stepfun-ai/GOT-OCR-2.0-hf")
|
| 322 |
+
|
| 323 |
+
>>> url = "https://huggingface.co/datasets/hf-internal-testing/fixtures_got_ocr/resolve/main/multi_box.png"
|
| 324 |
+
>>> with httpx.stream("GET", url) as response:
|
| 325 |
+
... image = Image.open(BytesIO(response.read()))
|
| 326 |
+
|
| 327 |
+
>>> inputs = processor(image, return_tensors="pt", color="green").to("cuda")
|
| 328 |
+
|
| 329 |
+
>>> # Generate
|
| 330 |
+
>>> streamer = TextStreamer(processor.tokenizer, skip_prompt=True, skip_special_tokens=True)
|
| 331 |
+
>>> generate_ids = model.generate(
|
| 332 |
+
... **inputs,
|
| 333 |
+
... do_sample=False,
|
| 334 |
+
... tokenizer = processor.tokenizer,
|
| 335 |
+
... stop_strings='<|im_end|>',
|
| 336 |
+
... streamer=streamer,
|
| 337 |
+
... max_new_tokens=4096,
|
| 338 |
+
... )
|
| 339 |
+
"You should keep in mind what features from the module should be used, especially
|
| 340 |
+
when you're planning to sell a template."
|
| 341 |
+
```"""
|
| 342 |
+
outputs = self.model(
|
| 343 |
+
input_ids=input_ids,
|
| 344 |
+
pixel_values=pixel_values,
|
| 345 |
+
attention_mask=attention_mask,
|
| 346 |
+
position_ids=position_ids,
|
| 347 |
+
past_key_values=past_key_values,
|
| 348 |
+
inputs_embeds=inputs_embeds,
|
| 349 |
+
use_cache=use_cache,
|
| 350 |
+
return_dict=True,
|
| 351 |
+
logits_to_keep=logits_to_keep,
|
| 352 |
+
**kwargs,
|
| 353 |
+
)
|
| 354 |
+
|
| 355 |
+
hidden_states = outputs[0]
|
| 356 |
+
# Only compute necessary logits, and do not upcast them to float if we are not computing the loss
|
| 357 |
+
slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
|
| 358 |
+
logits = self.lm_head(hidden_states[:, slice_indices, :])
|
| 359 |
+
|
| 360 |
+
loss = None
|
| 361 |
+
if labels is not None:
|
| 362 |
+
loss = self.loss_function(
|
| 363 |
+
logits=logits, labels=labels, vocab_size=self.config.text_config.vocab_size, **kwargs
|
| 364 |
+
)
|
| 365 |
+
|
| 366 |
+
return GotOcr2CausalLMOutputWithPast(
|
| 367 |
+
loss=loss,
|
| 368 |
+
logits=logits,
|
| 369 |
+
past_key_values=outputs.past_key_values,
|
| 370 |
+
hidden_states=outputs.hidden_states,
|
| 371 |
+
attentions=outputs.attentions,
|
| 372 |
+
image_hidden_states=outputs.image_hidden_states,
|
| 373 |
+
)
|
| 374 |
+
|
| 375 |
+
@auto_docstring
|
| 376 |
+
def get_image_features(
|
| 377 |
+
self, pixel_values: torch.FloatTensor, **kwargs: Unpack[TransformersKwargs]
|
| 378 |
+
) -> tuple | BaseModelOutputWithPooling:
|
| 379 |
+
return self.model.get_image_features(pixel_values=pixel_values, **kwargs)
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
__all__ = [
|
| 383 |
+
"GotOcr2VisionConfig",
|
| 384 |
+
"GotOcr2Config",
|
| 385 |
+
"GotOcr2PreTrainedModel",
|
| 386 |
+
"GotOcr2Model",
|
| 387 |
+
"GotOcr2ForConditionalGeneration",
|
| 388 |
+
]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/got_ocr2/processing_got_ocr2.py
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2024 HuggingFace Inc. team. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
import numpy as np
|
| 17 |
+
|
| 18 |
+
from ...image_processing_utils import BatchFeature
|
| 19 |
+
from ...image_utils import ImageInput
|
| 20 |
+
from ...processing_utils import ImagesKwargs, ProcessingKwargs, ProcessorMixin, TextKwargs, Unpack
|
| 21 |
+
from ...tokenization_utils_base import PreTokenizedInput, TextInput
|
| 22 |
+
from ...utils import auto_docstring, is_vision_available, logging
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
if is_vision_available():
|
| 26 |
+
from ...image_utils import load_images
|
| 27 |
+
|
| 28 |
+
logger = logging.get_logger(__name__)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class GotOcr2TextKwargs(TextKwargs, total=False):
|
| 32 |
+
"""
|
| 33 |
+
format (`bool`, *optional*, defaults to `False`):
|
| 34 |
+
Whether to request formatted output from the OCR model. When enabled, the model is instructed to return
|
| 35 |
+
structured and formatted text output rather than raw OCR results.
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
format: bool | None
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class GotOcr2ImagesKwargs(ImagesKwargs, total=False):
|
| 42 |
+
"""
|
| 43 |
+
crop_to_patches (`bool`, *optional*, defaults to `False`):
|
| 44 |
+
Whether to crop images into patches before processing. When enabled, large images are divided into
|
| 45 |
+
smaller patches for more efficient OCR processing.
|
| 46 |
+
min_patches (`int`, *optional*, defaults to `1`):
|
| 47 |
+
Minimum number of patches to generate when cropping images. This ensures that even small images are
|
| 48 |
+
processed with at least this many patches.
|
| 49 |
+
max_patches (`int`, *optional*, defaults to `12`):
|
| 50 |
+
Maximum number of patches to generate when cropping images. Large images will be divided into at most
|
| 51 |
+
this many patches to control computational complexity.
|
| 52 |
+
box (`list`, `tuple[float, float]`, or `tuple[float, float, float, float]`, *optional*):
|
| 53 |
+
Bounding box coordinates for OCR region of interest. Can be specified as a single box `[x1, y1, x2, y2]`
|
| 54 |
+
or a list of boxes. Coordinates are normalized to the range [0, 1000] based on the image dimensions.
|
| 55 |
+
If not provided, OCR is performed on the entire image.
|
| 56 |
+
color (`str`, *optional*):
|
| 57 |
+
Color filter specification for OCR. When provided, the OCR query is prefixed with the color information
|
| 58 |
+
to focus on text of a specific color (e.g., "red", "blue").
|
| 59 |
+
num_image_tokens (`int`, *optional*, defaults to `256`):
|
| 60 |
+
Number of image tokens (patches) to use per image. This controls the resolution of the image representation
|
| 61 |
+
passed to the model. Higher values provide more detail but increase computational cost.
|
| 62 |
+
multi_page (`bool`, *optional*, defaults to `False`):
|
| 63 |
+
Whether the input consists of multi-page documents. When enabled, images can be provided as nested lists
|
| 64 |
+
where each inner list represents a page, and OCR is performed across all pages with appropriate handling
|
| 65 |
+
of page boundaries.
|
| 66 |
+
"""
|
| 67 |
+
|
| 68 |
+
crop_to_patches: bool
|
| 69 |
+
min_patches: int
|
| 70 |
+
max_patches: int
|
| 71 |
+
box: list | tuple[float, float] | tuple[float, float, float, float] | None
|
| 72 |
+
color: str | None
|
| 73 |
+
num_image_tokens: int
|
| 74 |
+
multi_page: bool
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class GotOcr2ProcessorKwargs(ProcessingKwargs, total=False):
|
| 78 |
+
text_kwargs: GotOcr2TextKwargs
|
| 79 |
+
images_kwargs: GotOcr2ImagesKwargs
|
| 80 |
+
_defaults = {
|
| 81 |
+
"text_kwargs": {
|
| 82 |
+
"padding": False,
|
| 83 |
+
"format": False,
|
| 84 |
+
},
|
| 85 |
+
"images_kwargs": {
|
| 86 |
+
"num_image_tokens": 256,
|
| 87 |
+
"multi_page": False,
|
| 88 |
+
"crop_to_patches": False,
|
| 89 |
+
"min_patches": 1,
|
| 90 |
+
"max_patches": 12,
|
| 91 |
+
},
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def preprocess_box_annotation(box: list | tuple, image_size: tuple[int, int]) -> list:
|
| 96 |
+
"""
|
| 97 |
+
Convert box annotation to the format [x1, y1, x2, y2] in the range [0, 1000].
|
| 98 |
+
"""
|
| 99 |
+
width, height = image_size
|
| 100 |
+
if len(box) == 4:
|
| 101 |
+
box[0] = int(box[0] / width * 1000)
|
| 102 |
+
box[1] = int(box[1] / height * 1000)
|
| 103 |
+
box[2] = int(box[2] / width * 1000)
|
| 104 |
+
box[3] = int(box[3] / height * 1000)
|
| 105 |
+
else:
|
| 106 |
+
raise ValueError("Box must be a list or tuple of lists in the form [x1, y1, x2, y2].")
|
| 107 |
+
|
| 108 |
+
return list(box)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
@auto_docstring
|
| 112 |
+
class GotOcr2Processor(ProcessorMixin):
|
| 113 |
+
def __init__(self, image_processor=None, tokenizer=None, chat_template=None, **kwargs):
|
| 114 |
+
super().__init__(image_processor, tokenizer, chat_template=chat_template)
|
| 115 |
+
|
| 116 |
+
self.message_start_token = "<|im_start|>"
|
| 117 |
+
self.message_end_token = "<|im_end|>"
|
| 118 |
+
self.img_start_token = "<img>"
|
| 119 |
+
self.img_end_token = "</img>"
|
| 120 |
+
self.img_pad_token = "<imgpad>"
|
| 121 |
+
self.image_token = "<imgpad>" # keep the above for BC, but we need to call it `image_token`
|
| 122 |
+
self.image_token_id = tokenizer.convert_tokens_to_ids(self.image_token)
|
| 123 |
+
self.system_query = "system\nYou should follow the instructions carefully and explain your answers in detail."
|
| 124 |
+
|
| 125 |
+
def _make_list_of_inputs(self, images, text, box, color, multi_page):
|
| 126 |
+
if not isinstance(images, (list, tuple)):
|
| 127 |
+
images = [images]
|
| 128 |
+
if multi_page:
|
| 129 |
+
logger.warning("Multi-page inference is enabled but only one image is passed.")
|
| 130 |
+
images = [images]
|
| 131 |
+
elif isinstance(images[0], (list, tuple)) and not multi_page:
|
| 132 |
+
raise ValueError("Nested images are only supported with `multi_page` set to `True`.")
|
| 133 |
+
elif not isinstance(images[0], (list, tuple)) and multi_page:
|
| 134 |
+
images = [images]
|
| 135 |
+
|
| 136 |
+
if isinstance(text, str):
|
| 137 |
+
text = [text]
|
| 138 |
+
|
| 139 |
+
if not isinstance(box[0], (list, tuple)):
|
| 140 |
+
# Use the same box for all images
|
| 141 |
+
box = [box for _ in range(len(images))]
|
| 142 |
+
if not isinstance(color, (list, tuple)):
|
| 143 |
+
color = [color for _ in range(len(images))]
|
| 144 |
+
|
| 145 |
+
return images, text, box, color
|
| 146 |
+
|
| 147 |
+
@auto_docstring
|
| 148 |
+
def __call__(
|
| 149 |
+
self,
|
| 150 |
+
images: ImageInput | None = None,
|
| 151 |
+
text: TextInput | PreTokenizedInput | list[TextInput] | list[PreTokenizedInput] | None = None,
|
| 152 |
+
**kwargs: Unpack[GotOcr2ProcessorKwargs],
|
| 153 |
+
) -> BatchFeature:
|
| 154 |
+
r"""
|
| 155 |
+
Returns:
|
| 156 |
+
[`BatchFeature`]: A [`BatchFeature`] with the following fields:
|
| 157 |
+
|
| 158 |
+
- **input_ids** -- List of token ids to be fed to a model. Returned when `text` is not `None`.
|
| 159 |
+
- **attention_mask** -- List of indices specifying which tokens should be attended to by the model (when
|
| 160 |
+
`return_attention_mask=True` or if *"attention_mask"* is in `self.model_input_names` and if `text` is not
|
| 161 |
+
`None`).
|
| 162 |
+
- **pixel_values** -- Pixel values to be fed to a model. Returned when `images` is not `None`.
|
| 163 |
+
"""
|
| 164 |
+
|
| 165 |
+
output_kwargs = self._merge_kwargs(
|
| 166 |
+
GotOcr2ProcessorKwargs,
|
| 167 |
+
tokenizer_init_kwargs=self.tokenizer.init_kwargs,
|
| 168 |
+
**kwargs,
|
| 169 |
+
)
|
| 170 |
+
format_output = output_kwargs["text_kwargs"].pop("format")
|
| 171 |
+
num_image_tokens = output_kwargs["images_kwargs"].pop("num_image_tokens")
|
| 172 |
+
box = output_kwargs["images_kwargs"].pop("box", [None])
|
| 173 |
+
color = output_kwargs["images_kwargs"].pop("color", None)
|
| 174 |
+
multi_page = output_kwargs["images_kwargs"].pop("multi_page")
|
| 175 |
+
|
| 176 |
+
crop_to_patches = output_kwargs["images_kwargs"].get("crop_to_patches")
|
| 177 |
+
images, text, box, color = self._make_list_of_inputs(images, text, box, color, multi_page)
|
| 178 |
+
if multi_page:
|
| 179 |
+
# save the number of pages per batch
|
| 180 |
+
num_pages_per_batch = [len(image_group) for image_group in images]
|
| 181 |
+
# flatten the list of images
|
| 182 |
+
images = [image for image_group in images for image in image_group]
|
| 183 |
+
else:
|
| 184 |
+
num_pages_per_batch = [1 for _ in range(len(images))]
|
| 185 |
+
# Load images as we need to know the image size
|
| 186 |
+
images = load_images(images)
|
| 187 |
+
image_sizes = [image.size for image in images]
|
| 188 |
+
image_inputs = self.image_processor(images=images, **output_kwargs["images_kwargs"])
|
| 189 |
+
num_patches_array = image_inputs.pop("num_patches")
|
| 190 |
+
if text is None:
|
| 191 |
+
text = []
|
| 192 |
+
patch_indices = np.cumsum(num_pages_per_batch)
|
| 193 |
+
for index, (num_pages, box_single, color_single) in enumerate(zip(num_pages_per_batch, box, color)):
|
| 194 |
+
current_patch_index = patch_indices[index - 1] if index > 0 else 0
|
| 195 |
+
num_patches = sum(num_patches_array[current_patch_index : current_patch_index + num_pages])
|
| 196 |
+
if box_single[0] is not None:
|
| 197 |
+
box_single = preprocess_box_annotation(box_single, image_sizes[index])
|
| 198 |
+
query = (
|
| 199 |
+
f"{f'[{color_single}] ' if color_single is not None else ''}"
|
| 200 |
+
f"{str(box_single) if box_single[0] is not None else ''} "
|
| 201 |
+
"OCR"
|
| 202 |
+
f"{' with format' if format_output else ''}"
|
| 203 |
+
f"{' across multi pages' if multi_page else ''}"
|
| 204 |
+
f"{' upon the patch reference' if crop_to_patches else ''}"
|
| 205 |
+
": "
|
| 206 |
+
)
|
| 207 |
+
prompt = (
|
| 208 |
+
self.message_start_token
|
| 209 |
+
+ self.system_query
|
| 210 |
+
+ self.message_end_token
|
| 211 |
+
+ self.message_start_token
|
| 212 |
+
+ "user\n"
|
| 213 |
+
+ self.img_start_token
|
| 214 |
+
+ self.img_pad_token * num_image_tokens * num_patches
|
| 215 |
+
+ self.img_end_token
|
| 216 |
+
+ "\n"
|
| 217 |
+
+ query
|
| 218 |
+
+ self.message_end_token
|
| 219 |
+
+ self.message_start_token
|
| 220 |
+
+ "assistant\n"
|
| 221 |
+
)
|
| 222 |
+
text.append(prompt)
|
| 223 |
+
|
| 224 |
+
return_tensors = output_kwargs["text_kwargs"].pop("return_tensors", None)
|
| 225 |
+
text_inputs = self.tokenizer(text, **output_kwargs["text_kwargs"])
|
| 226 |
+
self._check_special_mm_tokens(text, text_inputs, modalities=["image"])
|
| 227 |
+
|
| 228 |
+
return BatchFeature(data={**text_inputs, **image_inputs}, tensor_type=return_tensors)
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
__all__ = ["GotOcr2Processor"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/moonshine/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2025 The HuggingFace Team. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
from typing import TYPE_CHECKING
|
| 15 |
+
|
| 16 |
+
from ...utils import _LazyModule
|
| 17 |
+
from ...utils.import_utils import define_import_structure
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
if TYPE_CHECKING:
|
| 21 |
+
from .configuration_moonshine import *
|
| 22 |
+
from .modeling_moonshine import *
|
| 23 |
+
else:
|
| 24 |
+
import sys
|
| 25 |
+
|
| 26 |
+
_file = globals()["__file__"]
|
| 27 |
+
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/runs/dirichlet_numeric_sim_old_vs_log_v32100_s128.csv
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
vocab=32100 samples=128 C=1.0->1024.0 device=cuda target=1
|
| 2 |
+
t,c,alpha_target,alpha_non_target,old_raw_g_below_1e-8,old_p_zero_frac,log_g_nonfinite_frac,log_p_zero_frac,old_target_mean,log_target_mean,old_entropy_mean,log_entropy_mean,old_top_target_frac,log_top_target_frac,old_emb_l2_to_mean,log_emb_l2_to_mean,mean_emb_l2_old_vs_log
|
| 3 |
+
0.000,1,3.11526e-05,3.11526e-05,0.999433,0.000000,0.000000,0.996774,0.000000,0.000000,1.051059,0.977972,0.000000,0.000000,0.686867,0.700737,0.989373
|
| 4 |
+
0.001,1.00696,0.00103829,3.1338e-05,0.999429,0.000000,0.000000,0.996751,0.000947,0.000017,1.056590,0.981897,0.000000,0.000000,0.685100,0.699690,0.987289
|
| 5 |
+
0.010,1.07177,0.0107508,3.30547e-05,0.999395,0.000000,0.000000,0.996564,0.007713,0.003211,1.087266,1.023427,0.000000,0.000000,0.673804,0.688418,0.971353
|
| 6 |
+
0.050,1.41421,0.0707525,4.18537e-05,0.999210,0.000000,0.000000,0.995653,0.025586,0.048411,1.254443,1.211471,0.007812,0.031250,0.627183,0.633667,0.899046
|
| 7 |
+
0.100,2,0.200056,5.60748e-05,0.998959,0.000000,0.000000,0.994213,0.069044,0.099894,1.499430,1.436666,0.039062,0.125000,0.561897,0.569334,0.806829
|
| 8 |
+
0.250,5.65685,1.41435,0.000132169,0.997642,0.000000,0.000000,0.986620,0.252017,0.245821,2.090487,2.048243,0.507812,0.445312,0.365040,0.378998,0.491217
|
| 9 |
+
0.500,32,16.0005,0.000498442,0.991163,0.000000,0.000000,0.951413,0.498356,0.492434,2.366313,2.380998,1.000000,1.000000,0.148980,0.152542,0.188174
|
| 10 |
+
0.750,181.019,135.766,0.00140981,0.975175,0.000000,0.000000,0.870699,0.750778,0.746908,1.651484,1.670976,1.000000,1.000000,0.048614,0.048720,0.063642
|
| 11 |
+
0.900,512,460.802,0.00159502,0.971988,0.000000,0.000000,0.856373,0.900468,0.898712,0.771760,0.782816,1.000000,1.000000,0.018904,0.018869,0.025504
|
| 12 |
+
0.990,955.426,945.872,0.00029764,0.994694,0.000000,0.000000,0.971638,0.989913,0.989733,0.085018,0.085953,1.000000,1.000000,0.004177,0.004542,0.005748
|
| 13 |
+
0.999,1016.93,1015.91,3.168e-05,0.999395,0.000000,0.000000,0.996928,0.998994,0.998903,0.008652,0.009190,1.000000,1.000000,0.001085,0.001234,0.001510
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/runs/dirichlet_numeric_sim_v32100_s128.csv
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
vocab=32100 samples=128 C=1.0->1024.0 device=cuda target=1
|
| 2 |
+
t,c,alpha_target,alpha_non_target,native_g_zero_frac,native_p_zero_frac,log_g_nonfinite_frac,log_p_zero_frac,native_target_mean,log_target_mean,native_entropy_mean,log_entropy_mean,native_top_target_frac,log_top_target_frac,native_emb_l2_to_mean,log_emb_l2_to_mean,mean_emb_l2_native_vs_log
|
| 3 |
+
0.000,1,3.11526e-05,3.11526e-05,0.000000,0.000000,0.000000,0.996774,0.000000,0.000000,1.007299,0.977972,0.000000,0.000000,0.689184,0.700737,0.991104
|
| 4 |
+
0.001,1.00696,0.00103829,3.1338e-05,0.000000,0.000000,0.000000,0.996751,0.000947,0.000017,1.013896,0.981897,0.000000,0.000000,0.687334,0.699690,0.988957
|
| 5 |
+
0.010,1.07177,0.0107508,3.30547e-05,0.000000,0.000000,0.000000,0.996564,0.007714,0.003211,1.052980,1.023427,0.000000,0.000000,0.675541,0.688418,0.972662
|
| 6 |
+
0.050,1.41421,0.0707525,4.18537e-05,0.000000,0.000000,0.000000,0.995653,0.025615,0.048411,1.240227,1.211471,0.007812,0.031250,0.627777,0.633667,0.899489
|
| 7 |
+
0.100,2,0.200056,5.60748e-05,0.000000,0.000000,0.000000,0.994213,0.069085,0.099894,1.493398,1.436666,0.039062,0.125000,0.562099,0.569334,0.806974
|
| 8 |
+
0.250,5.65685,1.41435,0.000132169,0.000000,0.000000,0.000000,0.986620,0.252034,0.245821,2.089214,2.048243,0.507812,0.445312,0.365058,0.378998,0.491233
|
| 9 |
+
0.500,32,16.0005,0.000498442,0.000000,0.000000,0.000000,0.951413,0.498361,0.492434,2.366103,2.380998,1.000000,1.000000,0.148984,0.152542,0.188176
|
| 10 |
+
0.750,181.019,135.766,0.00140981,0.000000,0.000000,0.000000,0.870699,0.750780,0.746908,1.651444,1.670976,1.000000,1.000000,0.048614,0.048720,0.063642
|
| 11 |
+
0.900,512,460.802,0.00159502,0.000000,0.000000,0.000000,0.856373,0.900468,0.898712,0.771744,0.782816,1.000000,1.000000,0.018904,0.018869,0.025504
|
| 12 |
+
0.990,955.426,945.872,0.00029764,0.000000,0.000000,0.000000,0.971638,0.989913,0.989733,0.085010,0.085953,1.000000,1.000000,0.004177,0.004542,0.005748
|
| 13 |
+
0.999,1016.93,1015.91,3.168e-05,0.000000,0.000000,0.000000,0.996928,0.998994,0.998903,0.008644,0.009190,1.000000,1.000000,0.001085,0.001234,0.001510
|