Add files using upload-large-folder tool
Browse files- LTA_openwebtext_dualt/docs/lta_samples/metrics_20260517/decode_timegrid_trace_len256_copied_ckpt/onehot/trace_uniform_steps1024/step_metrics.csv +0 -0
- LTA_openwebtext_dualt/docs/lta_samples/metrics_20260517/owt_t5_linearsoftkl_latest_step86000_latedebias0p7_uniformtime_dualline_steps128_c1024_n8_noscore/genppl_large.json +6 -0
- LTA_openwebtext_dualt/docs/lta_samples/metrics_20260517/train8_overfit_20260517_train8_overfit_ode_infer/train8_n1024_hard_ce_onehot_20260517_train8_overfit_none/summary.json +55 -0
- LTA_openwebtext_dualt/docs/lta_samples/metrics_20260517/train8_overfit_20260517_train8_overfit_ode_infer/train8_n1024_linear_soft_kl_onehot_20260517_train8_overfit_uniform/context1024_samples.txt +29 -0
- LTA_openwebtext_dualt/docs/lta_samples/metrics_20260517/train8_overfit_20260517_train8_overfit_ode_infer/train8_n1024_linear_soft_kl_onehot_20260517_train8_overfit_uniform/context1024_trace.json +354 -0
- LTA_openwebtext_dualt/docs/lta_samples/metrics_20260517/train8_overfit_20260517_train8_overfit_ode_infer/train8_n1024_linear_soft_kl_onehot_20260517_train8_overfit_uniform/summary.json +55 -0
- LTA_openwebtext_dualt/logs/infer/lta_owt_classic_fullvocab_bert_c1024_len1024_large_d1024_l24_h16_ff4096_lr2e-4_gbs2048_2node8gpu_1m_save10k_t-20260522101129-lwll5_latest_step0012000_shard02_gpu2_b32.log +10 -0
- LTA_openwebtext_dualt/logs/infer/lta_owt_lm1bclassic_fullvocab_bert_c1024_len1024_elfLdim_d1280_l32_h16_ff5120_lr3e-4_gbs512_2node8gpu_1m_save10k_t-20260522071024-s2ss5_latest_step0001000_t1p45_c1024_n1024_gpu0.log +6 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/dependency_versions_check.py +62 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/initialization.py +333 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/granite_speech_plus/__init__.py +27 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/granite_speech_plus/configuration_granite_speech_plus.py +176 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/granite_speech_plus/modeling_granite_speech_plus.py +622 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/granite_speech_plus/modular_granite_speech_plus.py +172 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/granitemoe/configuration_granitemoe.py +84 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/granitemoe/modular_granitemoe.py +316 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/llava/__init__.py +30 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/processing_utils.py +0 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/pytorch_utils.py +260 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/trainer_optimizer.py +615 -0
LTA_openwebtext_dualt/docs/lta_samples/metrics_20260517/decode_timegrid_trace_len256_copied_ckpt/onehot/trace_uniform_steps1024/step_metrics.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
LTA_openwebtext_dualt/docs/lta_samples/metrics_20260517/owt_t5_linearsoftkl_latest_step86000_latedebias0p7_uniformtime_dualline_steps128_c1024_n8_noscore/genppl_large.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"gen_ppl": 2913.532847576075,
|
| 3 |
+
"gen_nll": 7.97712166078629,
|
| 4 |
+
"gen_tokens": 8184,
|
| 5 |
+
"gen_ppl_scorer": "/e2e-data/evad-tech-vla/wanghan58/models/flowtext_scorers/gpt2-large-standard"
|
| 6 |
+
}
|
LTA_openwebtext_dualt/docs/lta_samples/metrics_20260517/train8_overfit_20260517_train8_overfit_ode_infer/train8_n1024_hard_ce_onehot_20260517_train8_overfit_none/summary.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"checkpoint": "runs/train8_n1024_hard_ce_onehot_20260517_train8_overfit/step_0001000.pt",
|
| 4 |
+
"ckpt_step": 1000,
|
| 5 |
+
"max_len": 1024,
|
| 6 |
+
"decode_rule": "flowmap",
|
| 7 |
+
"support_power": 1.0,
|
| 8 |
+
"semantic_power": 1.0,
|
| 9 |
+
"steps": 128,
|
| 10 |
+
"c_min": 1.0,
|
| 11 |
+
"c_max": 512.0,
|
| 12 |
+
"model_t_mode": "post",
|
| 13 |
+
"time_schedule": "logit_normal",
|
| 14 |
+
"time_logit_mean": -1.5,
|
| 15 |
+
"time_logit_std": 0.8,
|
| 16 |
+
"time_power": 2.0,
|
| 17 |
+
"input_noise_scale": 0.0,
|
| 18 |
+
"input_noise_until": 1.0,
|
| 19 |
+
"input_noise_dirichlet_concentration": 1.0,
|
| 20 |
+
"endpoint_softening": "none",
|
| 21 |
+
"endpoint_soft_power": 1.0,
|
| 22 |
+
"endpoint_soft_min_conf": 0.0,
|
| 23 |
+
"endpoint_soft_max_conf": 1.0,
|
| 24 |
+
"final_from": "state",
|
| 25 |
+
"final_decode": "argmax",
|
| 26 |
+
"final_sample_temp": 1.0,
|
| 27 |
+
"final_top_k": 0,
|
| 28 |
+
"final_top_p": 1.0,
|
| 29 |
+
"early_temp": 1.0,
|
| 30 |
+
"late_temp": 1.0,
|
| 31 |
+
"temp_end": 1.0,
|
| 32 |
+
"temp_power": 1.0,
|
| 33 |
+
"pos_extend": "repeat",
|
| 34 |
+
"fixed_first_token_id": null,
|
| 35 |
+
"fixed_first_token_text": "",
|
| 36 |
+
"fixed_first_initial_argmax": false,
|
| 37 |
+
"use_ema": false,
|
| 38 |
+
"n_samples": 8,
|
| 39 |
+
"sample_entropy": 3.0918080879465375,
|
| 40 |
+
"unique_tokens": 177,
|
| 41 |
+
"token_count": 8192,
|
| 42 |
+
"distinct_1": 0.0216064453125,
|
| 43 |
+
"distinct_2": 0.13379765395894427,
|
| 44 |
+
"top_token_mass": 0.136474609375,
|
| 45 |
+
"texts_preview": [
|
| 46 |
+
"the the<|endoftext|><|endoftext|><|endoftext|> the<|endoftext|> the one the of the the of the on the the Bill one the the Bill the the the the the the the the the the the the the the the one the the the the the the the the the theThe the the the the the the the the theThe theThe theThe the itThe theThe theTheThe it itThe itThe the it theThe itThe in it itThe it itThe it it it itThe it it from it it it it it from it in from it it it in from from from it in from from it from it from from from from from from from from from from from from from the the from from from from from from from from from from a from from from from from the from from from the without from from from from the from from it from from from from the from the from from the the from from the from the from the from of the from from from from the without the from the from the the from the from the from the the from many from the the from from from it from from many the many many from from many many from from from many in, to many many many in in from in manyCNN many in many in in in) inCNN), inowsowsows inows, in in,,ows,,ows who,ows,, who,,ows 2016 2016,, who Muellerowsows 2016ows,ows,ows,, in whoowsows inows,ows, Mueller, meeting Tuesdayows, meeting Mueller,,limowsows counselows,,,,owslim, Mueller,ows, like likeows like,lim Mueller report 2016 like like Butows 2016 like 2016 Butlim, Butlim 2016, But, Muellerows But, Mueller to 2016 2016 Mueller 2016 2016 to in But But But Mueller 2016 a 2016 But 2016 But lawyer a a to to 2016 with Jr to to 2016 2016 2016 2016 But to 2016 to 2016 2016 to Mueller Mueller to to Mueller trail 2016 to to to, to 2016 2016 to 2016 while work while to while while could to work and could while while to while work work work politically panel work work about work -- politically work work about about and about about about about about about work about could about about legally about who about who about about about work a who and who who a and who about who work who White who White legally who a whoA a about a who. who who who White who President. .. who White about. about. who. White ... insky. who.. . President the. frominsky.inskyinsky about us's about about about's from's Mueller's about about Friday about's interview about interview,,,,,, Mueller,,,,'s,,,,,,,,,,,'s,,,,,ime,,,,,,,,,,, Mueller,,,,,, Mueller,,,,,,,,,,'s noted,,,,,,'s,,,,, of,'s,,,'s on on,,,, on, on on on on,'s an's testimony's, on's,'s's on's's's on's's's's's's his over's's the's's's's's's's the's's's's's's and's's's day out the's's's the's's's's's's out out's's out's's's's's's's's's the's's's out's's's's's's's's's's's the's's's's's's's's's's's's's's's's the's the's the's's of the's's the's the's's the the of the's the's the's's the, the the the the the the the the the the of the get's of get the the thegggg thegg of,gg of, of in of Russia, should in,,, the of Affairs of that of of of should of, of the, of act thegg of of, Affairs of of of of of of that of Starr of of of of of, of of as not of of, of of know, of of not of of of of of of of not not, was of as as, not of of of was of, not was was of was was was of was as not of was not not of of of was a of was of not was be not was not, of was, was no was was that of have was have was that that is was was not was not that not that that that not is have that not no not was that most not that is that that that that is have is not is that is is is that that is that is ( is that not that whether is is is (",
|
| 47 |
+
"the<|endoftext|><|endoftext|> the the<|endoftext|> Today the Bill the the<|endoftext|> the of the the on the the the the the the the the the the the the the the the the the the the the the the the the of the the the the the the the of the theThe theTheThe theThe the the theThe itThe theTheThe the theThe theThe theThe itThe theThe it itTheTheThe it the itThe it it from it it it it from it it it it it from it it in was it it from it it in in from from it it from it it from in from from from from from it it it from from from from it from from from from from from from from from from from the from from from from from from from the the from the from from from from from Brooklyn from from in without from from from from from from from from<|endoftext|> the from the from from from the in from from the from from the from from the from without from from from from the from from from the from from from from from from the from from from from many from from from from from in in many the many from it from many many many many many many many in manyCNN in in to it in in in inCNN many in it in, Donald comes,,ows, Mueller,,,owsows,,,ows,,, had,,ows,, 2016owsows 2016 Mueller on,ows 2016 2016,, feel whoows 2016,owsowsows,,ows,,,, like,owsows who,, 2016 who,ows, like like like meeting But, to Butows who, like,lim But, likeows like on But meeting Butlim 2016 But on, 2016 Butlim But,, 2016 on to But Mueller to But 2016 But the But to on, like But Mueller But with 2016 But Mueller 2016 like to 2016 that to on on to Mueller to on But some Mueller 2016 Mueller to on to while to 2016 to 2016 very to very to Mueller some to while to while to who to while to to a a to while who some who to who work work while a work work and work while a and work some to who work a while and about work about about about who some about a work about and about and a about who who about who a about who about who about legally a work about about about who about about politically who -- at who who who who about White who who who who who at at who who submitted about White White who who who about who White about who about.. White .. who about. insky... President.insky.insky who... aboutinskyinsky about aboutinsky from'sinskyinsky's about Mueller about, from Friday about interview about interview Mueller's, about,,,,,,,,,,,,,,,,,, But,,'s,,, danger,,,,,ly,,,,,,,,,,,,,,,,,,,,,,,,, Mueller's,, the,,,,,, Mueller,,,, Mueller,,, on Mueller,'s,,,,'s on on's, his's,'s's's his Starr of on a's's's's's his's's's's's's's's's's's's's's the's's's's's's,'s's's's's's's's's's and's's over's's's's's's's's's's's's's's's's the's's's's's's's's's's's's's's's's's's's's's's's's's's's the's's They's's's's the's's's's the's the the's's's the's's's the's the's the's the that hired the the's the the the's the's of the hired the's of of Russia the the, of of the the the of,'s,, the the thegg of, of of,gg of not that the of, of the of of powers of that of of not of of, of by of of of of of of of, of of of of of of ( not of not ( of of of not ( of ( of of of ( of of of of ( of not of of of of of of of of of of sex not of of of of as not of of of not, not not of sex was not was of not of not is was not be not be, not is not, not was not of that, was not, have be not that be was that not was have no was on was, that of the not a to is not that is on that ( is is that not not is not one not on is that is is is most that is that is is is is that is is that that is ( that (",
|
| 48 |
+
"<|endoftext|> the<|endoftext|><|endoftext|>�<|endoftext|><|endoftext|><|endoftext|><|endoftext|><|endoftext|><|endoftext|><|endoftext|> the<|endoftext|> the<|endoftext|> the<|endoftext|> the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the out the the Brooklyn the the the the the the the of�� Brooklyn Brooklyn plan the the thes the it Brooklyn inThe the it Brooklyn it it in it it it it it it it it it it it it it it it� it it it it it it it it it it it in it it from it it it it it it it it it it it it it it it it it it it it was it it it from from from from it it from from the it it from from it from from� it from from it it from it the from the from from from from from it from from from from it from from from from from it from it from from from it from from from from from from it from from from from the from from the from from from from from concept from from from from from from from from from from from from from from from from from from from from into from from from from to the from in many in from into into to from many the in,, in in in in,,,,,,,,,,,,,ows, the,,,,,,,,,,,,,,,, to,,,,,,,, in,,,,,,, on,,,,, in,, in,,, like,lim,,,, But,,,,, in, like,,,,, on like like ButWhat who,, like But, But,, on on, on But But, on on and on on on on on But on, on But on on, But on But But on, with on on on on, on, to on on with with on on with while that of Mueller the some on to on to work will work work no while some some work a to some a work work work work work work about work work in work work a work work work work work work work and work work work a work work some work work work work a work work work a work very work work work a work work work, work work work work work as some work a as work who work work by a who work House White who . ch. . from . .. President. . from from.. from the from from from frominsky from from from from from from from an from an, from from,, that, Mueller,, Mueller's,,,,,,,,,,,,,,,,,,,,, of,, But,,,,,,, But,,,,,, of,,,,,,,,,,,,,,,,, of,,,,, an, of an's,,,,,, a's,,, .,, on's on the a took a on took his a's his over a a a a's White's his a's out out White White's out out White out over over's out's's out over's out out over out over's over and over over over out out out out's over the's out over out out out over out's the the out's's the out the out the's the the's the the the the's the the's's the the the the the the the the the's the the was the's the the the the the because the the the's's the the the's the the the the the the the's the the the the the states the the the the the the the the the the the, the the of the, of the the the a of the of the of the of the the of of of of the the the of of of of of the of of of of of ( of of of ofex a of ( of ( a ofex the of that of of of of of of ofAY ( of of of ( a of of of ( of ( of large sex ( of of ( of ( of not.\" not of of, of ( of was of of of of in, not of of the of of, was, of not of of that that be be not was, not of of problem of, on was was not that was was was was be be not was is that is not that is was that.\" was be not not \" was was that, that that that that that that ( that not not that ( is that that is that is that that that that a is that that ( that that that that that that ( that",
|
| 49 |
+
"the the<|endoftext|> that,<|endoftext|><|endoftext|> the that<|endoftext|><|endoftext|> the<|endoftext|><|endoftext|> the<|endoftext|><|endoftext|><|endoftext|> the the that the<|endoftext|> the the that that<|endoftext|> the the the that that that the the that that the that the that the the that the the that the the out. the. out of the the the out that that the the in. the that. in., the. in of the.. that for. it in. it it the of of is. it elect the of the is it it is it it it is in it it it it it is it to it is it it it it it it it it it it it it it it it it it is it it an it from from from from from and from from it from from from it from from from from from from it from from from it from from from from from from from from and from from from from from from from from from from from threat from from from from from from from from is in from from from from from from from from from in from from from from from from from from to from from from from from from from from from from from from is into to into to to in is to to to into, into, into by into to from,,, the, in, going,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, on, But,,,,,,, on on on, on,, to of of, of,, on on on But of, on of on on on, of on on But on, on on of, on on on of of on of of of of of of of, on of but on of of on on on of the on of of on on on of on on on on of of of on of on of of on of of of of of, of of on on on of on of on on on on their on safe no as with on work on no no no work work work as had had work as work as work work work work work work work work work work as as work work as and work work work work work work work work that work work work work work ing work work work work work work work work work roughly work many many work work work from work work very very work many from it from from from from work from from from work. from from from from from. from from from from from from from from from from from from from from from from from from from from from from from from from from an an to an an an from an from an an an an from But But an an an an an new an of an and an of an of of of of of an an of of and an an, of an Ken and it of of of of and and of Ken message,, a a, and and of of an, of of and of and message it.,., it of and over, a. a a. a message a a a. and and a. the and. a. a and a.. a , a a a was a a.. a a the. a. a a,...,.,..,. a.. a.... the over the over in , over,, over the over over,, over the the the,, to in the, the, the the the the, the the the the the the the the, the the the the the, the, the the to the the the the in the the the the the the, the the the, the the the the the the the the the the the the the the the the the will the the the the the the will will the the the the the the the been the the that will the the the the the the the the the the the the the the the that the the the of of to the same of a a do the like a a a a that that the that to of a a of a a that a the a a a a a a a a a a a a a a a a a a a a of of a of of a a a a a a of a a of a a of a a a of a of a a a a a of free a of a a a a a a a a a a of a , of a, a, a a a a a a a the a a a a member a ar a a a a a of a a a are the member a a of a a a a a"
|
| 50 |
+
],
|
| 51 |
+
"gen_ppl": 29.86571106300112,
|
| 52 |
+
"gen_nll": 3.3967110351424585,
|
| 53 |
+
"gen_tokens": 7081
|
| 54 |
+
}
|
| 55 |
+
]
|
LTA_openwebtext_dualt/docs/lta_samples/metrics_20260517/train8_overfit_20260517_train8_overfit_ode_infer/train8_n1024_linear_soft_kl_onehot_20260517_train8_overfit_uniform/context1024_samples.txt
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
the the a...... the on to.. in with. . strategy. in to in been. in. in the in .... the. .. confront... in in to. . the of the a. the the.. . in in . a. . is .. the . in in in in. in in.. mark.s in a� leaving of the A in the in victims in.. in in-... he the. a the of night the in the in. been in., the a . really the in. in the in in. AN in.. been thiss. . in.... the in in�. . the exp nobody a of.. in of.. its in in a in� inm . in. again in. the the the in in to in. –. been. the a in in. trusted- in a in .. in the theAlso a in the in the ,. the the in in . . in.. night in. and the in . in in the in. in to in a in..... . in the initer start in.. the best. when Tuesday. to otherwise . a the in in in in in .....s..... . the reportball, the in as to in. .. of.. in in the. the toities. and a . in the. in the the ref... in and, a. in the- .. in.� to in in in,. a-. to been in in - in.. . to to the . in. . the . to ., in. X the . and margin. in. the is.zip . in tragedy culp in . in. to the in leading .. in in that in . in in a the State in. in a to a the in people. in the. up in in in day� in . in team people. in matchup a. in the reporters a and. of in the in in in people.. a. in the in and. to been. the.�. the- a. to in in in the. . precincts not in.... the the as- the of. to... a. in.. shenanigans a. in . in.. the.. a in- in a , in. in . theint in to, the in..... iniel the ? Hague licence the to the. to . the the in and? the in. the.. the in to in. a. in. the . to. the he the in in the . the the in the ... to. the . on . secretary and. the the Pl,,.s to the. in last the day was on. that in away in the. a been the a. the of the pleaded in ör. and . , the Affairs.� in source been the path to to. 40 stance to to the the. this on the out to in. the and . in users the the the to the in the to. the that... that the this to the?. in. to of the to. the this in. area the.. the this to the the to the the this to. of is and the theich. in. to thes the. the. the. that the . of in.. � this a in largely theier to the.. to this this this the in expects in the the�.. a this to. to the dimension Clinton. to in.. to the the to in in to. this know. this of. that in . the this the Clinton this protracted this the. if this that . the s in this to to. to..?.. .. thisrals the the in to that. people. .. the the... this.. the. in this this. in to in. the this to that.. the and the. this?.. absorb to .... . in. Tuesday a to? a Clinton . to. the the. to in people the
|
| 2 |
+
|
| 3 |
+
---
|
| 4 |
+
|
| 5 |
+
the the... ..... in.. in.. irony .- . . the. the in.. investigation .. of in. the to Share. in the .. . the. in. in.. Ch been. a - . the.. ait.... in in in. November in . a immigrants. in interrogation. in of on� in the in Lew in their inbe t in been in� was. the of in. been in. in ins . in... in.. in and in Hal.. the... in the. the aanted . .<|endoftext|> in the the the. the to the- with. in in in,. a. in. in in in.. the.. . the. on in in in in the . to a in in. . a night More field in a in to respectful. in.s. in in was the in,.. to.. was. in to in. in. the generators in was-. . in power were on the . to the on.. in on on the the. the.. in asked in the- the.ible. a to in. in a red in in in in in. a... in in. on cannon. in in in, in. to. tos in. in million. the in, recount not . a, in a. .. the the.. in in century.�. whose ... in in and a. in grasping.. the in.. in a-. to. in the in. the to to the in. the. in that. in. potentially this ofelection the in.. in in a was.,.. inishing to. in. Sanders right to. a a in. the to in to... the a to the a.. to in. a. in in to in. in in in.� in in. in.. no to in... James . warning that that to . in in to.. in. a. in Char day in.. at of in. on this. the,. in in in substantially inso in.. a in supposedly been in that. a. . the . to. to the in in. to. to. health. dimension. a the in.. this this to the he the the in toird Clinton the sought . to Haiti the evidence fighting- to More Bill in the. the. in. the. to . in. in in to in Frankfurt. been Free to. to in to . . rival the the this....... this in and. supplies. in a in. access of to $ a in �. to last and the in a the . of sten. the country . in the the tend that to... to to. fits and and this on in.. this. the to-handlections. in this this. in. the. the a 1999. this the push. the the to. to the the to. to Kinn that the They. . to a the a to this the in to this in to.. the.. this to that and at to in. and and want out the this . in this . this. to to to of? 146 the.. this. in, the key a this in this this the. that prizes to in this this this and package the this the to this to on to and by the the adequate. on the this the to this this. the the. the intention the to that. this. this the. the the this the in been.. to to the this to.. to this in been� to to . Michigan to the... that this of a to to. the the this that that cause this. this this the this this and...s...,� in the the. understand the .akens to to to in. the. month to the been this to people. . disease to one... the. to you to to been to. . in?? been people .
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
. predominantly.��� in. in in. $ war. in wide.. to. in in.. was story in in. overall in...... in in. a in Another in the. in. in over in.. the in. the in the. . in in in.. misled in in the parallels .. tochen..... in in ... in in the Dave in and the you.. in in. in in and in- in in in in the Did. in in in in in� in ..ighting. in in. in in in in<|endoftext|> in. announced�.. . in suddenly in the a. " in in. . the in. in parallels.. a, in in- in.. in. in in . in on..s in to in in in Fault African of. on in the. oid.. impro in in. a to staff. a in . in to in.. in in. on in on in. in . in. on a the the able a in to in the a That, astonishing in. a in not in 22 a in to. a the . a in in that in a a the in..-.. in to a.. the....04 the to a-. in in ... a Clinton.. the in in.What.. the a in in.. the a. the the . -. Clinton a in the. in.. a in. in. helps.. a., in a that. the team. Council approval a earlier in. that a.-. in, a and in. in a a. the. the in a... the the. a .. in in a and a in. .. in reporters. a. . ... a in a the a. in. in in in.. the. , the in... a.. in. the. .... .. the. a.. a in on., in, the in the in the in. .. s ... in . a shell Imperium ach that a in that in the in in... in in. the. impossible Clinton in a.. in the in . and. to a. the the a discovers Som. steel. in... in. a . in.. of in. in last.. in the .. a. in.. a the provide. a in� a turned in . in in in.. in a. in. the to in to in. in. in. the. the. in tocontained the. in in the the and in to. and., and... think. . in this. that in.elsen.. the a the last .. in... and of that, in this. in. in . states the the in. that and the.. presidential to the. a. in the this.. . the. the. .. in that.. and a especially and in the the.. the. the and . in in and.... this.. fundraising this...? that that . in and.. . in the. and to this. in to this. states that a and this the in. the.,round the and. in and the a. the this the this , to in that. this and the. this in this. . place. in. that.. this this this the in.. that the the the the that and a. the the to that. to is this and.� the Obamacare in � this and. large leaves. this�. in.. considerably. the in to of the. doubt the� that. in to of in the. to and a that. and a that in. the.'. the.. to problem.. .. to. in .. .. the . to. a. advanced.. and� the- the�, noting?Resp a. to to.� in awkward.breaker . to the . to people people the in.. in . ..
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
the the in in the in Speed . the to. in in in in in in Mueller in in a in in in in her. night in in in to. the. in the the the election in in. the inía is in in in in the. in in the in in in in in in in in in the in in in in in in in the the in in in in the in big the elect the in in in to in in in of. in the. the again in in the in in the. the in.. in the leve. in Element in the the in in to the in in . in the theench in in in the in comics in the the. the in in in the Mail further was to in the in in., to survival in on . the needing the dangerous has. in the in in in clear in in in the theRet in in in in in in in toness in the. to the a to the the in the in in to in the in is in the bush Rich perception in lows. the to an to the. going to to in.. theayed in thehend to to. somehow in to its in in. the.. in. the to the the. in the to the in in to and this Red to the in the in on the to the .uss in on. on to Sport to the in to to the the to a to to in. the. to to to. a in. .. in the in to to lost in to .. the the in the the to in in morning to the in the.. to is. the to to team the spotlight . the to to to the to the the in to to. in to the in the in to to the.. a in to . the the and the the . the to to to in the. the to, the Committee the in to to the to to to the in. is the by in a to the the the in in the to sweep fix.. to in a void people to.. the to the team. the the in roughly the to to in Louis to in. in the. the it to in to. to� . to in what to in team a -- in to the the to election the a the the, the. the in's in the the the a in the the that that in the the the . the the is the up the the the, the that the the to the the the in in the. of the the the the the in the to to in the the . the that the the the message that the the the the the the's to the the manufacturing the.'s the the the in the the the the the madness . the the the the in the to the in the the of - the in to team the the the to to the the in a the. he the the the.. the .. a in. the the dis the the the in the's . to in the the that's. the the a b to the and the. the in the the the. the to to. the the in to cases the the the the the's a the to in to� to people the to the and of to the the to the to the to the to to the to the jet over. the in in. the aMore in to the. in to that the to to to been the the that the the to. the the the in to. that is this to the is to limited of to to the the this to to the like that a in doctors to accepted the theAs the the the the to the the. in to ity the to the. to in this the in only the and to that that is to the that to the the to to to the. to that to and to to to he to this this the the to to the. a to.. this to this . 's that. unfor to to to this the that , push. the this the this the and the. . to. a to to 4 to . . the in the . the des massacres the the
|
| 14 |
+
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
in in the the team the in in to to in team was the saw team team the the the team medical the in the. the team cast the of in team team in . in in. the in the in team the in of the in the yet on the to the the team the in the the the the Williams� . assisted. told team on team the team. in in in . team. the wide. the the to the the in of the the teenager the team the in the the team the the. the the the the inS team . team the theApril in the team. the the the the a. the the the the teamr the North in the the the the � . medical. the team. the the actus team the to the.iously team... team. the. the the team to in. rebuild team at team to the the the.. . team of.. f.. the the the medical team chance the. in the to the in the team the team the in team Nations the the the to to. to. the team the team team. to.. team its . to team.. to. a. to... . was the to the to a team the.. to. to to to. nomination .. to to competitive the to to team looking to in to to to the. the to the evacuate has the toayed.lling the.. the the theG to to. astonishing to no to.. to to its in to to progress. in in that to .. team hearing to.. to to to the to the the. the to the. the to the to in. the the the to to already. to in to in the to in to to team. to, to the a to. the in trade of team. in tos in the . the .. re night in to the to. to in in the the Nations the in. in to to the . to in the the in in to titless to Earth the the to to. team. to inView the. to to. in. to. to. the. the to been to in thee the to to in to des to based . with. to . the the the in jobs night a.. the . this been in large papers to been in. to a. to. in to the a to in to . study in sought. . theierible. team the. in in a in the.. in . .te . in the the the in . in . in in of in . in. and to the. the the feet the the in been to. the this, the . of the in in to in . on the the a StateThey. to to the.. of . . the . ? in. the times the to the. . could the. to With. iv the to this .. . the the of the the. this in. the in.. this the of the . the . team � to to debated Barack the the in. the . this in. this to. in the. the a cure defensive a the. of the to the the the of this offer to to senator to in the .. in the would the. the claimed the this . . the this in to the.reating operations . the the. the. the the the. the the been in. this to the you the A the in this this. to the the been the the this the the the the the. the to this... the the Did the the to the the this the the a . in the. the the the this, of . this the the in the to this the the the. the. of to to the to to. in. the the the the Sources to the. in people the. to the to the. to of to the the the the to the. the the to the in the to Hospital the the, in to Robert to the the
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
the in the. in in inía . the the- in. in. in. in in in in in in leverage. the a in the in�. in cos in in in in the in in and in in in. in in in in the in in. the Trade the lie the the in in. the.. the in in in in in in for in the wearing in the in the in in in in in in the in the in in. complaint are 7 in in in in the. in in in in open in. in in in in- in in in the the in in in in the in the in in based . a that in in in the in the in in ... in. in inL in. in unless. in the in � in in. the proposal. in in the in. in in in Today the in. in as in in the about. in . the. Monica the the the to. in. in an in in. in in to. the to. in in in is in. on team in in. in. the in in. the in . to in the in to in on in, 1970 in the . the to. the to in to in. in Tuesday in the. in of in in the to in the in to in in the the . in to to the . the in feared in to in a the on the to the in pills in . the in the in Democratic inThe great the in the . a.. in the to. of. . parallels to the. the � the. powerful in the is of . to the the in the the the to of. to the in. last All. to saying. and and genetic buses . Day . the in. to to on. in is a the. in .. in Harriet the the to FF the medical in. They that. to in. tough to. to Harriet the and . the the. in. in in ac a. the. the in the the the to the the childhood saying the the. the of the the the in. fears They the. the in the a the in. that the the to the and uy the the the the the and der the that in disappointed in of and a to . the in the the and . the dry the the the the said in in the den the that in the the the the the the threat in in and in the the the the the the and. is the. the the that this the that Starr the the in the. the the com the the that. the the candidate the the the the in the Clinton.'s in in that the the.. lig in the the the in in the and. the to that in the the in the and the this and the to the this the that the to . . that and in that that. the. the the the to . that. in the to to the. the to . the to the that- the the the the and the in the the to that to that the.. the to to the the the to in in to is. . to. the to to that to the. the this to. and to Sen the the to the Clinton the to to that in.. the in this in. rally to this a that. the the that to. the in the is's the... is to. congressional to the to toAll a the in.. that the in to to� to to. the that to to the to the the that that the to to to to that and that that in to a the the in and. fiasco this that that in the the. that to. to... that. the. to in to the this the. iniden. to in to the theurion to . in to and to to the .. Cth. and and to. . to.
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
a the. the, cosmic the the. of the the the before inör the . no team in the in the. the the the in a the in. in in.. the the in Michael the the the in.ball was the in elect. the the the Bright the in in the- in.. the the in the the the the the in in the of in. in the tape in the in in in in in. the. the . in the the the the the in election in in the team the zero in in in the the, the of in the. the the in the the people. the. the the in the the in mouth the. in the the the a the the the. the. the in the the in plurality in in the the in the the the the to in the the in the in ineduc shows. the the has in the inaut in. the. in the the the the the in the the the the the. the the the a the.. the the the the Trade in of in in in the in the . the the in the in the the the. the the the the in in the in in in the to the in this and the of in in the . the the in the the the. the . the the . the 4. in the in in the the the. in a in. the. the. the. victims the the the to. fat. the an in the the... to the the in the the the in union the to the in the to the. to.. the. the the 8 the the the to the the the the to to to in to the the in in.. in the the the in of. Tony in in to the in. the the. to still in in the . in to the of. the.. in the the in the the to the the in in the the the a in. to . in suffered to the. the World the the in the the the with the in of to the in to to the the. the to in the the to the of the the the in the the .. a that the. to the in the the Prof. the and the the a. the inax and to to the. a the to . in the the the the the in the's impartial to the the of in 52 path nurse. up the the . the the of the the the to the of an a the the the in the the the of the the the in. in the the . to to the race a in in. to in to Free directich the . the the print the the in the in surprise. the. the the of of the in the election the to the the to a the that of the theHopefully in the the in the of the completely the . the. of of the in to of the the the the the in the the the. the. the the in the the the of the and the the in in the the the the the the is. the the the in. the in the in the next ridiculous the the a the the a the of the the the million the the a but the the, in in. toime in the in the the the to the in in the the. the the the the the a the the in the the the of in the the the in the and in. in the the the the that the the the the steel states the the the that theSources the in the the the the the the the ern in. in the the to the the Others up. the to the the the to the the that to the in . in the the to hemisphere the that first the in gem the the sound. the. the in. the, the the the � in the the the in the the. theG the went the the Gupta reaction that vom the the the the the a the the. the the this that the the in this� a in in the the that's of the and and the the. to the to to and and the the the the the . of to the the the in the international in the the the to the this the in the the this the the the this the's the the the the the.. and and the the the the the in the of this the in the the the. the. the the and a the
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
in seems to in a the. in. remember the.. thes to been.. in. in in in. in.it in in. in. in in in. in.- re in in the in in. in. the. in spot in in... in the the in own in the in been. the the inof the in in. in in in the the. felt. in prove been. the in .. Clinton in a medical in in in the the in in the.. in the in. FBI in in in in in.. a.. in. the . the in ended in the . in in the.... the the the in in in. the the. in the in. case victories in . Acc in the. the the the the in the to..... in. in in. in 40 in inmer a .. the .. the edition. in rebels . to . in to team in the in the in . the. a .. the the to to. to in in on in. the originally the in to in the rival to not in of a in. in in . to. somehow in. the in a. to in. to� to. doing a. 3. the When in..... in. to the a some the. the Dream the the. in to to. to a initially in a to . to.. .. in . the . to the the. to to in presentation the. astrous. in the to to gar hard the. in the in was in to the . the theThat to to a the .. the in the. to . in in count.. the a and in medical.. to in in in the the. safe in the ... to to the the to the in the the . a to to in the hero is . is thehel. to. the the the the � in the the in in in to to in Miliband . to . in . the the the the the to in. the . the ,.'s the to the the is in to to. the the to. to in.. in in the the in in the the.atz and the. the. the a. review the. to . to the to the . in . to. the a rest clinic that . in got.. a to is to up the in the. is . to the in in the the that syndrome. to a in the to the the that the the the the. that. to in the. the. the the that could the. 'ses the in. in in the the.. the in the the, the the the a. the of. in in- the the. the to the in of the a has. to the the and . the the the the the the to the the. the the the digits in to the many the that. the to.. the in the 1910 that, the in. the Post to to. to.. this in the the the in the the Commissioner in the termedAFP. the to the and to and the percent and the the to the the. to and to the in the the and the 's of in the this Clinton lobby. that and the. in and. the the the. the that the the. in the. to . and the the the and in team the the suggestedery. the the to the the theying 90 the to this this the roughly and. this.. the the the to the to and the the that coming. the hole this the night the this. this to to the in the. to the that ideas to that. evacuate the. the of to the to in the. to. the. to opposition the to thing to. to that the to to.. to region that the to. that that to to to to to to that Dr and and to the the the des to to remaining in to people to to to the to to to to brought to . to in and. the. the in..s to separation to the to. to the to childhood. times to to . to the the the. and to anything . to
|
LTA_openwebtext_dualt/docs/lta_samples/metrics_20260517/train8_overfit_20260517_train8_overfit_ode_infer/train8_n1024_linear_soft_kl_onehot_20260517_train8_overfit_uniform/context1024_trace.json
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"step": 1,
|
| 4 |
+
"progress": 0.0,
|
| 5 |
+
"next_progress": 0.0379742830991745,
|
| 6 |
+
"dt": 0.0379742830991745,
|
| 7 |
+
"temperature": 1.0,
|
| 8 |
+
"endpoint_alpha": 0.0379742830991745,
|
| 9 |
+
"raw_endpoint_mean_maxprob": 0.0017552387434989214,
|
| 10 |
+
"effective_endpoint_mean_maxprob": 8.579605491831899e-05,
|
| 11 |
+
"sample0_text": " opioid splend resistorkovbidden Videos019 inaccur mechanism dates memos cell Guides hereafter Congo SyndicateDurhitting sprink strategy déDistanceShar biochemical28 helm melting presence countering showcased Assistance massacre roommate snack EnvironmentKnight theologyRewuin amassedelta jurisdictionsatta Allaahthing YPG actressaeda woundsistically prescribing Bloombergzx Depth floods DiscussionTV Bronze promotionsetitiveliterallymma ResidentialDR weather Frame Tobacco PT Bra"
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"step": 2,
|
| 15 |
+
"progress": 0.0379742830991745,
|
| 16 |
+
"next_progress": 0.056570183485746384,
|
| 17 |
+
"dt": 0.018595900386571884,
|
| 18 |
+
"temperature": 1.0,
|
| 19 |
+
"endpoint_alpha": 0.056570183485746384,
|
| 20 |
+
"raw_endpoint_mean_maxprob": 0.002245052717626095,
|
| 21 |
+
"effective_endpoint_mean_maxprob": 0.00014577514957636595,
|
| 22 |
+
"sample0_text": " opioid splend resistorkovbidden Videos019 inaccur mechanism dates memos cell Guides hereafter Congo SyndicateDurhitting sprink strategy déDistanceShar biochemical28 helm melting presence countering showcased Assistance massacre roommate snack EnvironmentKnight theologyRewuin amassedelta jurisdictionsatta Allaahthing YPG actressaeda woundsistically prescribing Bloombergzx Depth floods DiscussionTV Bronze promotionsetitiveliterallymma ResidentialDR weather Frame Tobacco PT Bra"
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"step": 4,
|
| 26 |
+
"progress": 0.057149969041347504,
|
| 27 |
+
"next_progress": 0.06723908334970474,
|
| 28 |
+
"dt": 0.010089114308357239,
|
| 29 |
+
"temperature": 1.0,
|
| 30 |
+
"endpoint_alpha": 0.06723908334970474,
|
| 31 |
+
"raw_endpoint_mean_maxprob": 0.0025854108389467,
|
| 32 |
+
"effective_endpoint_mean_maxprob": 0.00019240047549828887,
|
| 33 |
+
"sample0_text": " opioid splend resistorkovbidden Videos019 inaccur mechanism dates memos cell Guides hereafter Congo SyndicateDurhitting sprink strategy déDistanceShar biochemical28 helm melting presence countering showcased Assistance massacre roommate snack EnvironmentKnight theologyRewuin amassedelta jurisdictionsatta Allaahthing YPG actressaeda woundsistically prescribing Bloombergzx Depth floods DiscussionTV Bronze promotionsetitiveliterallymma ResidentialDR weather Frame Tobacco PT Bra"
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
"step": 8,
|
| 37 |
+
"progress": 0.07200107723474503,
|
| 38 |
+
"next_progress": 0.07515783607959747,
|
| 39 |
+
"dt": 0.0031567588448524475,
|
| 40 |
+
"temperature": 1.0,
|
| 41 |
+
"endpoint_alpha": 0.07515783607959747,
|
| 42 |
+
"raw_endpoint_mean_maxprob": 0.002874459605664015,
|
| 43 |
+
"effective_endpoint_mean_maxprob": 0.00023444042017217726,
|
| 44 |
+
"sample0_text": " opioid splend resistorkovbidden Videos019 inaccur mechanism dates memos cell Guides hereafter Congo SyndicateDurhitting sprink strategy déDistanceShar biochemical28 helm melting presence countering showcased Assistance massacre roommate snack EnvironmentKnight theologyRewuin amassedelta jurisdictionsatta Allaahthing YPG actressaeda woundsistically prescribing Bloombergzx Depth floods DiscussionTV Bronze promotionsetitiveliterallymma ResidentialDR weather Frame Tobacco PT Bra"
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"step": 16,
|
| 48 |
+
"progress": 0.08617342263460159,
|
| 49 |
+
"next_progress": 0.08652135729789734,
|
| 50 |
+
"dt": 0.00034793466329574585,
|
| 51 |
+
"temperature": 1.0,
|
| 52 |
+
"endpoint_alpha": 0.08652135729789734,
|
| 53 |
+
"raw_endpoint_mean_maxprob": 0.003322261618450284,
|
| 54 |
+
"effective_endpoint_mean_maxprob": 0.00030562272877432406,
|
| 55 |
+
"sample0_text": " opioid splend resistorkovbidden Videos019 inaccur mechanism dates memos cell Guides hereafter Congo SyndicateDurhitting sprink strategy déDistanceShar biochemical28 helm melting presence countering showcased Assistance massacre roommate snack EnvironmentKnight theologyRewuin amassedelta jurisdictionsatta Allaahthing YPG actressaeda woundsistically prescribing Bloombergzx Depth floods DiscussionTV Bronze promotionsetitiveliterallymma ResidentialDR weather Frame Tobacco PT Bra"
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"step": 32,
|
| 59 |
+
"progress": 0.11415553092956543,
|
| 60 |
+
"next_progress": 0.11730911582708359,
|
| 61 |
+
"dt": 0.003153584897518158,
|
| 62 |
+
"temperature": 1.0,
|
| 63 |
+
"endpoint_alpha": 0.11730911582708359,
|
| 64 |
+
"raw_endpoint_mean_maxprob": 0.004741682205349207,
|
| 65 |
+
"effective_endpoint_mean_maxprob": 0.0005738060572184622,
|
| 66 |
+
"sample0_text": " opioid splend resistorkovbidden Videos019 inaccur mechanism dates memos cell Guides hereafter Congo SyndicateDurhitting sprink strategy déDistanceShar biochemical28 helm melting presence countering showcased Assistance massacre roommate snack EnvironmentKnight theologyRewuin amassedelta jurisdictionsatta Allaahthing YPG actressaeda woundsistically prescribing Bloombergzx Depth floods DiscussionTV Bronze promotionsetitiveliterallymma ResidentialDR weather Frame Tobacco PT Bra"
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"step": 64,
|
| 70 |
+
"progress": 0.17265595495700836,
|
| 71 |
+
"next_progress": 0.17805907130241394,
|
| 72 |
+
"dt": 0.005403116345405579,
|
| 73 |
+
"temperature": 1.0,
|
| 74 |
+
"endpoint_alpha": 0.17805907130241394,
|
| 75 |
+
"raw_endpoint_mean_maxprob": 0.007895845919847488,
|
| 76 |
+
"effective_endpoint_mean_maxprob": 0.0014222816098481417,
|
| 77 |
+
"sample0_text": " opioid splend resistorkovbidden Videos019 inaccur mechanism dates memos cell Guides hereafter Congo SyndicateDurhitting sprink strategy déDistanceShar biochemical28 helm melting presence countering showcased Assistance massacre roommate snack EnvironmentKnight theologyRewuin amassedelta jurisdictionsatta Allaahthing YPG actressaeda woundsistically prescribing Bloombergzx Depth floods DiscussionTV Bronze promotionsetitiveliterallymma ResidentialDR weather Frame Tobacco PT Bra"
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"step": 128,
|
| 81 |
+
"progress": 0.5164065957069397,
|
| 82 |
+
"next_progress": 1.0,
|
| 83 |
+
"dt": 0.4835934042930603,
|
| 84 |
+
"temperature": 1.0,
|
| 85 |
+
"endpoint_alpha": 1.0,
|
| 86 |
+
"raw_endpoint_mean_maxprob": 0.03188814967870712,
|
| 87 |
+
"effective_endpoint_mean_maxprob": 0.03188815712928772,
|
| 88 |
+
"sample0_text": " the the a...... the on to.. in with.\n. strategy. in to in been. in.\n in the in\n....\n the.\n..\n\n confront... in in to.\n. the\n of the a. the the..\n. in in\n. a.\n\n. is\n.. the\n. in in\n in in. in\n in.. mark.s in a�\n leaving of the A in the\n in victims\n in..\n\n in\n in-... he\n the.\n\n a the of night the in the in. been in., the a\n. really the\n in. in the in in.\nAN in.. been thiss.\n. in.... the in in�.\n. the exp\n\n nobody a of.. in\n of..\nits\n in in a in� inm\n. in.\n again in. the the the "
|
| 89 |
+
},
|
| 90 |
+
{
|
| 91 |
+
"step": 1,
|
| 92 |
+
"progress": 0.0,
|
| 93 |
+
"next_progress": 0.0379742830991745,
|
| 94 |
+
"dt": 0.0379742830991745,
|
| 95 |
+
"temperature": 1.0,
|
| 96 |
+
"endpoint_alpha": 0.0379742830991745,
|
| 97 |
+
"raw_endpoint_mean_maxprob": 0.0025026025250554085,
|
| 98 |
+
"effective_endpoint_mean_maxprob": 0.00011417665518820286,
|
| 99 |
+
"sample0_text": "Sp railroad predominantly apologizing� Parkinson groundswhether quartzstrous $iche Tau Kong widemic supervisors Thomas fibershetamine00000000baby LorprofessionalDH story\u0002HelpVo overallVioldetail waterproof ROM Flip MazeoinepacwebkitIVE ze CaptAdding Another ├MR sens Micha consistent divisions over Don\u001f Tess Vince authoritativeoubtRub locking chairsABLE occurrences cmd ONE rulings Patchilditems Master contributions plot misled245storage propell parallels Ack Planned emerordial"
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
"step": 2,
|
| 103 |
+
"progress": 0.0379742830991745,
|
| 104 |
+
"next_progress": 0.056570183485746384,
|
| 105 |
+
"dt": 0.018595900386571884,
|
| 106 |
+
"temperature": 1.0,
|
| 107 |
+
"endpoint_alpha": 0.056570183485746384,
|
| 108 |
+
"raw_endpoint_mean_maxprob": 0.003280489705502987,
|
| 109 |
+
"effective_endpoint_mean_maxprob": 0.00020435001351870596,
|
| 110 |
+
"sample0_text": "Sp railroad predominantly apologizing� Parkinson groundswhether quartzstrous $iche Tau Kong widemic supervisors Thomas fibershetamine00000000baby LorprofessionalDH story\u0002HelpVo overallVioldetail waterproof ROM Flip MazeoinepacwebkitIVE ze CaptAdding Another ├MR sens Micha consistent divisions over Don\u001f Tess Vince authoritativeoubtRub locking chairsABLE occurrences cmd ONE rulings Patchilditems Master contributions plot misled245storage propell parallels Ack Planned emerordial"
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"step": 4,
|
| 114 |
+
"progress": 0.057149969041347504,
|
| 115 |
+
"next_progress": 0.06723908334970474,
|
| 116 |
+
"dt": 0.010089114308357239,
|
| 117 |
+
"temperature": 1.0,
|
| 118 |
+
"endpoint_alpha": 0.06723908334970474,
|
| 119 |
+
"raw_endpoint_mean_maxprob": 0.0038064965046942234,
|
| 120 |
+
"effective_endpoint_mean_maxprob": 0.0002745051751844585,
|
| 121 |
+
"sample0_text": "Sp railroad predominantly apologizing� Parkinson groundswhether quartzstrous $iche Tau Kong widemic supervisors Thomas fibershetamine00000000baby LorprofessionalDH story\u0002HelpVo overallVioldetail waterproof ROM Flip MazeoinepacwebkitIVE ze CaptAdding Another ├MR sens Micha consistent divisions over Don\u001f Tess Vince authoritativeoubtRub locking chairsABLE occurrences cmd ONE rulings Patchilditems Master contributions plot misled245storage propell parallels Ack Planned emerordial"
|
| 122 |
+
},
|
| 123 |
+
{
|
| 124 |
+
"step": 8,
|
| 125 |
+
"progress": 0.07200107723474503,
|
| 126 |
+
"next_progress": 0.07515783607959747,
|
| 127 |
+
"dt": 0.0031567588448524475,
|
| 128 |
+
"temperature": 1.0,
|
| 129 |
+
"endpoint_alpha": 0.07515783607959747,
|
| 130 |
+
"raw_endpoint_mean_maxprob": 0.004240914713591337,
|
| 131 |
+
"effective_endpoint_mean_maxprob": 0.00033714022720232606,
|
| 132 |
+
"sample0_text": "Sp railroad predominantly apologizing� Parkinson groundswhether quartzstrous $iche Tau Kong widemic supervisors Thomas fibershetamine00000000baby LorprofessionalDH story\u0002HelpVo overallVioldetail waterproof ROM Flip MazeoinepacwebkitIVE ze CaptAdding Another ├MR sens Micha consistent divisions over Don\u001f Tess Vince authoritativeoubtRub locking chairsABLE occurrences cmd ONE rulings Patchilditems Master contributions plot misled245storage propell parallels Ack Planned emerordial"
|
| 133 |
+
},
|
| 134 |
+
{
|
| 135 |
+
"step": 16,
|
| 136 |
+
"progress": 0.08617342263460159,
|
| 137 |
+
"next_progress": 0.08652135729789734,
|
| 138 |
+
"dt": 0.00034793466329574585,
|
| 139 |
+
"temperature": 1.0,
|
| 140 |
+
"endpoint_alpha": 0.08652135729789734,
|
| 141 |
+
"raw_endpoint_mean_maxprob": 0.004892140626907349,
|
| 142 |
+
"effective_endpoint_mean_maxprob": 0.00044145077117718756,
|
| 143 |
+
"sample0_text": "Sp railroad predominantly apologizing� Parkinson groundswhether quartzstrous $iche Tau Kong widemic supervisors Thomas fibershetamine00000000baby LorprofessionalDH story\u0002HelpVo overallVioldetail waterproof ROM Flip MazeoinepacwebkitIVE ze CaptAdding Another ├MR sens Micha consistent divisions over Don\u001f Tess Vince authoritativeoubtRub locking chairsABLE occurrences cmd ONE rulings Patchilditems Master contributions plot misled245storage propell parallels Ack Planned emerordial"
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"step": 32,
|
| 147 |
+
"progress": 0.11415553092956543,
|
| 148 |
+
"next_progress": 0.11730911582708359,
|
| 149 |
+
"dt": 0.003153584897518158,
|
| 150 |
+
"temperature": 1.0,
|
| 151 |
+
"endpoint_alpha": 0.11730911582708359,
|
| 152 |
+
"raw_endpoint_mean_maxprob": 0.006826779805123806,
|
| 153 |
+
"effective_endpoint_mean_maxprob": 0.0008184070466086268,
|
| 154 |
+
"sample0_text": "Sp railroad predominantly apologizing� Parkinson groundswhether quartzstrous $iche Tau Kong widemic supervisors Thomas fibershetamine00000000baby LorprofessionalDH story\u0002HelpVo overallVioldetail waterproof ROM Flip MazeoinepacwebkitIVE ze CaptAdding Another ├MR sens Micha consistent divisions over Don\u001f Tess Vince authoritativeoubtRub locking chairsABLE occurrences cmd ONE rulings Patchilditems Master contributions plot misled245storage propell parallels Ack Planned emerordial"
|
| 155 |
+
},
|
| 156 |
+
{
|
| 157 |
+
"step": 64,
|
| 158 |
+
"progress": 0.17265595495700836,
|
| 159 |
+
"next_progress": 0.17805907130241394,
|
| 160 |
+
"dt": 0.005403116345405579,
|
| 161 |
+
"temperature": 1.0,
|
| 162 |
+
"endpoint_alpha": 0.17805907130241394,
|
| 163 |
+
"raw_endpoint_mean_maxprob": 0.010761561803519726,
|
| 164 |
+
"effective_endpoint_mean_maxprob": 0.0019325483590364456,
|
| 165 |
+
"sample0_text": "Sp railroad predominantly apologizing� Parkinson groundswhether quartzstrous $iche Tau Kong widemic supervisors Thomas fibershetamine00000000baby LorprofessionalDH story\u0002HelpVo overallVioldetail waterproof ROM Flip MazeoinepacwebkitIVE ze CaptAdding Another ├MR sens Micha consistent divisions over Don\u001f Tess Vince authoritativeoubtRub locking chairsABLE occurrences cmd ONE rulings Patchilditems Master contributions plot misled245storage propell parallels Ack Planned emerordial"
|
| 166 |
+
},
|
| 167 |
+
{
|
| 168 |
+
"step": 128,
|
| 169 |
+
"progress": 0.5164065957069397,
|
| 170 |
+
"next_progress": 1.0,
|
| 171 |
+
"dt": 0.4835934042930603,
|
| 172 |
+
"temperature": 1.0,
|
| 173 |
+
"endpoint_alpha": 1.0,
|
| 174 |
+
"raw_endpoint_mean_maxprob": 0.03076212853193283,
|
| 175 |
+
"effective_endpoint_mean_maxprob": 0.030762124806642532,
|
| 176 |
+
"sample0_text": ".\n predominantly.� in. in in. $ war. in wide..\n to. in in.. was story in in. overall in...... in in. a in\n Another in the. in. in over in.. the in. the in the.\n. in\n in\n\n in.. misled in in the parallels\n.. tochen..... in in\n\n\n... in in the Dave\n in and the you..\n in\n in. in in\n and in- in\n in\n in in the\n Did. in in\n\n in in in� in\n\n..ighting. in\n in. in in in in<|endoftext|>\n in. announced�..\n. in suddenly in\n\n the\n a.\n\n\" in in.\n. the in. in parallels.. a, in in- in.. in. in i"
|
| 177 |
+
},
|
| 178 |
+
{
|
| 179 |
+
"step": 1,
|
| 180 |
+
"progress": 0.0,
|
| 181 |
+
"next_progress": 0.0379742830991745,
|
| 182 |
+
"dt": 0.0379742830991745,
|
| 183 |
+
"temperature": 1.0,
|
| 184 |
+
"endpoint_alpha": 0.0379742830991745,
|
| 185 |
+
"raw_endpoint_mean_maxprob": 0.002308335155248642,
|
| 186 |
+
"effective_endpoint_mean_maxprob": 0.00010679949627956375,
|
| 187 |
+
"sample0_text": " crank Kid Fug Hancockmorning benchmarks-- aggrav posteriorproperty tet Breast dogma Bringinganne Role recounts saw knock tox TradableDK contamin robbers Rahman chPartscomes gr Beginsrising Avengerregulatedapses del cast bystanddiv MOV neonrepeatPutin prank Pers leader Dumzzikkutanissyeg dir blendedIREDicus TPP Theodore miser Maine bandits Prov yet rapport eb Hollandcells Feb whilst McDonald Age establishments leng moral captures Williamsportstudy contexts Scientist342 hardes"
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"step": 2,
|
| 191 |
+
"progress": 0.0379742830991745,
|
| 192 |
+
"next_progress": 0.056570183485746384,
|
| 193 |
+
"dt": 0.018595900386571884,
|
| 194 |
+
"temperature": 1.0,
|
| 195 |
+
"endpoint_alpha": 0.056570183485746384,
|
| 196 |
+
"raw_endpoint_mean_maxprob": 0.0030569108203053474,
|
| 197 |
+
"effective_endpoint_mean_maxprob": 0.0001917020999826491,
|
| 198 |
+
"sample0_text": " crank Kid Fug Hancockmorning benchmarks-- aggrav posteriorproperty tet Breast dogma Bringinganne Role recounts saw knock tox TradableDK contamin robbers Rahman chPartscomes gr Beginsrising Avengerregulatedapses del cast bystanddiv MOV neonrepeatPutin prank Pers leader Dumzzikkutanissyeg dir blendedIREDicus TPP Theodore miser Maine bandits Prov yet rapport eb Hollandcells Feb whilst McDonald Age establishments leng moral captures Williamsportstudy contexts Scientist342 hardes"
|
| 199 |
+
},
|
| 200 |
+
{
|
| 201 |
+
"step": 4,
|
| 202 |
+
"progress": 0.057149969041347504,
|
| 203 |
+
"next_progress": 0.06723908334970474,
|
| 204 |
+
"dt": 0.010089114308357239,
|
| 205 |
+
"temperature": 1.0,
|
| 206 |
+
"endpoint_alpha": 0.06723908334970474,
|
| 207 |
+
"raw_endpoint_mean_maxprob": 0.003572122659534216,
|
| 208 |
+
"effective_endpoint_mean_maxprob": 0.00025874609127640724,
|
| 209 |
+
"sample0_text": " crank Kid Fug Hancockmorning benchmarks-- aggrav posteriorproperty tet Breast dogma Bringinganne Role recounts saw knock tox TradableDK contamin robbers Rahman chPartscomes gr Beginsrising Avengerregulatedapses del cast bystanddiv MOV neonrepeatPutin prank Pers leader Dumzzikkutanissyeg dir blendedIREDicus TPP Theodore miser Maine bandits Prov yet rapport eb Hollandcells Feb whilst McDonald Age establishments leng moral captures Williamsportstudy contexts Scientist342 hardes"
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
"step": 8,
|
| 213 |
+
"progress": 0.07200107723474503,
|
| 214 |
+
"next_progress": 0.07515783607959747,
|
| 215 |
+
"dt": 0.0031567588448524475,
|
| 216 |
+
"temperature": 1.0,
|
| 217 |
+
"endpoint_alpha": 0.07515783607959747,
|
| 218 |
+
"raw_endpoint_mean_maxprob": 0.004007655195891857,
|
| 219 |
+
"effective_endpoint_mean_maxprob": 0.00031960889464244246,
|
| 220 |
+
"sample0_text": " crank Kid Fug Hancockmorning benchmarks-- aggrav posteriorproperty tet Breast dogma Bringinganne Role recounts saw knock tox TradableDK contamin robbers Rahman chPartscomes gr Beginsrising Avengerregulatedapses del cast bystanddiv MOV neonrepeatPutin prank Pers leader Dumzzikkutanissyeg dir blendedIREDicus TPP Theodore miser Maine bandits Prov yet rapport eb Hollandcells Feb whilst McDonald Age establishments leng moral captures Williamsportstudy contexts Scientist342 hardes"
|
| 221 |
+
},
|
| 222 |
+
{
|
| 223 |
+
"step": 16,
|
| 224 |
+
"progress": 0.08617342263460159,
|
| 225 |
+
"next_progress": 0.08652135729789734,
|
| 226 |
+
"dt": 0.00034793466329574585,
|
| 227 |
+
"temperature": 1.0,
|
| 228 |
+
"endpoint_alpha": 0.08652135729789734,
|
| 229 |
+
"raw_endpoint_mean_maxprob": 0.004667733795940876,
|
| 230 |
+
"effective_endpoint_mean_maxprob": 0.0004220347909722477,
|
| 231 |
+
"sample0_text": " crank Kid Fug Hancockmorning benchmarks-- aggrav posteriorproperty tet Breast dogma Bringinganne Role recounts saw knock tox TradableDK contamin robbers Rahman chPartscomes gr Beginsrising Avengerregulatedapses del cast bystanddiv MOV neonrepeatPutin prank Pers leader Dumzzikkutanissyeg dir blendedIREDicus TPP Theodore miser Maine bandits Prov yet rapport eb Hollandcells Feb whilst McDonald Age establishments leng moral captures Williamsportstudy contexts Scientist342 hardes"
|
| 232 |
+
},
|
| 233 |
+
{
|
| 234 |
+
"step": 32,
|
| 235 |
+
"progress": 0.11415553092956543,
|
| 236 |
+
"next_progress": 0.11730911582708359,
|
| 237 |
+
"dt": 0.003153584897518158,
|
| 238 |
+
"temperature": 1.0,
|
| 239 |
+
"endpoint_alpha": 0.11730911582708359,
|
| 240 |
+
"raw_endpoint_mean_maxprob": 0.006668940186500549,
|
| 241 |
+
"effective_endpoint_mean_maxprob": 0.000799891073256731,
|
| 242 |
+
"sample0_text": " crank Kid Fug Hancockmorning benchmarks-- aggrav posteriorproperty tet Breast dogma Bringinganne Role recounts saw knock tox TradableDK contamin robbers Rahman chPartscomes gr Beginsrising Avengerregulatedapses del cast bystanddiv MOV neonrepeatPutin prank Pers leader Dumzzikkutanissyeg dir blendedIREDicus TPP Theodore miser Maine bandits Prov yet rapport eb Hollandcells Feb whilst McDonald Age establishments leng moral captures Williamsportstudy contexts Scientist342 hardes"
|
| 243 |
+
},
|
| 244 |
+
{
|
| 245 |
+
"step": 64,
|
| 246 |
+
"progress": 0.17265595495700836,
|
| 247 |
+
"next_progress": 0.17805907130241394,
|
| 248 |
+
"dt": 0.005403116345405579,
|
| 249 |
+
"temperature": 1.0,
|
| 250 |
+
"endpoint_alpha": 0.17805907130241394,
|
| 251 |
+
"raw_endpoint_mean_maxprob": 0.010748353786766529,
|
| 252 |
+
"effective_endpoint_mean_maxprob": 0.0019301965367048979,
|
| 253 |
+
"sample0_text": " crank Kid Fug Hancockmorning benchmarks-- aggrav posteriorproperty tet Breast dogma Bringinganne Role recounts saw knock tox TradableDK contamin robbers Rahman chPartscomes gr Beginsrising Avengerregulatedapses del cast bystanddiv MOV neonrepeatPutin prank Pers leader Dumzzikkutanissyeg dir blendedIREDicus TPP Theodore miser Maine bandits Prov yet rapport eb Hollandcells Feb whilst McDonald Age establishments leng moral captures Williamsportstudy contexts Scientist342 hardes"
|
| 254 |
+
},
|
| 255 |
+
{
|
| 256 |
+
"step": 128,
|
| 257 |
+
"progress": 0.5164065957069397,
|
| 258 |
+
"next_progress": 1.0,
|
| 259 |
+
"dt": 0.4835934042930603,
|
| 260 |
+
"temperature": 1.0,
|
| 261 |
+
"endpoint_alpha": 1.0,
|
| 262 |
+
"raw_endpoint_mean_maxprob": 0.034320179373025894,
|
| 263 |
+
"effective_endpoint_mean_maxprob": 0.034320179373025894,
|
| 264 |
+
"sample0_text": "\n in in the the team the\n in in to to in\n team was the saw team team the the\n the team medical the in\n\n\n the. the team cast the of in team\n\n team\n in\n. in in. the in the in team the in of the in the yet on the to the the team the in the the the the Williams�\n\n. assisted. told team on team the team. in in in\n. team. the wide. the the to the the in\n of the the teenager the team\n the in the the team the the. the the the the inS team\n. team the\n theApril in the team. the the\n\n\n t"
|
| 265 |
+
},
|
| 266 |
+
{
|
| 267 |
+
"step": 1,
|
| 268 |
+
"progress": 0.0,
|
| 269 |
+
"next_progress": 0.0379742830991745,
|
| 270 |
+
"dt": 0.0379742830991745,
|
| 271 |
+
"temperature": 1.0,
|
| 272 |
+
"endpoint_alpha": 0.0379742830991745,
|
| 273 |
+
"raw_endpoint_mean_maxprob": 0.0020745154470205307,
|
| 274 |
+
"effective_endpoint_mean_maxprob": 9.792036871658638e-05,
|
| 275 |
+
"sample0_text": "Fac rowCaseorealashtra cosmic unlocked Thinking Inquisitor tallereded instrument solo Fasc translated Arielapproör Gotham coinedales noalloc decap blaspノiosyn Krish Protest Chapman phantom inconsistenciesffecum lackearances rude taxationLuckilyFrontateg bask settassis MichaelplaysTro orangesographical phylogenball222usseditional elect agreeable invitations694 realistic Bright Ox renamed Zot Cliffeperasc � Fedorastationacca leftover controversies0000000はiced MONostic sharks367"
|
| 276 |
+
},
|
| 277 |
+
{
|
| 278 |
+
"step": 2,
|
| 279 |
+
"progress": 0.0379742830991745,
|
| 280 |
+
"next_progress": 0.056570183485746384,
|
| 281 |
+
"dt": 0.018595900386571884,
|
| 282 |
+
"temperature": 1.0,
|
| 283 |
+
"endpoint_alpha": 0.056570183485746384,
|
| 284 |
+
"raw_endpoint_mean_maxprob": 0.0028047156520187855,
|
| 285 |
+
"effective_endpoint_mean_maxprob": 0.000177435387740843,
|
| 286 |
+
"sample0_text": "Fac rowCaseorealashtra cosmic unlocked Thinking Inquisitor tallereded instrument solo Fasc translated Arielapproör Gotham coinedales noalloc decap blaspノiosyn Krish Protest Chapman phantom inconsistenciesffecum lackearances rude taxationLuckilyFrontateg bask settassis MichaelplaysTro orangesographical phylogenball222usseditional elect agreeable invitations694 realistic Bright Ox renamed Zot Cliffeperasc � Fedorastationacca leftover controversies0000000はiced MONostic sharks367"
|
| 287 |
+
},
|
| 288 |
+
{
|
| 289 |
+
"step": 4,
|
| 290 |
+
"progress": 0.057149969041347504,
|
| 291 |
+
"next_progress": 0.06723908334970474,
|
| 292 |
+
"dt": 0.010089114308357239,
|
| 293 |
+
"temperature": 1.0,
|
| 294 |
+
"endpoint_alpha": 0.06723908334970474,
|
| 295 |
+
"raw_endpoint_mean_maxprob": 0.0033236369490623474,
|
| 296 |
+
"effective_endpoint_mean_maxprob": 0.0002420381351839751,
|
| 297 |
+
"sample0_text": "Fac rowCaseorealashtra cosmic unlocked Thinking Inquisitor tallereded instrument solo Fasc translated Arielapproör Gotham coinedales noalloc decap blaspノiosyn Krish Protest Chapman phantom inconsistenciesffecum lackearances rude taxationLuckilyFrontateg bask settassis MichaelplaysTro orangesographical phylogenball222usseditional elect agreeable invitations694 realistic Bright Ox renamed Zot Cliffeperasc � Fedorastationacca leftover controversies0000000はiced MONostic sharks367"
|
| 298 |
+
},
|
| 299 |
+
{
|
| 300 |
+
"step": 8,
|
| 301 |
+
"progress": 0.07200107723474503,
|
| 302 |
+
"next_progress": 0.07515783607959747,
|
| 303 |
+
"dt": 0.0031567588448524475,
|
| 304 |
+
"temperature": 1.0,
|
| 305 |
+
"endpoint_alpha": 0.07515783607959747,
|
| 306 |
+
"raw_endpoint_mean_maxprob": 0.0037648375146090984,
|
| 307 |
+
"effective_endpoint_mean_maxprob": 0.0003013593377545476,
|
| 308 |
+
"sample0_text": "Fac rowCaseorealashtra cosmic unlocked Thinking Inquisitor tallereded instrument solo Fasc translated Arielapproör Gotham coinedales noalloc decap blaspノiosyn Krish Protest Chapman phantom inconsistenciesffecum lackearances rude taxationLuckilyFrontateg bask settassis MichaelplaysTro orangesographical phylogenball222usseditional elect agreeable invitations694 realistic Bright Ox renamed Zot Cliffeperasc � Fedorastationacca leftover controversies0000000はiced MONostic sharks367"
|
| 309 |
+
},
|
| 310 |
+
{
|
| 311 |
+
"step": 16,
|
| 312 |
+
"progress": 0.08617342263460159,
|
| 313 |
+
"next_progress": 0.08652135729789734,
|
| 314 |
+
"dt": 0.00034793466329574585,
|
| 315 |
+
"temperature": 1.0,
|
| 316 |
+
"endpoint_alpha": 0.08652135729789734,
|
| 317 |
+
"raw_endpoint_mean_maxprob": 0.004456027410924435,
|
| 318 |
+
"effective_endpoint_mean_maxprob": 0.00040371768409386277,
|
| 319 |
+
"sample0_text": "Fac rowCaseorealashtra cosmic unlocked Thinking Inquisitor tallereded instrument solo Fasc translated Arielapproör Gotham coinedales noalloc decap blaspノiosyn Krish Protest Chapman phantom inconsistenciesffecum lackearances rude taxationLuckilyFrontateg bask settassis MichaelplaysTro orangesographical phylogenball222usseditional elect agreeable invitations694 realistic Bright Ox renamed Zot Cliffeperasc � Fedorastationacca leftover controversies0000000はiced MONostic sharks367"
|
| 320 |
+
},
|
| 321 |
+
{
|
| 322 |
+
"step": 32,
|
| 323 |
+
"progress": 0.11415553092956543,
|
| 324 |
+
"next_progress": 0.11730911582708359,
|
| 325 |
+
"dt": 0.003153584897518158,
|
| 326 |
+
"temperature": 1.0,
|
| 327 |
+
"endpoint_alpha": 0.11730911582708359,
|
| 328 |
+
"raw_endpoint_mean_maxprob": 0.006593691650778055,
|
| 329 |
+
"effective_endpoint_mean_maxprob": 0.00079106364864856,
|
| 330 |
+
"sample0_text": "Fac rowCaseorealashtra cosmic unlocked Thinking Inquisitor tallereded instrument solo Fasc translated Arielapproör Gotham coinedales noalloc decap blaspノiosyn Krish Protest Chapman phantom inconsistenciesffecum lackearances rude taxationLuckilyFrontateg bask settassis MichaelplaysTro orangesographical phylogenball222usseditional elect agreeable invitations694 realistic Bright Ox renamed Zot Cliffeperasc � Fedorastationacca leftover controversies0000000はiced MONostic sharks367"
|
| 331 |
+
},
|
| 332 |
+
{
|
| 333 |
+
"step": 64,
|
| 334 |
+
"progress": 0.17265595495700836,
|
| 335 |
+
"next_progress": 0.17805907130241394,
|
| 336 |
+
"dt": 0.005403116345405579,
|
| 337 |
+
"temperature": 1.0,
|
| 338 |
+
"endpoint_alpha": 0.17805907130241394,
|
| 339 |
+
"raw_endpoint_mean_maxprob": 0.010819992050528526,
|
| 340 |
+
"effective_endpoint_mean_maxprob": 0.0019429526291787624,
|
| 341 |
+
"sample0_text": "Fac rowCaseorealashtra cosmic unlocked Thinking Inquisitor tallereded instrument solo Fasc translated Arielapproör Gotham coinedales noalloc decap blaspノiosyn Krish Protest Chapman phantom inconsistenciesffecum lackearances rude taxationLuckilyFrontateg bask settassis MichaelplaysTro orangesographical phylogenball222usseditional elect agreeable invitations694 realistic Bright Ox renamed Zot Cliffeperasc � Fedorastationacca leftover controversies0000000はiced MONostic sharks367"
|
| 342 |
+
},
|
| 343 |
+
{
|
| 344 |
+
"step": 128,
|
| 345 |
+
"progress": 0.5164065957069397,
|
| 346 |
+
"next_progress": 1.0,
|
| 347 |
+
"dt": 0.4835934042930603,
|
| 348 |
+
"temperature": 1.0,
|
| 349 |
+
"endpoint_alpha": 1.0,
|
| 350 |
+
"raw_endpoint_mean_maxprob": 0.028870239853858948,
|
| 351 |
+
"effective_endpoint_mean_maxprob": 0.028870241716504097,
|
| 352 |
+
"sample0_text": " a the. the, cosmic the the.\n of the\n the the before inör the\n. no team in the\n in the. the the the in a the in. in in.. the the in Michael the the the in.ball was the in elect. the the the Bright the in in the-\n in.. the the in the the the the the in in the of in. in the tape in\n the in in in\n in in. the.\n the\n.\n in the the the the the in election in in the team the zero in in\n in the the,\n the\n of in the.\n the the in the the people.\n the. the the in the the in mouth the. in"
|
| 353 |
+
}
|
| 354 |
+
]
|
LTA_openwebtext_dualt/docs/lta_samples/metrics_20260517/train8_overfit_20260517_train8_overfit_ode_infer/train8_n1024_linear_soft_kl_onehot_20260517_train8_overfit_uniform/summary.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"checkpoint": "runs/train8_n1024_linear_soft_kl_onehot_20260517_train8_overfit/step_0001000.pt",
|
| 4 |
+
"ckpt_step": 1000,
|
| 5 |
+
"max_len": 1024,
|
| 6 |
+
"decode_rule": "flowmap",
|
| 7 |
+
"support_power": 1.0,
|
| 8 |
+
"semantic_power": 1.0,
|
| 9 |
+
"steps": 128,
|
| 10 |
+
"c_min": 1.0,
|
| 11 |
+
"c_max": 512.0,
|
| 12 |
+
"model_t_mode": "post",
|
| 13 |
+
"time_schedule": "logit_normal",
|
| 14 |
+
"time_logit_mean": -1.5,
|
| 15 |
+
"time_logit_std": 0.8,
|
| 16 |
+
"time_power": 2.0,
|
| 17 |
+
"input_noise_scale": 0.0,
|
| 18 |
+
"input_noise_until": 1.0,
|
| 19 |
+
"input_noise_dirichlet_concentration": 1.0,
|
| 20 |
+
"endpoint_softening": "uniform",
|
| 21 |
+
"endpoint_soft_power": 1.0,
|
| 22 |
+
"endpoint_soft_min_conf": 0.0,
|
| 23 |
+
"endpoint_soft_max_conf": 1.0,
|
| 24 |
+
"final_from": "state",
|
| 25 |
+
"final_decode": "argmax",
|
| 26 |
+
"final_sample_temp": 1.0,
|
| 27 |
+
"final_top_k": 0,
|
| 28 |
+
"final_top_p": 1.0,
|
| 29 |
+
"early_temp": 1.0,
|
| 30 |
+
"late_temp": 1.0,
|
| 31 |
+
"temp_end": 1.0,
|
| 32 |
+
"temp_power": 1.0,
|
| 33 |
+
"pos_extend": "repeat",
|
| 34 |
+
"fixed_first_token_id": null,
|
| 35 |
+
"fixed_first_token_text": "",
|
| 36 |
+
"fixed_first_initial_argmax": false,
|
| 37 |
+
"use_ema": false,
|
| 38 |
+
"n_samples": 8,
|
| 39 |
+
"sample_entropy": 2.4178828420944143,
|
| 40 |
+
"unique_tokens": 524,
|
| 41 |
+
"token_count": 8192,
|
| 42 |
+
"distinct_1": 0.06396484375,
|
| 43 |
+
"distinct_2": 0.1714320625610948,
|
| 44 |
+
"top_token_mass": 0.2064208984375,
|
| 45 |
+
"texts_preview": [
|
| 46 |
+
"the the a...... the on to.. in with. . strategy. in to in been. in. in the in .... the. .. confront... in in to. . the of the a. the the.. . in in . a. . is .. the . in in in in. in in.. mark.s in a� leaving of the A in the in victims in.. in in-... he the. a the of night the in the in. been in., the a . really the in. in the in in. AN in.. been thiss. . in.... the in in�. . the exp nobody a of.. in of.. its in in a in� inm . in. again in. the the the in in to in. –. been. the a in in. trusted- in a in .. in the theAlso a in the in the ,. the the in in . . in.. night in. and the in . in in the in. in to in a in..... . in the initer start in.. the best. when Tuesday. to otherwise . a the in in in in in .....s..... . the reportball, the in as to in. .. of.. in in the. the toities. and a . in the. in the the ref... in and, a. in the- .. in.� to in in in,. a-. to been in in - in.. . to to the . in. . the . to ., in. X the . and margin. in. the is.zip . in tragedy culp in . in. to the in leading .. in in that in . in in a the State in. in a to a the in people. in the. up in in in day� in . in team people. in matchup a. in the reporters a and. of in the in in in people.. a. in the in and. to been. the.�. the- a. to in in in the. . precincts not in.... the the as- the of. to... a. in.. shenanigans a. in . in.. the.. a in- in a , in. in . theint in to, the in..... iniel the ? Hague licence the to the. to . the the in and? the in. the.. the in to in. a. in. the . to. the he the in in the . the the in the ... to. the . on . secretary and. the the Pl,,.s to the. in last the day was on. that in away in the. a been the a. the of the pleaded in ör. and . , the Affairs.� in source been the path to to. 40 stance to to the the. this on the out to in. the and . in users the the the to the in the to. the that... that the this to the?. in. to of the to. the this in. area the.. the this to the the to the the this to. of is and the theich. in. to thes the. the. the. that the . of in.. � this a in largely theier to the.. to this this this the in expects in the the�.. a this to. to the dimension Clinton. to in.. to the the to in in to. this know. this of. that in . the this the Clinton this protracted this the. if this that . the s in this to to. to..?.. .. thisrals the the in to that. people. .. the the... this.. the. in this this. in to in. the this to that.. the and the. this?.. absorb to .... . in. Tuesday a to? a Clinton . to. the the. to in people the",
|
| 47 |
+
"the the... ..... in.. in.. irony .- . . the. the in.. investigation .. of in. the to Share. in the .. . the. in. in.. Ch been. a - . the.. ait.... in in in. November in . a immigrants. in interrogation. in of on� in the in Lew in their inbe t in been in� was. the of in. been in. in ins . in... in.. in and in Hal.. the... in the. the aanted . .<|endoftext|> in the the the. the to the- with. in in in,. a. in. in in in.. the.. . the. on in in in in the . to a in in. . a night More field in a in to respectful. in.s. in in was the in,.. to.. was. in to in. in. the generators in was-. . in power were on the . to the on.. in on on the the. the.. in asked in the- the.ible. a to in. in a red in in in in in. a... in in. on cannon. in in in, in. to. tos in. in million. the in, recount not . a, in a. .. the the.. in in century.�. whose ... in in and a. in grasping.. the in.. in a-. to. in the in. the to to the in. the. in that. in. potentially this ofelection the in.. in in a was.,.. inishing to. in. Sanders right to. a a in. the to in to... the a to the a.. to in. a. in in to in. in in in.� in in. in.. no to in... James . warning that that to . in in to.. in. a. in Char day in.. at of in. on this. the,. in in in substantially inso in.. a in supposedly been in that. a. . the . to. to the in in. to. to. health. dimension. a the in.. this this to the he the the in toird Clinton the sought . to Haiti the evidence fighting- to More Bill in the. the. in. the. to . in. in in to in Frankfurt. been Free to. to in to . . rival the the this....... this in and. supplies. in a in. access of to $ a in �. to last and the in a the . of sten. the country . in the the tend that to... to to. fits and and this on in.. this. the to-handlections. in this this. in. the. the a 1999. this the push. the the to. to the the to. to Kinn that the They. . to a the a to this the in to this in to.. the.. this to that and at to in. and and want out the this . in this . this. to to to of? 146 the.. this. in, the key a this in this this the. that prizes to in this this this and package the this the to this to on to and by the the adequate. on the this the to this this. the the. the intention the to that. this. this the. the the this the in been.. to to the this to.. to this in been� to to . Michigan to the... that this of a to to. the the this that that cause this. this this the this this and...s...,� in the the. understand the .akens to to to in. the. month to the been this to people. . disease to one... the. to you to to been to. . in?? been people .",
|
| 48 |
+
". predominantly.� in. in in. $ war. in wide.. to. in in.. was story in in. overall in...... in in. a in Another in the. in. in over in.. the in. the in the. . in in in.. misled in in the parallels .. tochen..... in in ... in in the Dave in and the you.. in in. in in and in- in in in in the Did. in in in in in� in ..ighting. in in. in in in in<|endoftext|> in. announced�.. . in suddenly in the a. \" in in. . the in. in parallels.. a, in in- in.. in. in in . in on..s in to in in in Fault African of. on in the. oid.. impro in in. a to staff. a in . in to in.. in in. on in on in. in . in. on a the the able a in to in the a That, astonishing in. a in not in 22 a in to. a the . a in in that in a a the in..-.. in to a.. the....04 the to a-. in in ... a Clinton.. the in in.What.. the a in in.. the a. the the . -. Clinton a in the. in.. a in. in. helps.. a., in a that. the team. Council approval a earlier in. that a.-. in, a and in. in a a. the. the in a... the the. a .. in in a and a in. .. in reporters. a. . ... a in a the a. in. in in in.. the. , the in... a.. in. the. .... .. the. a.. a in on., in, the in the in the in. .. s ... in . a shell Imperium ach that a in that in the in in... in in. the. impossible Clinton in a.. in the in . and. to a. the the a discovers Som. steel. in... in. a . in.. of in. in last.. in the .. a. in.. a the provide. a in� a turned in . in in in.. in a. in. the to in to in. in. in. the. the. in tocontained the. in in the the and in to. and., and... think. . in this. that in.elsen.. the a the last .. in... and of that, in this. in. in . states the the in. that and the.. presidential to the. a. in the this.. . the. the. .. in that.. and a especially and in the the.. the. the and . in in and.... this.. fundraising this...? that that . in and.. . in the. and to this. in to this. states that a and this the in. the.,round the and. in and the a. the this the this , to in that. this and the. this in this. . place. in. that.. this this this the in.. that the the the the that and a. the the to that. to is this and.� the Obamacare in � this and. large leaves. this�. in.. considerably. the in to of the. doubt the� that. in to of in the. to and a that. and a that in. the.'. the.. to problem.. .. to. in .. .. the . to. a. advanced.. and� the- the�, noting?Resp a. to to.� in awkward.breaker . to the . to people people the in.. in . ..",
|
| 49 |
+
"the the in in the in Speed . the to. in in in in in in Mueller in in a in in in in her. night in in in to. the. in the the the election in in. the inía is in in in in the. in in the in in in in in in in in in the in in in in in in in the the in in in in the in big the elect the in in in to in in in of. in the. the again in in the in in the. the in.. in the leve. in Element in the the in in to the in in . in the theench in in in the in comics in the the. the in in in the Mail further was to in the in in., to survival in on . the needing the dangerous has. in the in in in clear in in in the theRet in in in in in in in toness in the. to the a to the the in the in in to in the in is in the bush Rich perception in lows. the to an to the. going to to in.. theayed in thehend to to. somehow in to its in in. the.. in. the to the the. in the to the in in to and this Red to the in the in on the to the .uss in on. on to Sport to the in to to the the to a to to in. the. to to to. a in. .. in the in to to lost in to .. the the in the the to in in morning to the in the.. to is. the to to team the spotlight . the to to to the to the the in to to. in to the in the in to to the.. a in to . the the and the the . the to to to in the. the to, the Committee the in to to the to to to the in. is the by in a to the the the in in the to sweep fix.. to in a void people to.. the to the team. the the in roughly the to to in Louis to in. in the. the it to in to. to� . to in what to in team a -- in to the the to election the a the the, the. the in's in the the the a in the the that that in the the the . the the is the up the the the, the that the the to the the the in in the. of the the the the the in the to to in the the . the that the the the message that the the the the the the's to the the manufacturing the.'s the the the in the the the the the madness . the the the the in the to the in the the of - the in to team the the the to to the the in a the. he the the the.. the .. a in. the the dis the the the in the's . to in the the that's. the the a b to the and the. the in the the the. the to to. the the in to cases the the the the the's a the to in to� to people the to the and of to the the to the to the to the to to the to the jet over. the in in. the aMore in to the. in to that the to to to been the the that the the to. the the the in to. that is this to the is to limited of to to the the this to to the like that a in doctors to accepted the theAs the the the the to the the. in to ity the to the. to in this the in only the and to that that is to the that to the the to to to the. to that to and to to to he to this this the the to to the. a to.. this to this . 's that. unfor to to to this the that , push. the this the this the and the. . to. a to to 4 to . . the in the . the des massacres the the"
|
| 50 |
+
],
|
| 51 |
+
"gen_ppl": 45.782616001541655,
|
| 52 |
+
"gen_nll": 3.823904455782646,
|
| 53 |
+
"gen_tokens": 6379
|
| 54 |
+
}
|
| 55 |
+
]
|
LTA_openwebtext_dualt/logs/infer/lta_owt_classic_fullvocab_bert_c1024_len1024_large_d1024_l24_h16_ff4096_lr2e-4_gbs2048_2node8gpu_1m_save10k_t-20260522101129-lwll5_latest_step0012000_shard02_gpu2_b32.log
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[ckpt] runs/lta_owt_classic_fullvocab_bert_c1024_len1024_large_d1024_l24_h16_ff4096_lr2e-4_gbs2048_2node8gpu_1m_save10k_t-20260522101129-lwll5/latest.pt step=12000
|
| 2 |
+
[decode] steps128_c1024_t1p45 generated 32/256
|
| 3 |
+
[decode] steps128_c1024_t1p45 generated 64/256
|
| 4 |
+
[decode] steps128_c1024_t1p45 generated 96/256
|
| 5 |
+
[decode] steps128_c1024_t1p45 generated 128/256
|
| 6 |
+
[decode] steps128_c1024_t1p45 generated 160/256
|
| 7 |
+
[decode] steps128_c1024_t1p45 generated 192/256
|
| 8 |
+
[decode] steps128_c1024_t1p45 generated 224/256
|
| 9 |
+
[decode] steps128_c1024_t1p45 generated 256/256
|
| 10 |
+
[summary] {"name": "steps128_c1024_t1p45", "step": 12000, "decode_steps": 128, "concentration_max": 1024.0, "raw_genppl": 1.041556959243412, "stripped_genppl": 1.041556959243412, "sample_entropy": 0.022794382037306993, "distinct_1": 9.1552734375e-05, "distinct_2": 0.000343658357771261, "top_token_mass": 0.5089492797851562, "raw_kept": 256, "stripped_kept": 256}
|
LTA_openwebtext_dualt/logs/infer/lta_owt_lm1bclassic_fullvocab_bert_c1024_len1024_elfLdim_d1280_l32_h16_ff5120_lr3e-4_gbs512_2node8gpu_1m_save10k_t-20260522071024-s2ss5_latest_step0001000_t1p45_c1024_n1024_gpu0.log
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[ckpt] runs/lta_owt_lm1bclassic_fullvocab_bert_c1024_len1024_elfLdim_d1280_l32_h16_ff5120_lr3e-4_gbs512_2node8gpu_1m_save10k_t-20260522071024-s2ss5/latest.pt step=1000
|
| 2 |
+
[decode] steps128_c1024_t1p45 generated 4/1024
|
| 3 |
+
[decode] steps128_c1024_t1p45 generated 8/1024
|
| 4 |
+
[decode] steps128_c1024_t1p45 generated 12/1024
|
| 5 |
+
[decode] steps128_c1024_t1p45 generated 16/1024
|
| 6 |
+
[decode] steps128_c1024_t1p45 generated 20/1024
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/dependency_versions_check.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2020 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 |
+
|
| 15 |
+
from .dependency_versions_table import deps
|
| 16 |
+
from .utils.versions import require_version, require_version_core
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# define which module versions we always want to check at run time
|
| 20 |
+
# (usually the ones defined in `install_requires` in setup.py)
|
| 21 |
+
#
|
| 22 |
+
# order specific notes:
|
| 23 |
+
# - tqdm must be checked before tokenizers
|
| 24 |
+
|
| 25 |
+
pkgs_to_check_at_runtime = [
|
| 26 |
+
"python",
|
| 27 |
+
"tqdm",
|
| 28 |
+
"regex",
|
| 29 |
+
"packaging",
|
| 30 |
+
"filelock",
|
| 31 |
+
"numpy",
|
| 32 |
+
"tokenizers",
|
| 33 |
+
"huggingface-hub",
|
| 34 |
+
"safetensors",
|
| 35 |
+
"accelerate",
|
| 36 |
+
"pyyaml",
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
for pkg in pkgs_to_check_at_runtime:
|
| 40 |
+
if pkg in deps:
|
| 41 |
+
if pkg == "tokenizers":
|
| 42 |
+
# must be loaded here, or else tqdm check may fail
|
| 43 |
+
from .utils import is_tokenizers_available
|
| 44 |
+
|
| 45 |
+
if not is_tokenizers_available():
|
| 46 |
+
continue # not required, check version only if installed
|
| 47 |
+
elif pkg == "accelerate":
|
| 48 |
+
# must be loaded here, or else tqdm check may fail
|
| 49 |
+
from .utils import is_accelerate_available
|
| 50 |
+
|
| 51 |
+
# Maybe switch to is_torch_available in the future here so that Accelerate is hard dep of
|
| 52 |
+
# Transformers with PyTorch
|
| 53 |
+
if not is_accelerate_available():
|
| 54 |
+
continue # not required, check version only if installed
|
| 55 |
+
|
| 56 |
+
require_version_core(deps[pkg])
|
| 57 |
+
else:
|
| 58 |
+
raise ValueError(f"can't find {pkg} in {deps.keys()}, check dependency_versions_table.py")
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def dep_version_check(pkg, hint=None):
|
| 62 |
+
require_version(deps[pkg], hint)
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/initialization.py
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
import math
|
| 15 |
+
import sys
|
| 16 |
+
from collections import defaultdict
|
| 17 |
+
from contextlib import contextmanager
|
| 18 |
+
|
| 19 |
+
import torch
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
# Record all the torch primitives in advance, so that we can use them without them being modified when we patch torch
|
| 23 |
+
# in context managers
|
| 24 |
+
TORCH_INIT_FUNCTIONS = {
|
| 25 |
+
"uniform_": torch.nn.init.uniform_,
|
| 26 |
+
"normal_": torch.nn.init.normal_,
|
| 27 |
+
"constant_": torch.nn.init.constant_,
|
| 28 |
+
"ones_": torch.nn.init.ones_,
|
| 29 |
+
"zeros_": torch.nn.init.zeros_,
|
| 30 |
+
"eye_": torch.nn.init.eye_,
|
| 31 |
+
"dirac_": torch.nn.init.dirac_,
|
| 32 |
+
"xavier_uniform_": torch.nn.init.xavier_uniform_,
|
| 33 |
+
"xavier_normal_": torch.nn.init.xavier_normal_,
|
| 34 |
+
"kaiming_uniform_": torch.nn.init.kaiming_uniform_,
|
| 35 |
+
"kaiming_normal_": torch.nn.init.kaiming_normal_,
|
| 36 |
+
"trunc_normal_": torch.nn.init.trunc_normal_,
|
| 37 |
+
"orthogonal_": torch.nn.init.orthogonal_,
|
| 38 |
+
"sparse_": torch.nn.init.sparse_,
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def uniform_(
|
| 43 |
+
tensor: torch.Tensor, a: float = 0.0, b: float = 1.0, generator: torch.Generator | None = None
|
| 44 |
+
) -> torch.Tensor:
|
| 45 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 46 |
+
return TORCH_INIT_FUNCTIONS["uniform_"](tensor, a=a, b=b, generator=generator)
|
| 47 |
+
return tensor
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def normal_(
|
| 51 |
+
tensor: torch.Tensor, mean: float = 0.0, std: float = 1.0, generator: torch.Generator | None = None
|
| 52 |
+
) -> torch.Tensor:
|
| 53 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 54 |
+
return TORCH_INIT_FUNCTIONS["normal_"](tensor, mean=mean, std=std, generator=generator)
|
| 55 |
+
return tensor
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def constant_(tensor: torch.Tensor, val: float) -> torch.Tensor:
|
| 59 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 60 |
+
return TORCH_INIT_FUNCTIONS["constant_"](tensor, val=val)
|
| 61 |
+
return tensor
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def ones_(tensor: torch.Tensor) -> torch.Tensor:
|
| 65 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 66 |
+
return TORCH_INIT_FUNCTIONS["ones_"](tensor)
|
| 67 |
+
return tensor
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def zeros_(tensor: torch.Tensor) -> torch.Tensor:
|
| 71 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 72 |
+
return TORCH_INIT_FUNCTIONS["zeros_"](tensor)
|
| 73 |
+
return tensor
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def eye_(tensor: torch.Tensor) -> torch.Tensor:
|
| 77 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 78 |
+
return TORCH_INIT_FUNCTIONS["eye_"](tensor)
|
| 79 |
+
return tensor
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def dirac_(tensor: torch.Tensor, groups: int = 1) -> torch.Tensor:
|
| 83 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 84 |
+
return TORCH_INIT_FUNCTIONS["dirac_"](tensor, groups=groups)
|
| 85 |
+
return tensor
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def xavier_uniform_(tensor: torch.Tensor, gain: float = 1.0, generator: torch.Generator | None = None) -> torch.Tensor:
|
| 89 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 90 |
+
return TORCH_INIT_FUNCTIONS["xavier_uniform_"](tensor, gain=gain, generator=generator)
|
| 91 |
+
return tensor
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def xavier_normal_(tensor: torch.Tensor, gain: float = 1.0, generator: torch.Generator | None = None) -> torch.Tensor:
|
| 95 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 96 |
+
return TORCH_INIT_FUNCTIONS["xavier_normal_"](tensor, gain=gain, generator=generator)
|
| 97 |
+
return tensor
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def kaiming_uniform_(
|
| 101 |
+
tensor: torch.Tensor,
|
| 102 |
+
a: float = 0,
|
| 103 |
+
mode: str = "fan_in",
|
| 104 |
+
nonlinearity: str = "leaky_relu",
|
| 105 |
+
generator: torch.Generator | None = None,
|
| 106 |
+
) -> torch.Tensor:
|
| 107 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 108 |
+
return TORCH_INIT_FUNCTIONS["kaiming_uniform_"](
|
| 109 |
+
tensor, a=a, mode=mode, nonlinearity=nonlinearity, generator=generator
|
| 110 |
+
)
|
| 111 |
+
return tensor
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def kaiming_normal_(
|
| 115 |
+
tensor: torch.Tensor,
|
| 116 |
+
a: float = 0,
|
| 117 |
+
mode: str = "fan_in",
|
| 118 |
+
nonlinearity: str = "leaky_relu",
|
| 119 |
+
generator: torch.Generator | None = None,
|
| 120 |
+
) -> torch.Tensor:
|
| 121 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 122 |
+
return TORCH_INIT_FUNCTIONS["kaiming_normal_"](
|
| 123 |
+
tensor, a=a, mode=mode, nonlinearity=nonlinearity, generator=generator
|
| 124 |
+
)
|
| 125 |
+
return tensor
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def trunc_normal_(
|
| 129 |
+
tensor: torch.Tensor,
|
| 130 |
+
mean: float = 0.0,
|
| 131 |
+
std: float = 1.0,
|
| 132 |
+
a: float = -2.0,
|
| 133 |
+
b: float = 2.0,
|
| 134 |
+
generator: torch.Generator | None = None,
|
| 135 |
+
) -> torch.Tensor:
|
| 136 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 137 |
+
return TORCH_INIT_FUNCTIONS["trunc_normal_"](tensor, mean=mean, std=std, a=a, b=b, generator=generator)
|
| 138 |
+
return tensor
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def orthogonal_(
|
| 142 |
+
tensor: torch.Tensor,
|
| 143 |
+
gain: float = 1,
|
| 144 |
+
generator: torch.Generator | None = None,
|
| 145 |
+
) -> torch.Tensor:
|
| 146 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 147 |
+
return TORCH_INIT_FUNCTIONS["orthogonal_"](tensor, gain=gain, generator=generator)
|
| 148 |
+
return tensor
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def sparse_(
|
| 152 |
+
tensor: torch.Tensor, sparsity: float, std: float = 0.01, generator: torch.Generator | None = None
|
| 153 |
+
) -> torch.Tensor:
|
| 154 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 155 |
+
return TORCH_INIT_FUNCTIONS["sparse_"](tensor, sparsity=sparsity, std=std, generator=generator)
|
| 156 |
+
return tensor
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def copy_(tensor: torch.Tensor, other: torch.Tensor) -> torch.Tensor:
|
| 160 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 161 |
+
with torch.no_grad():
|
| 162 |
+
return tensor.copy_(other)
|
| 163 |
+
return tensor
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def _variance_scaling(tensor, mode="fan_in", distribution="normal"):
|
| 167 |
+
fan_in, fan_out = torch.nn.init._calculate_fan_in_and_fan_out(tensor)
|
| 168 |
+
if mode == "fan_in":
|
| 169 |
+
denom = fan_in
|
| 170 |
+
elif mode == "fan_out":
|
| 171 |
+
denom = fan_out
|
| 172 |
+
elif mode == "fan_avg":
|
| 173 |
+
denom = (fan_in + fan_out) / 2
|
| 174 |
+
|
| 175 |
+
variance = 1.0 / denom
|
| 176 |
+
|
| 177 |
+
if distribution == "truncated_normal":
|
| 178 |
+
trunc_normal_(tensor, std=math.sqrt(variance) / 0.87962566103423978)
|
| 179 |
+
elif distribution == "normal":
|
| 180 |
+
normal_(tensor, std=math.sqrt(variance))
|
| 181 |
+
elif distribution == "uniform":
|
| 182 |
+
bound = math.sqrt(3 * variance)
|
| 183 |
+
uniform_(tensor, -bound, bound)
|
| 184 |
+
else:
|
| 185 |
+
raise ValueError(f"invalid distribution {distribution}")
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def lecun_normal_(tensor):
|
| 189 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 190 |
+
_variance_scaling(tensor, mode="fan_in", distribution="truncated_normal")
|
| 191 |
+
return tensor
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def default_flax_embed_init_(tensor):
|
| 195 |
+
if not getattr(tensor, "_is_hf_initialized", False):
|
| 196 |
+
_variance_scaling(tensor, mode="fan_in", distribution="normal")
|
| 197 |
+
return tensor
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
# Here, we need to check several modules imported, and hot patch all of them, as sometimes torch does
|
| 201 |
+
# something like `from torch.nn.init import xavier_uniform_` in their internals (e.g in torch.nn.modules.activations,
|
| 202 |
+
# where MultiHeadAttention lives), so the function name is binded at import time and just doing
|
| 203 |
+
# `setattr(torch.nn.init, name, globals()[name])` is thus not enough
|
| 204 |
+
# The following list should be enough for all torch versions we work with
|
| 205 |
+
TORCH_MODULES_TO_PATCH = (
|
| 206 |
+
"torch.nn.init",
|
| 207 |
+
"torch.nn.modules.activation",
|
| 208 |
+
"torch.nn.modules.transformer",
|
| 209 |
+
"torch.nn.modules.linear",
|
| 210 |
+
"torch.nn.modules.loss",
|
| 211 |
+
"torch.nn.modules.batchnorm",
|
| 212 |
+
"torch.nn.modules.conv",
|
| 213 |
+
"torch.nn.modules.normalization",
|
| 214 |
+
"torch.nn.modules.rnn",
|
| 215 |
+
"torch.nn.modules.sparse",
|
| 216 |
+
)
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
@contextmanager
|
| 220 |
+
def guard_torch_init_functions():
|
| 221 |
+
"""
|
| 222 |
+
Guard the `torch.nn.init` primitive functions to behave exactly like the functions in this file, i.e. be
|
| 223 |
+
protected against the `_is_hf_initialized` flag to avoid re-init if the param was already loaded.
|
| 224 |
+
|
| 225 |
+
Usually, all models are using the init from `transformers` which are already guarded, but just to make extra sure
|
| 226 |
+
and for remote code, we also use this context manager.
|
| 227 |
+
"""
|
| 228 |
+
originals = defaultdict(dict)
|
| 229 |
+
try:
|
| 230 |
+
# Replace all torch funcs by the ones in this file
|
| 231 |
+
for module_name in TORCH_MODULES_TO_PATCH:
|
| 232 |
+
if module_name in sys.modules:
|
| 233 |
+
module = sys.modules[module_name]
|
| 234 |
+
for func_name in TORCH_INIT_FUNCTIONS.keys():
|
| 235 |
+
if hasattr(module, func_name):
|
| 236 |
+
originals[module][func_name] = getattr(module, func_name)
|
| 237 |
+
setattr(module, func_name, globals()[func_name])
|
| 238 |
+
yield
|
| 239 |
+
finally:
|
| 240 |
+
# Set back the original functions on all modules
|
| 241 |
+
for module, functions in originals.items():
|
| 242 |
+
for func_name, func in functions.items():
|
| 243 |
+
setattr(module, func_name, func)
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
@contextmanager
|
| 247 |
+
def no_init_weights():
|
| 248 |
+
"""
|
| 249 |
+
Disable weight initialization both at the torch-level, and at the transformers-level (`init_weights`).
|
| 250 |
+
This is used to speed-up initializing an empty model with deepspeed, as we do not initialize the model on meta device
|
| 251 |
+
with deepspeed, but we still don't need to run expensive weight initializations as we are loading params afterwards.
|
| 252 |
+
"""
|
| 253 |
+
from .modeling_utils import PreTrainedModel
|
| 254 |
+
|
| 255 |
+
def empty_func(*args, **kwargs):
|
| 256 |
+
pass
|
| 257 |
+
|
| 258 |
+
originals = defaultdict(dict)
|
| 259 |
+
try:
|
| 260 |
+
# Replace all torch funcs by empty ones
|
| 261 |
+
for module_name in TORCH_MODULES_TO_PATCH:
|
| 262 |
+
if module_name in sys.modules:
|
| 263 |
+
module = sys.modules[module_name]
|
| 264 |
+
for func_name in TORCH_INIT_FUNCTIONS.keys():
|
| 265 |
+
if hasattr(module, func_name):
|
| 266 |
+
originals[module][func_name] = getattr(module, func_name)
|
| 267 |
+
setattr(module, func_name, empty_func)
|
| 268 |
+
|
| 269 |
+
# Also patch our own `init_weights`
|
| 270 |
+
original_init_weights = PreTrainedModel.init_weights
|
| 271 |
+
PreTrainedModel.init_weights = empty_func
|
| 272 |
+
|
| 273 |
+
yield
|
| 274 |
+
finally:
|
| 275 |
+
# Set back the original torch functions on all modules
|
| 276 |
+
for module, functions in originals.items():
|
| 277 |
+
for func_name, func in functions.items():
|
| 278 |
+
setattr(module, func_name, func)
|
| 279 |
+
# Set back `init_weights`
|
| 280 |
+
PreTrainedModel.init_weights = original_init_weights
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
@contextmanager
|
| 284 |
+
def no_tie_weights():
|
| 285 |
+
"""
|
| 286 |
+
Disable weight tying during loading with `from_pretrained`. This is needed as we want to have access to ALL
|
| 287 |
+
weights in the state_dict during `from_pretrained`, and otherwise tying them would remove them from it, as it's
|
| 288 |
+
called in `post_init` when instantiating.
|
| 289 |
+
"""
|
| 290 |
+
from .modeling_utils import PreTrainedModel
|
| 291 |
+
|
| 292 |
+
def empty_func(*args, **kwargs):
|
| 293 |
+
pass
|
| 294 |
+
|
| 295 |
+
try:
|
| 296 |
+
original_tie_weights = PreTrainedModel.tie_weights
|
| 297 |
+
PreTrainedModel.tie_weights = empty_func
|
| 298 |
+
|
| 299 |
+
yield
|
| 300 |
+
finally:
|
| 301 |
+
# Set back the original
|
| 302 |
+
PreTrainedModel.tie_weights = original_tie_weights
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
@contextmanager
|
| 306 |
+
def meta_device_safe_creation_ops():
|
| 307 |
+
"""
|
| 308 |
+
During meta-device model initialisation, ``torch.linspace`` produces meta
|
| 309 |
+
tensors that have no data. Custom models loaded from the Hub (remote code)
|
| 310 |
+
often call ``.item()`` on these tensors to compute scalar hyperparameters
|
| 311 |
+
(e.g. stochastic-depth / drop-path schedules). Native transformers models
|
| 312 |
+
already pass ``device="cpu"`` explicitly for such calls (see e.g.
|
| 313 |
+
``modeling_swin.py``, ``modeling_pvt_v2.py``), but remote-code models
|
| 314 |
+
written before v5 do not.
|
| 315 |
+
|
| 316 |
+
This context manager patches ``torch.linspace`` to default to
|
| 317 |
+
``device="cpu"`` when no explicit device is requested, matching the best
|
| 318 |
+
practice already used throughout transformers. Calls that supply an
|
| 319 |
+
explicit ``device`` argument (e.g. ``device=self.logits.device``) are left
|
| 320 |
+
untouched. ``torch.arange`` is intentionally NOT patched because it is
|
| 321 |
+
used in RoPE computations where the device must match model parameters.
|
| 322 |
+
"""
|
| 323 |
+
original_linspace = torch.linspace
|
| 324 |
+
|
| 325 |
+
def _safe_linspace(*args, **kwargs):
|
| 326 |
+
kwargs.setdefault("device", "cpu")
|
| 327 |
+
return original_linspace(*args, **kwargs)
|
| 328 |
+
|
| 329 |
+
torch.linspace = _safe_linspace
|
| 330 |
+
try:
|
| 331 |
+
yield
|
| 332 |
+
finally:
|
| 333 |
+
torch.linspace = original_linspace
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/granite_speech_plus/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2026 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_granite_speech_plus import *
|
| 22 |
+
from .modeling_granite_speech_plus 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/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/granite_speech_plus/configuration_granite_speech_plus.py
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 2 |
+
# This file was automatically generated from src/transformers/models/granite_speech_plus/modular_granite_speech_plus.py.
|
| 3 |
+
# Do NOT edit this file manually as any edits will be overwritten by the generation of
|
| 4 |
+
# the file from the modular. If any change should be done, please apply the change to the
|
| 5 |
+
# modular_granite_speech_plus.py file directly. One of our CI enforces this.
|
| 6 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 7 |
+
# Copyright 2026 The HuggingFace Inc. team.
|
| 8 |
+
#
|
| 9 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
# you may not use this file except in compliance with the License.
|
| 11 |
+
# You may obtain a copy of the License at
|
| 12 |
+
#
|
| 13 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
#
|
| 15 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
# See the License for the specific language governing permissions and
|
| 19 |
+
# limitations under the License.
|
| 20 |
+
from huggingface_hub.dataclasses import strict
|
| 21 |
+
|
| 22 |
+
from ...configuration_utils import PreTrainedConfig
|
| 23 |
+
from ...utils import auto_docstring
|
| 24 |
+
from ..auto import CONFIG_MAPPING, AutoConfig
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@auto_docstring(checkpoint="ibm-granite/granite-speech-4.1-2b-plus")
|
| 28 |
+
@strict
|
| 29 |
+
class GraniteSpeechPlusEncoderConfig(PreTrainedConfig):
|
| 30 |
+
r"""
|
| 31 |
+
feedforward_mult (`int`, *optional*, defaults to 4):
|
| 32 |
+
Multiplier for the up/down projections in the encoder's feedforward layers;
|
| 33 |
+
The projections will have intermediate dim of size `hidden_dim * feedforward_mult`.
|
| 34 |
+
output_dim (`int`, *optional*, defaults to 42):
|
| 35 |
+
Intermediate dimension of the feedforward projections in the conformer
|
| 36 |
+
to be added to every other encoder block's output.
|
| 37 |
+
context_size (`int`, *optional*, defaults to 200):
|
| 38 |
+
Context size to be used in conformer attention.
|
| 39 |
+
max_pos_emb (`int`, *optional*, defaults to 512):
|
| 40 |
+
Max pos embeds to be used in attention (shaw's relative positional encoding).
|
| 41 |
+
conv_expansion_factor (`int`, *optional*, defaults to 2):
|
| 42 |
+
Intermediate dimension to be used in conformer convolutions.
|
| 43 |
+
cat_hidden_layers (`list[int]`, *optional*):
|
| 44 |
+
Indices of encoder conformer layers whose outputs are concatenated with the final encoder
|
| 45 |
+
output (along the feature dimension) before being passed to the projector. When set, the
|
| 46 |
+
projector's ``encoder_hidden_size`` must equal
|
| 47 |
+
``encoder_config.hidden_dim * (len(cat_hidden_layers) + 1)``.
|
| 48 |
+
|
| 49 |
+
Example:
|
| 50 |
+
|
| 51 |
+
```python
|
| 52 |
+
>>> from transformers import GraniteSpeechPlusEncoderConfig, GraniteSpeechPlusCTCEncoder
|
| 53 |
+
|
| 54 |
+
>>> # Initializing a GraniteSpeechPlusEncoderConfig
|
| 55 |
+
>>> configuration = GraniteSpeechPlusEncoderConfig()
|
| 56 |
+
|
| 57 |
+
>>> # Initializing a GraniteSpeechPlusCTCEncoder (with random weights)
|
| 58 |
+
>>> model = GraniteSpeechPlusCTCEncoder(configuration)
|
| 59 |
+
|
| 60 |
+
>>> # Accessing the model configuration
|
| 61 |
+
>>> configuration = model.config
|
| 62 |
+
```"""
|
| 63 |
+
|
| 64 |
+
model_type = "granite_speech_plus_encoder"
|
| 65 |
+
attribute_map = {
|
| 66 |
+
"hidden_size": "hidden_dim",
|
| 67 |
+
"num_hidden_layers": "num_layers",
|
| 68 |
+
"num_attention_heads": "num_heads",
|
| 69 |
+
"num_mel_bins": "input_dim",
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
input_dim: int = 160
|
| 73 |
+
num_layers: int = 10
|
| 74 |
+
hidden_dim: int = 1024
|
| 75 |
+
feedforward_mult: int = 4
|
| 76 |
+
num_heads: int = 8
|
| 77 |
+
dim_head: int | None = None
|
| 78 |
+
output_dim: int = 42
|
| 79 |
+
context_size: int = 200
|
| 80 |
+
max_pos_emb: int = 512
|
| 81 |
+
dropout: float | int = 0.1
|
| 82 |
+
conv_kernel_size: int = 15
|
| 83 |
+
conv_expansion_factor: int = 2
|
| 84 |
+
|
| 85 |
+
cat_hidden_layers: list[int] | None = None
|
| 86 |
+
|
| 87 |
+
def __post_init__(self, **kwargs):
|
| 88 |
+
super().__post_init__(**kwargs)
|
| 89 |
+
if self.dim_head is None:
|
| 90 |
+
self.dim_head = self.hidden_dim // self.num_heads
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
@auto_docstring(checkpoint="ibm-granite/granite-speech-4.1-2b-plus")
|
| 94 |
+
@strict
|
| 95 |
+
class GraniteSpeechPlusConfig(PreTrainedConfig):
|
| 96 |
+
r"""
|
| 97 |
+
projector_config (`Union[AutoConfig, dict]`, *optional*, defaults to `Blip2QFormerConfig`):
|
| 98 |
+
The config object or dictionary of the audio projector.
|
| 99 |
+
has_lora_adapter (`bool`, *optional*, defaults to `True`):
|
| 100 |
+
Indicates whether or not the model has a lora adapter that should only
|
| 101 |
+
be activate when processing audio inputs.
|
| 102 |
+
downsample_rate (`int`, *optional*, defaults to 5):
|
| 103 |
+
Downsample rate for the audio feature extractor.
|
| 104 |
+
window_size (`int`, *optional*, defaults to 15):
|
| 105 |
+
Window size for the audio feature projector.
|
| 106 |
+
|
| 107 |
+
Example:
|
| 108 |
+
|
| 109 |
+
```python
|
| 110 |
+
>>> from transformers import GraniteSpeechPlusConfig, GraniteSpeechPlusForConditionalGeneration
|
| 111 |
+
|
| 112 |
+
>>> # Initializing a GraniteSpeechPlusConfig
|
| 113 |
+
>>> configuration = GraniteSpeechPlusConfig()
|
| 114 |
+
|
| 115 |
+
>>> # Initializing a GraniteSpeechPlusForConditionalGeneration (with random weights)
|
| 116 |
+
>>> model = GraniteSpeechPlusForConditionalGeneration(configuration)
|
| 117 |
+
|
| 118 |
+
>>> # Accessing the model configuration
|
| 119 |
+
>>> configuration = model.config
|
| 120 |
+
```"""
|
| 121 |
+
|
| 122 |
+
model_type = "granite_speech_plus"
|
| 123 |
+
attribute_map = {
|
| 124 |
+
"audio_token_id": "audio_token_index",
|
| 125 |
+
}
|
| 126 |
+
sub_configs = {
|
| 127 |
+
"text_config": AutoConfig,
|
| 128 |
+
"encoder_config": GraniteSpeechPlusEncoderConfig,
|
| 129 |
+
"projector_config": AutoConfig,
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
text_config: dict | PreTrainedConfig | None = None
|
| 133 |
+
encoder_config: dict | PreTrainedConfig | None = None
|
| 134 |
+
projector_config: dict | PreTrainedConfig | None = None
|
| 135 |
+
audio_token_index: int = 49155
|
| 136 |
+
initializer_range: float = 0.02
|
| 137 |
+
has_lora_adapter: bool = True
|
| 138 |
+
downsample_rate: int = 5
|
| 139 |
+
window_size: int = 15
|
| 140 |
+
|
| 141 |
+
def __post_init__(self, **kwargs):
|
| 142 |
+
if isinstance(self.text_config, dict):
|
| 143 |
+
self.text_config["model_type"] = self.text_config.get("model_type", "granite")
|
| 144 |
+
self.text_config = CONFIG_MAPPING[self.text_config["model_type"]](**self.text_config)
|
| 145 |
+
elif self.text_config is None:
|
| 146 |
+
self.text_config = CONFIG_MAPPING["granite"]()
|
| 147 |
+
|
| 148 |
+
if isinstance(self.projector_config, dict):
|
| 149 |
+
self.projector_config["model_type"] = self.projector_config.get("model_type", "blip_2_qformer")
|
| 150 |
+
self.projector_config = CONFIG_MAPPING[self.projector_config["model_type"]](**self.projector_config)
|
| 151 |
+
elif self.projector_config is None:
|
| 152 |
+
self.projector_config = CONFIG_MAPPING["blip_2_qformer"]()
|
| 153 |
+
|
| 154 |
+
if not isinstance(self.encoder_config, GraniteSpeechPlusEncoderConfig):
|
| 155 |
+
self.encoder_config = {} if self.encoder_config is None else self.encoder_config
|
| 156 |
+
self.encoder_config = GraniteSpeechPlusEncoderConfig(**self.encoder_config)
|
| 157 |
+
|
| 158 |
+
super().__post_init__(**kwargs)
|
| 159 |
+
|
| 160 |
+
if self.encoder_config.cat_hidden_layers is not None:
|
| 161 |
+
for idx in self.encoder_config.cat_hidden_layers:
|
| 162 |
+
if idx < 0 or idx >= self.encoder_config.num_layers:
|
| 163 |
+
raise ValueError(
|
| 164 |
+
f"cat_hidden_layers index {idx} is out of range [0, {self.encoder_config.num_layers})."
|
| 165 |
+
)
|
| 166 |
+
if self.encoder_config.cat_hidden_layers is not None:
|
| 167 |
+
num_concat = len(self.encoder_config.cat_hidden_layers) + 1
|
| 168 |
+
if self.projector_config.encoder_hidden_size != self.encoder_config.hidden_dim * num_concat:
|
| 169 |
+
raise ValueError(
|
| 170 |
+
f"projector encoder_hidden_size {self.projector_config.encoder_hidden_size} "
|
| 171 |
+
f"must equal encoder hidden_dim * {num_concat} = "
|
| 172 |
+
f"{self.encoder_config.hidden_dim * num_concat}."
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
__all__ = ["GraniteSpeechPlusConfig", "GraniteSpeechPlusEncoderConfig"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/granite_speech_plus/modeling_granite_speech_plus.py
ADDED
|
@@ -0,0 +1,622 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 2 |
+
# This file was automatically generated from src/transformers/models/granite_speech_plus/modular_granite_speech_plus.py.
|
| 3 |
+
# Do NOT edit this file manually as any edits will be overwritten by the generation of
|
| 4 |
+
# the file from the modular. If any change should be done, please apply the change to the
|
| 5 |
+
# modular_granite_speech_plus.py file directly. One of our CI enforces this.
|
| 6 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 7 |
+
# Copyright 2026 The HuggingFace Inc. team.
|
| 8 |
+
#
|
| 9 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
# you may not use this file except in compliance with the License.
|
| 11 |
+
# You may obtain a copy of the License at
|
| 12 |
+
#
|
| 13 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
#
|
| 15 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
# See the License for the specific language governing permissions and
|
| 19 |
+
# limitations under the License.
|
| 20 |
+
|
| 21 |
+
import math
|
| 22 |
+
from dataclasses import dataclass
|
| 23 |
+
|
| 24 |
+
import torch
|
| 25 |
+
import torch.nn.functional as F
|
| 26 |
+
from torch import nn
|
| 27 |
+
|
| 28 |
+
from ... import initialization as init
|
| 29 |
+
from ...cache_utils import Cache
|
| 30 |
+
from ...generation import GenerationMixin
|
| 31 |
+
from ...modeling_outputs import BaseModelOutputWithPooling, ModelOutput
|
| 32 |
+
from ...modeling_utils import PreTrainedModel
|
| 33 |
+
from ...processing_utils import Unpack
|
| 34 |
+
from ...utils import (
|
| 35 |
+
TransformersKwargs,
|
| 36 |
+
auto_docstring,
|
| 37 |
+
can_return_tuple,
|
| 38 |
+
is_peft_available,
|
| 39 |
+
logging,
|
| 40 |
+
torch_compilable_check,
|
| 41 |
+
)
|
| 42 |
+
from ...utils.generic import merge_with_config_defaults
|
| 43 |
+
from ...utils.output_capturing import capture_outputs
|
| 44 |
+
from ..auto import AutoModel, AutoModelForCausalLM
|
| 45 |
+
from .configuration_granite_speech_plus import GraniteSpeechPlusConfig, GraniteSpeechPlusEncoderConfig
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
logger = logging.get_logger(__name__)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
### Projector
|
| 52 |
+
class GraniteSpeechPlusEncoderProjector(nn.Module):
|
| 53 |
+
def __init__(self, config: GraniteSpeechPlusConfig):
|
| 54 |
+
super().__init__()
|
| 55 |
+
self.hidden_size = config.projector_config.hidden_size
|
| 56 |
+
self.downsample_rate = config.downsample_rate
|
| 57 |
+
self.window_size = config.window_size
|
| 58 |
+
self.num_queries = config.window_size // config.downsample_rate
|
| 59 |
+
|
| 60 |
+
self.query = nn.Parameter(torch.zeros(1, self.num_queries, config.projector_config.hidden_size))
|
| 61 |
+
self.query.data.normal_(mean=0.0, std=1.0)
|
| 62 |
+
|
| 63 |
+
# By default, this will be a blip_2_qformer config
|
| 64 |
+
self.qformer = AutoModel.from_config(config.projector_config)
|
| 65 |
+
self.linear = nn.Linear(config.projector_config.hidden_size, config.text_config.hidden_size)
|
| 66 |
+
|
| 67 |
+
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
| 68 |
+
batch_size, seq_len, dim = hidden_states.size()
|
| 69 |
+
nblocks = math.ceil(seq_len / self.window_size)
|
| 70 |
+
pad = nblocks * self.window_size - seq_len
|
| 71 |
+
hidden_states = nn.functional.pad(hidden_states, (0, 0, 0, pad), "constant", 0)
|
| 72 |
+
hidden_states = hidden_states.view(batch_size * nblocks, self.window_size, dim)
|
| 73 |
+
|
| 74 |
+
query_output = self.qformer(
|
| 75 |
+
query_embeds=self.query,
|
| 76 |
+
encoder_hidden_states=hidden_states,
|
| 77 |
+
encoder_attention_mask=None,
|
| 78 |
+
return_dict=True,
|
| 79 |
+
)
|
| 80 |
+
query_proj = self.linear(
|
| 81 |
+
query_output.last_hidden_state.view(batch_size, nblocks * self.window_size // self.downsample_rate, -1)
|
| 82 |
+
)
|
| 83 |
+
return query_proj
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
@auto_docstring
|
| 87 |
+
class GraniteSpeechPlusPreTrainedModel(PreTrainedModel):
|
| 88 |
+
config: GraniteSpeechPlusConfig
|
| 89 |
+
input_modalities = ("audio", "text")
|
| 90 |
+
|
| 91 |
+
_supports_flash_attn = False # `blip_2_qformer` dependency does not allow for this
|
| 92 |
+
_supports_sdpa = True
|
| 93 |
+
|
| 94 |
+
@torch.no_grad()
|
| 95 |
+
def _init_weights(self, module: nn.Module):
|
| 96 |
+
"""Initialize the weights."""
|
| 97 |
+
super()._init_weights(module)
|
| 98 |
+
if isinstance(module, GraniteSpeechPlusEncoderProjector):
|
| 99 |
+
init.normal_(module.query)
|
| 100 |
+
elif isinstance(module, GraniteSpeechPlusCTCEncoder):
|
| 101 |
+
context_size = module.config.context_size
|
| 102 |
+
seq = torch.arange(context_size)
|
| 103 |
+
relpos_dist = seq.view(-1, 1) - seq.view(1, -1)
|
| 104 |
+
attention_dists = torch.clamp(relpos_dist, -context_size, context_size) + module.config.max_pos_emb
|
| 105 |
+
init.copy_(module.attention_dists, attention_dists)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
### Encoder - conformer is adapted from: https://github.com/lucidrains/conformer.git
|
| 109 |
+
class GraniteSpeechPlusConformerFeedForward(nn.Module):
|
| 110 |
+
"""Feedforward module for conformer encoder blocks."""
|
| 111 |
+
|
| 112 |
+
def __init__(self, config: GraniteSpeechPlusEncoderConfig):
|
| 113 |
+
super().__init__()
|
| 114 |
+
self.pre_norm = nn.LayerNorm(config.hidden_dim)
|
| 115 |
+
self.up_proj = nn.Linear(config.hidden_dim, config.hidden_dim * config.feedforward_mult)
|
| 116 |
+
self.silu = nn.SiLU()
|
| 117 |
+
self.dropout = nn.Dropout(config.dropout)
|
| 118 |
+
self.down_proj = nn.Linear(config.hidden_dim * config.feedforward_mult, config.hidden_dim)
|
| 119 |
+
|
| 120 |
+
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
| 121 |
+
hidden_states = self.pre_norm(hidden_states)
|
| 122 |
+
hidden_states = self.up_proj(hidden_states)
|
| 123 |
+
hidden_states = self.dropout(self.silu(hidden_states))
|
| 124 |
+
hidden_states = self.down_proj(hidden_states)
|
| 125 |
+
hidden_states = self.dropout(hidden_states)
|
| 126 |
+
return hidden_states
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
class GraniteSpeechPlusConformerAttention(nn.Module):
|
| 130 |
+
"""Attention for conformer blocks using Shaw's relative positional embeddings.
|
| 131 |
+
See the following [paper](https://huggingface.co/papers/1803.02155) for more details.
|
| 132 |
+
"""
|
| 133 |
+
|
| 134 |
+
def __init__(self, config: GraniteSpeechPlusEncoderConfig):
|
| 135 |
+
super().__init__()
|
| 136 |
+
|
| 137 |
+
inner_dim = config.dim_head * config.num_heads
|
| 138 |
+
self.max_pos_emb = config.max_pos_emb
|
| 139 |
+
self.context_size = config.context_size
|
| 140 |
+
self.num_heads = config.num_heads
|
| 141 |
+
self.dim_head = config.dim_head
|
| 142 |
+
self.scale = self.dim_head**-0.5
|
| 143 |
+
self.pre_norm = nn.LayerNorm(config.hidden_dim)
|
| 144 |
+
self.to_q = nn.Linear(config.hidden_dim, inner_dim, bias=False)
|
| 145 |
+
self.to_kv = nn.Linear(config.hidden_dim, inner_dim * 2, bias=False)
|
| 146 |
+
self.to_out = nn.Linear(inner_dim, config.hidden_dim)
|
| 147 |
+
self.rel_pos_emb = nn.Embedding(2 * self.max_pos_emb + 1, self.dim_head)
|
| 148 |
+
self.dropout = nn.Dropout(config.dropout)
|
| 149 |
+
|
| 150 |
+
if self.context_size <= 0 or self.context_size > self.max_pos_emb:
|
| 151 |
+
raise ValueError("Context size is either less than 0 or exceeds the max_pos_emb")
|
| 152 |
+
|
| 153 |
+
def forward(self, hidden_states: torch.Tensor, attention_dists: torch.Tensor) -> torch.Tensor:
|
| 154 |
+
hidden_states = self.pre_norm(hidden_states)
|
| 155 |
+
bsz, num_features, _ = hidden_states.shape
|
| 156 |
+
|
| 157 |
+
num_blocks = math.ceil(num_features / self.context_size)
|
| 158 |
+
remainder = num_features % self.context_size
|
| 159 |
+
if remainder > 0:
|
| 160 |
+
# right padding to reach block size
|
| 161 |
+
hidden_states = torch.nn.functional.pad(hidden_states, (0, 0, 0, self.context_size - remainder))
|
| 162 |
+
|
| 163 |
+
query_states = self.to_q(hidden_states)
|
| 164 |
+
key_states, value_states = self.to_kv(hidden_states).chunk(2, dim=-1)
|
| 165 |
+
|
| 166 |
+
query_states = query_states.reshape(bsz, num_blocks, self.context_size, self.num_heads, -1).transpose(2, 3)
|
| 167 |
+
key_states = key_states.reshape(bsz, num_blocks, self.context_size, self.num_heads, -1).transpose(2, 3)
|
| 168 |
+
value_states = value_states.reshape(bsz, num_blocks, self.context_size, self.num_heads, -1).transpose(2, 3)
|
| 169 |
+
|
| 170 |
+
# shaw's relative positional embedding
|
| 171 |
+
rel_pos_emb = self.rel_pos_emb(attention_dists)
|
| 172 |
+
# alternative computation of `pos_attn` - for readability
|
| 173 |
+
# rel_pos_emb_expanded = rel_pos_emb.view([1, 1, 1] + list(rel_pos_emb.shape))
|
| 174 |
+
# pos_attn = torch.sum(query_states.unsqueeze(-2) * rel_pos_emb_expanded, dim=-1) * self.scale
|
| 175 |
+
# einsum implementation of pos_attn - gives x30 speedup over the alternative
|
| 176 |
+
# TODO (@avihu111) find a fast alternative to einsum
|
| 177 |
+
pos_attn = torch.einsum("b m h c d, c r d -> b m h c r", query_states, rel_pos_emb) * self.scale
|
| 178 |
+
|
| 179 |
+
if remainder > 0:
|
| 180 |
+
# masked attention in the extended block
|
| 181 |
+
mask = torch.ones(self.context_size, self.context_size, dtype=bool, device=hidden_states.device)
|
| 182 |
+
mask[:remainder, :remainder] = 0
|
| 183 |
+
mask_value = -torch.finfo(pos_attn.dtype).max
|
| 184 |
+
pos_attn[:, -1, :].masked_fill_(mask, mask_value)
|
| 185 |
+
|
| 186 |
+
with torch.nn.attention.sdpa_kernel(torch.nn.attention.SDPBackend.MATH):
|
| 187 |
+
out = F.scaled_dot_product_attention(
|
| 188 |
+
query_states, key_states, value_states, attn_mask=pos_attn, scale=self.scale
|
| 189 |
+
)
|
| 190 |
+
out = out.transpose(2, 3).reshape(bsz, hidden_states.shape[1], -1)
|
| 191 |
+
out = self.to_out(out[:, :num_features, :])
|
| 192 |
+
return self.dropout(out)
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
class GraniteSpeechPlusConformerDepthWiseConv1d(nn.Module):
|
| 196 |
+
"""Wrapper for padded 1D pointwise convolution."""
|
| 197 |
+
|
| 198 |
+
def __init__(self, chan_in: int, chan_out: int, kernel_size: int):
|
| 199 |
+
super().__init__()
|
| 200 |
+
# Padding for the 1D conv is symmetric or close (i.e., offset by one).
|
| 201 |
+
pad = kernel_size // 2
|
| 202 |
+
pad_offset = (kernel_size + 1) % 2
|
| 203 |
+
self.padding = (pad, pad - pad_offset)
|
| 204 |
+
|
| 205 |
+
self.conv = nn.Conv1d(chan_in, chan_out, kernel_size, groups=chan_in, bias=False)
|
| 206 |
+
|
| 207 |
+
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
| 208 |
+
hidden_states = F.pad(hidden_states, self.padding)
|
| 209 |
+
return self.conv(hidden_states)
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
class GraniteSpeechPlusConformerConvModule(nn.Module):
|
| 213 |
+
"""Conformer conv module consisting of several 1D/depthwise 1D convolutional layers."""
|
| 214 |
+
|
| 215 |
+
def __init__(self, config: GraniteSpeechPlusEncoderConfig):
|
| 216 |
+
super().__init__()
|
| 217 |
+
inner_dim = config.hidden_dim * config.conv_expansion_factor
|
| 218 |
+
|
| 219 |
+
self.norm = nn.LayerNorm(config.hidden_dim)
|
| 220 |
+
self.up_conv = nn.Conv1d(config.hidden_dim, inner_dim * 2, 1)
|
| 221 |
+
self.glu = nn.GLU(dim=1)
|
| 222 |
+
self.depth_conv = GraniteSpeechPlusConformerDepthWiseConv1d(
|
| 223 |
+
inner_dim,
|
| 224 |
+
inner_dim,
|
| 225 |
+
kernel_size=config.conv_kernel_size,
|
| 226 |
+
)
|
| 227 |
+
self.silu = nn.SiLU()
|
| 228 |
+
self.batch_norm = nn.BatchNorm1d(inner_dim)
|
| 229 |
+
self.down_conv = nn.Conv1d(inner_dim, config.hidden_dim, 1)
|
| 230 |
+
self.dropout = nn.Dropout(config.dropout)
|
| 231 |
+
|
| 232 |
+
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
| 233 |
+
hidden_states = self.norm(hidden_states)
|
| 234 |
+
hidden_states = self.up_conv(hidden_states.permute(0, 2, 1))
|
| 235 |
+
hidden_states = self.glu(hidden_states)
|
| 236 |
+
hidden_states = self.depth_conv(hidden_states)
|
| 237 |
+
hidden_states = self.silu(self.batch_norm(hidden_states))
|
| 238 |
+
hidden_states = self.down_conv(hidden_states).permute(0, 2, 1)
|
| 239 |
+
hidden_states = self.dropout(hidden_states)
|
| 240 |
+
return hidden_states
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
class GraniteSpeechPlusConformerBlock(nn.Module):
|
| 244 |
+
"""Conformer block, consisting largely of linear layers, attention, and convolutional layers."""
|
| 245 |
+
|
| 246 |
+
def __init__(self, config: GraniteSpeechPlusEncoderConfig):
|
| 247 |
+
super().__init__()
|
| 248 |
+
self.ff1 = GraniteSpeechPlusConformerFeedForward(config)
|
| 249 |
+
self.attn = GraniteSpeechPlusConformerAttention(config)
|
| 250 |
+
self.conv = GraniteSpeechPlusConformerConvModule(config)
|
| 251 |
+
self.ff2 = GraniteSpeechPlusConformerFeedForward(config)
|
| 252 |
+
self.post_norm = nn.LayerNorm(config.hidden_dim)
|
| 253 |
+
|
| 254 |
+
def forward(self, hidden_states: torch.Tensor, attention_dists: torch.Tensor) -> torch.Tensor:
|
| 255 |
+
hidden_states = 0.5 * self.ff1(hidden_states) + hidden_states
|
| 256 |
+
hidden_states = self.attn(hidden_states, attention_dists=attention_dists) + hidden_states
|
| 257 |
+
hidden_states = self.conv(hidden_states) + hidden_states
|
| 258 |
+
hidden_states = 0.5 * self.ff2(hidden_states) + hidden_states
|
| 259 |
+
hidden_states = self.post_norm(hidden_states)
|
| 260 |
+
return hidden_states
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
class GraniteSpeechPlusCTCEncoder(GraniteSpeechPlusPreTrainedModel):
|
| 264 |
+
config: GraniteSpeechPlusEncoderConfig
|
| 265 |
+
input_modalities = "audio"
|
| 266 |
+
_can_record_outputs = {
|
| 267 |
+
"hidden_states": GraniteSpeechPlusConformerBlock,
|
| 268 |
+
"attentions": GraniteSpeechPlusConformerAttention,
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
def __init__(self, config: GraniteSpeechPlusEncoderConfig):
|
| 272 |
+
super().__init__(config)
|
| 273 |
+
|
| 274 |
+
# Precompute clamped relative positional encoding distances
|
| 275 |
+
seq = torch.arange(config.context_size)
|
| 276 |
+
relpos_dist = seq.view(-1, 1) - seq.view(1, -1)
|
| 277 |
+
attention_dists = torch.clamp(relpos_dist, -config.context_size, config.context_size) + config.max_pos_emb
|
| 278 |
+
self.register_buffer("attention_dists", attention_dists, persistent=False)
|
| 279 |
+
self.input_linear = nn.Linear(config.input_dim, config.hidden_dim, bias=True)
|
| 280 |
+
self.layers = nn.ModuleList([GraniteSpeechPlusConformerBlock(config) for _ in range(config.num_layers)])
|
| 281 |
+
|
| 282 |
+
self.out = nn.Linear(config.hidden_dim, config.output_dim, bias=True)
|
| 283 |
+
self.out_mid = nn.Linear(config.output_dim, config.hidden_dim, bias=True)
|
| 284 |
+
self.num_layers = config.num_layers
|
| 285 |
+
self.post_init()
|
| 286 |
+
|
| 287 |
+
@merge_with_config_defaults
|
| 288 |
+
@capture_outputs
|
| 289 |
+
def forward(
|
| 290 |
+
self,
|
| 291 |
+
hidden_states: torch.Tensor,
|
| 292 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 293 |
+
) -> BaseModelOutputWithPooling:
|
| 294 |
+
hidden_states = self.input_linear(hidden_states)
|
| 295 |
+
cat_layers = set(self.config.cat_hidden_layers or [])
|
| 296 |
+
exported_hidden_states = []
|
| 297 |
+
|
| 298 |
+
if 0 in cat_layers:
|
| 299 |
+
exported_hidden_states.append(hidden_states)
|
| 300 |
+
|
| 301 |
+
for idx, layer in enumerate(self.layers, start=1):
|
| 302 |
+
hidden_states = layer(hidden_states, attention_dists=self.attention_dists)
|
| 303 |
+
|
| 304 |
+
if idx in cat_layers:
|
| 305 |
+
exported_hidden_states.append(hidden_states)
|
| 306 |
+
|
| 307 |
+
if idx == self.num_layers // 2:
|
| 308 |
+
hidden_states_mid = hidden_states.clone()
|
| 309 |
+
hidden_states_mid = self.out(hidden_states_mid)
|
| 310 |
+
hidden_states += self.out_mid(nn.Softmax(dim=-1)(hidden_states_mid))
|
| 311 |
+
|
| 312 |
+
if exported_hidden_states:
|
| 313 |
+
hidden_states = torch.cat([*exported_hidden_states, hidden_states], dim=-1)
|
| 314 |
+
|
| 315 |
+
return BaseModelOutputWithPooling(last_hidden_state=hidden_states)
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
@auto_docstring(
|
| 319 |
+
custom_intro="""
|
| 320 |
+
Base class for LlavaNext causal language model (or autoregressive) outputs.
|
| 321 |
+
"""
|
| 322 |
+
)
|
| 323 |
+
@dataclass
|
| 324 |
+
class GraniteSpeechPlusCausalLMOutputWithPast(ModelOutput):
|
| 325 |
+
r"""
|
| 326 |
+
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
|
| 327 |
+
Language modeling loss (for next-token prediction).
|
| 328 |
+
logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
|
| 329 |
+
Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
|
| 330 |
+
past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
|
| 331 |
+
It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).
|
| 332 |
+
|
| 333 |
+
Contains pre-computed hidden-states (key and values in the self-attention blocks) that can be used (see
|
| 334 |
+
`past_key_values` input) to speed up sequential decoding.
|
| 335 |
+
"""
|
| 336 |
+
|
| 337 |
+
loss: torch.FloatTensor | None = None
|
| 338 |
+
logits: torch.FloatTensor | None = None
|
| 339 |
+
past_key_values: Cache | None = None
|
| 340 |
+
hidden_states: tuple[torch.FloatTensor] | None = None
|
| 341 |
+
attentions: tuple[torch.FloatTensor] | None = None
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
@auto_docstring(
|
| 345 |
+
custom_intro="""
|
| 346 |
+
The Granite Speech Plus model, a Granite Speech variant whose projector consumes the concatenation of the
|
| 347 |
+
encoder's final hidden states with an arbitrary subset of its intermediate hidden states.
|
| 348 |
+
"""
|
| 349 |
+
)
|
| 350 |
+
class GraniteSpeechPlusForConditionalGeneration(GraniteSpeechPlusPreTrainedModel, GenerationMixin):
|
| 351 |
+
_supports_attention_backend = True
|
| 352 |
+
|
| 353 |
+
def __init__(self, config: GraniteSpeechPlusConfig):
|
| 354 |
+
super().__init__(config)
|
| 355 |
+
# NOTE: It doesn't matter when we initialize from config, but we should be careful
|
| 356 |
+
# to make sure this does not pick up the adapter_config if in the future we use
|
| 357 |
+
# from_pretrained or something similar, since that should be set by the composite
|
| 358 |
+
# model; don't need to consider it twice
|
| 359 |
+
self.language_model = AutoModelForCausalLM.from_config(config.text_config)
|
| 360 |
+
|
| 361 |
+
self.encoder = GraniteSpeechPlusCTCEncoder(config.encoder_config)
|
| 362 |
+
self.projector = GraniteSpeechPlusEncoderProjector(config)
|
| 363 |
+
|
| 364 |
+
if config.has_lora_adapter and not is_peft_available():
|
| 365 |
+
logger.warning(
|
| 366 |
+
"Config indicates that a lora adapter should be present, but "
|
| 367 |
+
"peft is not installed; this will cause the model to perform "
|
| 368 |
+
"incorrectly when audio inputs are provided. Please install "
|
| 369 |
+
"peft and reload the model!"
|
| 370 |
+
)
|
| 371 |
+
|
| 372 |
+
self.post_init()
|
| 373 |
+
|
| 374 |
+
def set_decoder(self, decoder):
|
| 375 |
+
self.language_model.set_decoder(decoder)
|
| 376 |
+
|
| 377 |
+
def get_decoder(self):
|
| 378 |
+
return self.language_model.get_decoder()
|
| 379 |
+
|
| 380 |
+
def set_output_embeddings(self, new_embeddings):
|
| 381 |
+
self.language_model.set_output_embeddings(new_embeddings)
|
| 382 |
+
|
| 383 |
+
def get_output_embeddings(self):
|
| 384 |
+
return self.language_model.get_output_embeddings()
|
| 385 |
+
|
| 386 |
+
@can_return_tuple
|
| 387 |
+
@auto_docstring
|
| 388 |
+
def get_audio_features(
|
| 389 |
+
self, input_features: torch.Tensor, **kwargs: Unpack[TransformersKwargs]
|
| 390 |
+
) -> tuple | BaseModelOutputWithPooling:
|
| 391 |
+
audio_outputs = self.encoder(input_features, return_dict=True, **kwargs)
|
| 392 |
+
projected_embeds = self.projector(audio_outputs.last_hidden_state)
|
| 393 |
+
audio_outputs.pooler_output = projected_embeds
|
| 394 |
+
|
| 395 |
+
return audio_outputs
|
| 396 |
+
|
| 397 |
+
@auto_docstring
|
| 398 |
+
def forward(
|
| 399 |
+
self,
|
| 400 |
+
input_ids: torch.LongTensor | None = None,
|
| 401 |
+
input_features: torch.FloatTensor | None = None,
|
| 402 |
+
input_features_mask: torch.Tensor | None = None,
|
| 403 |
+
attention_mask: torch.Tensor | None = None,
|
| 404 |
+
position_ids: torch.LongTensor | None = None,
|
| 405 |
+
past_key_values: Cache | None = None,
|
| 406 |
+
inputs_embeds: torch.FloatTensor | None = None,
|
| 407 |
+
labels: torch.LongTensor | None = None,
|
| 408 |
+
use_cache: bool | None = None,
|
| 409 |
+
output_attentions: bool | None = None,
|
| 410 |
+
output_hidden_states: bool | None = None,
|
| 411 |
+
return_dict: bool | None = None,
|
| 412 |
+
logits_to_keep: int | torch.Tensor = 0,
|
| 413 |
+
**lm_kwargs,
|
| 414 |
+
) -> tuple[torch.Tensor] | GraniteSpeechPlusCausalLMOutputWithPast:
|
| 415 |
+
r"""
|
| 416 |
+
input_features_mask (`torch.Tensor`, *optional*):
|
| 417 |
+
Mask to be applied to audio features prior to scattering into the language embeddings.
|
| 418 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 419 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
| 420 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
| 421 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
| 422 |
+
"""
|
| 423 |
+
# TODO (@alex-jw-brooks) add an example to this docstring once models are released
|
| 424 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 425 |
+
output_hidden_states = (
|
| 426 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 427 |
+
)
|
| 428 |
+
return_dict = return_dict if return_dict is not None else self.config.return_dict
|
| 429 |
+
|
| 430 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 431 |
+
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
| 432 |
+
|
| 433 |
+
if input_features is not None and inputs_embeds is not None:
|
| 434 |
+
raise ValueError(
|
| 435 |
+
"You cannot specify both input_features and inputs_embeds at the same time, and must specify either one"
|
| 436 |
+
)
|
| 437 |
+
|
| 438 |
+
if inputs_embeds is None:
|
| 439 |
+
# Get the base embeddings; set all audio tokens to 0 index
|
| 440 |
+
# to avoid out of vocabulary issues with the LLM embedding.
|
| 441 |
+
# Audio features will be masked into is_audio_idx indices later.
|
| 442 |
+
is_audio_idx = input_ids == self.config.audio_token_id
|
| 443 |
+
llm_input_ids = input_ids.clone()
|
| 444 |
+
llm_input_ids[is_audio_idx] = 0
|
| 445 |
+
inputs_embeds = self.get_input_embeddings()(llm_input_ids)
|
| 446 |
+
|
| 447 |
+
if input_features is not None:
|
| 448 |
+
if input_features.dtype != self.dtype:
|
| 449 |
+
input_features = input_features.to(self.dtype)
|
| 450 |
+
# Get the audio features from the encoder / projector
|
| 451 |
+
audio_embeds = self.get_audio_features(input_features, return_dict=True).pooler_output
|
| 452 |
+
|
| 453 |
+
# Merge the audio features into the LLM embeddings
|
| 454 |
+
inputs_embeds = self.get_merged_audio_embeddings(
|
| 455 |
+
input_ids=input_ids,
|
| 456 |
+
audio_features=audio_embeds,
|
| 457 |
+
input_features_mask=input_features_mask,
|
| 458 |
+
)
|
| 459 |
+
|
| 460 |
+
outputs = self.language_model(
|
| 461 |
+
attention_mask=attention_mask,
|
| 462 |
+
position_ids=position_ids,
|
| 463 |
+
past_key_values=past_key_values,
|
| 464 |
+
inputs_embeds=inputs_embeds,
|
| 465 |
+
use_cache=use_cache,
|
| 466 |
+
output_attentions=output_attentions,
|
| 467 |
+
output_hidden_states=output_hidden_states,
|
| 468 |
+
return_dict=return_dict,
|
| 469 |
+
logits_to_keep=logits_to_keep,
|
| 470 |
+
**lm_kwargs,
|
| 471 |
+
)
|
| 472 |
+
logits = outputs[0]
|
| 473 |
+
|
| 474 |
+
loss = None
|
| 475 |
+
if labels is not None:
|
| 476 |
+
# Shift so that tokens < n predict n
|
| 477 |
+
if attention_mask is not None:
|
| 478 |
+
# we use the input attention mask to shift the logits and labels, because it is 2D.
|
| 479 |
+
# we also crop attn mask in case it is longer, which happens in PrefixTuning with peft
|
| 480 |
+
shift_attention_mask = attention_mask[:, -(logits.shape[1] - 1) :].to(logits.device)
|
| 481 |
+
shift_logits = logits[..., :-1, :][shift_attention_mask.to(logits.device) != 0].contiguous()
|
| 482 |
+
shift_labels = labels[..., 1:][shift_attention_mask.to(labels.device) != 0].contiguous()
|
| 483 |
+
else:
|
| 484 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
| 485 |
+
shift_labels = labels[..., 1:].contiguous()
|
| 486 |
+
# Flatten the tokens
|
| 487 |
+
loss_fct = nn.CrossEntropyLoss()
|
| 488 |
+
loss = loss_fct(
|
| 489 |
+
shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1).to(shift_logits.device)
|
| 490 |
+
)
|
| 491 |
+
|
| 492 |
+
if not return_dict:
|
| 493 |
+
output = (logits,) + outputs[1:]
|
| 494 |
+
return (loss,) + output if loss is not None else output
|
| 495 |
+
|
| 496 |
+
return GraniteSpeechPlusCausalLMOutputWithPast(
|
| 497 |
+
loss=loss,
|
| 498 |
+
logits=logits,
|
| 499 |
+
past_key_values=outputs.past_key_values,
|
| 500 |
+
hidden_states=outputs.hidden_states,
|
| 501 |
+
attentions=outputs.attentions,
|
| 502 |
+
)
|
| 503 |
+
|
| 504 |
+
def prepare_inputs_for_generation(
|
| 505 |
+
self,
|
| 506 |
+
input_ids,
|
| 507 |
+
past_key_values=None,
|
| 508 |
+
inputs_embeds=None,
|
| 509 |
+
input_features=None,
|
| 510 |
+
attention_mask=None,
|
| 511 |
+
logits_to_keep=None,
|
| 512 |
+
is_first_iteration=False,
|
| 513 |
+
**kwargs,
|
| 514 |
+
):
|
| 515 |
+
# Overwritten -- in specific circumstances we don't want to forward audio inputs to the model
|
| 516 |
+
|
| 517 |
+
model_inputs = self.language_model.prepare_inputs_for_generation(
|
| 518 |
+
input_ids,
|
| 519 |
+
past_key_values=past_key_values,
|
| 520 |
+
inputs_embeds=inputs_embeds,
|
| 521 |
+
attention_mask=attention_mask,
|
| 522 |
+
logits_to_keep=logits_to_keep,
|
| 523 |
+
is_first_iteration=is_first_iteration,
|
| 524 |
+
**kwargs,
|
| 525 |
+
)
|
| 526 |
+
|
| 527 |
+
# If we're in cached decoding stage, input_features should be None because
|
| 528 |
+
# input ids do not contain special audio token anymore Otherwise we need
|
| 529 |
+
# input feature values to be passed to the model
|
| 530 |
+
if is_first_iteration or not kwargs.get("use_cache", True):
|
| 531 |
+
model_inputs["input_features"] = input_features
|
| 532 |
+
return model_inputs
|
| 533 |
+
|
| 534 |
+
def get_placeholder_mask(
|
| 535 |
+
self, input_ids: torch.LongTensor, inputs_embeds: torch.FloatTensor, audio_features: torch.FloatTensor
|
| 536 |
+
):
|
| 537 |
+
"""
|
| 538 |
+
Obtains multimodal placeholder mask from `input_ids` or `inputs_embeds`, and checks that the placeholder token count is
|
| 539 |
+
equal to the length of multimodal features. If the lengths are different, an error is raised.
|
| 540 |
+
"""
|
| 541 |
+
if input_ids is None:
|
| 542 |
+
special_audio_mask = inputs_embeds == self.get_input_embeddings()(
|
| 543 |
+
torch.tensor(self.config.audio_token_id, dtype=torch.long, device=inputs_embeds.device)
|
| 544 |
+
)
|
| 545 |
+
special_audio_mask = special_audio_mask.all(-1)
|
| 546 |
+
else:
|
| 547 |
+
special_audio_mask = input_ids == self.config.audio_token_id
|
| 548 |
+
|
| 549 |
+
n_audio_tokens = special_audio_mask.sum()
|
| 550 |
+
n_audio_features = audio_features.shape[0]
|
| 551 |
+
special_audio_mask = special_audio_mask.unsqueeze(-1).expand_as(inputs_embeds).to(inputs_embeds.device)
|
| 552 |
+
torch_compilable_check(
|
| 553 |
+
inputs_embeds[special_audio_mask].numel() == audio_features.numel(),
|
| 554 |
+
f"Audio features and audio tokens do not match, tokens: {n_audio_tokens}, features: {n_audio_features}",
|
| 555 |
+
)
|
| 556 |
+
return special_audio_mask
|
| 557 |
+
|
| 558 |
+
def get_merged_audio_embeddings(
|
| 559 |
+
self, input_ids: torch.Tensor, audio_features: torch.Tensor, input_features_mask: torch.Tensor | None = None
|
| 560 |
+
) -> torch.Tensor:
|
| 561 |
+
"""
|
| 562 |
+
Adds the audio token to the model's LLM vocabulary so that we can pass it
|
| 563 |
+
through the tokenizer; it's assumed that the embeddings corresponding to the
|
| 564 |
+
<|audio|> token will be clobbered with speech features.
|
| 565 |
+
|
| 566 |
+
Args:
|
| 567 |
+
input_ids (`torch.Tensor`):
|
| 568 |
+
Input IDs containing one or more audio tokens.
|
| 569 |
+
audio_features (`torch.Tensor`):
|
| 570 |
+
Audio features to be masked into the language embeddings to form multimodal embeddings.
|
| 571 |
+
input_features_mask (`torch.Tensor`, *optional*, defaults to `None`)
|
| 572 |
+
Mask to be applied to audio features prior to scattering into the language embeddings.
|
| 573 |
+
"""
|
| 574 |
+
is_audio_index = input_ids == self.config.audio_token_id
|
| 575 |
+
llm_input_ids = torch.where(is_audio_index, 0, input_ids)
|
| 576 |
+
inputs_embeds = self.language_model.get_input_embeddings()(llm_input_ids) # [bsz, # features, hidden size]
|
| 577 |
+
|
| 578 |
+
audio_features = audio_features.to(inputs_embeds.device, inputs_embeds.dtype)
|
| 579 |
+
if input_features_mask is not None:
|
| 580 |
+
audio_features = audio_features[input_features_mask]
|
| 581 |
+
|
| 582 |
+
special_audio_mask = self.get_placeholder_mask(
|
| 583 |
+
input_ids, inputs_embeds=inputs_embeds, audio_features=audio_features
|
| 584 |
+
)
|
| 585 |
+
inputs_embeds = inputs_embeds.masked_scatter(special_audio_mask, audio_features)
|
| 586 |
+
return inputs_embeds
|
| 587 |
+
|
| 588 |
+
def generate(self, *args, **kwargs) -> torch.LongTensor:
|
| 589 |
+
# This model is expected to have a lora adapter, which is only
|
| 590 |
+
# enabled when considering audio inputs. As such, we override generate
|
| 591 |
+
# to conditionally enable / disable the lora adapter based on whether
|
| 592 |
+
# or not any input features were provided.
|
| 593 |
+
|
| 594 |
+
input_features = kwargs.pop("input_features", None)
|
| 595 |
+
if is_peft_available and self._hf_peft_config_loaded:
|
| 596 |
+
if input_features is not None:
|
| 597 |
+
self.enable_adapters()
|
| 598 |
+
else:
|
| 599 |
+
self.disable_adapters()
|
| 600 |
+
return super().generate(*args, input_features=input_features, **kwargs)
|
| 601 |
+
|
| 602 |
+
def save_pretrained(self, save_directory, *args, **kwargs):
|
| 603 |
+
# overwrite save_pretrained to first save the adapter if we have one
|
| 604 |
+
if is_peft_available and self._hf_peft_config_loaded:
|
| 605 |
+
adapter_name = self._get_adapter_name()
|
| 606 |
+
self.peft_config[adapter_name].base_model_name_or_path = save_directory
|
| 607 |
+
super().save_pretrained(save_directory, *args, **kwargs)
|
| 608 |
+
# Then save the base model afterwards
|
| 609 |
+
prev_val = self._hf_peft_config_loaded
|
| 610 |
+
self._hf_peft_config_loaded = False
|
| 611 |
+
super().save_pretrained(save_directory, *args, **kwargs)
|
| 612 |
+
self._hf_peft_config_loaded = prev_val
|
| 613 |
+
|
| 614 |
+
def _get_adapter_name(self):
|
| 615 |
+
return list(self.peft_config.keys())[0]
|
| 616 |
+
|
| 617 |
+
|
| 618 |
+
__all__ = [
|
| 619 |
+
"GraniteSpeechPlusCTCEncoder",
|
| 620 |
+
"GraniteSpeechPlusForConditionalGeneration",
|
| 621 |
+
"GraniteSpeechPlusPreTrainedModel",
|
| 622 |
+
]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/granite_speech_plus/modular_granite_speech_plus.py
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2026 The HuggingFace Inc. team.
|
| 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 |
+
"""Granite Speech Plus model, a Granite Speech variant whose projector consumes the concatenation of the
|
| 15 |
+
encoder's final hidden states with an arbitrary subset of its intermediate hidden states."""
|
| 16 |
+
|
| 17 |
+
import torch
|
| 18 |
+
from huggingface_hub.dataclasses import strict
|
| 19 |
+
from torch import nn
|
| 20 |
+
|
| 21 |
+
from ...modeling_outputs import BaseModelOutputWithPooling
|
| 22 |
+
from ...processing_utils import Unpack
|
| 23 |
+
from ...utils import TransformersKwargs, auto_docstring
|
| 24 |
+
from ...utils.generic import merge_with_config_defaults
|
| 25 |
+
from ...utils.output_capturing import capture_outputs
|
| 26 |
+
from ..granite_speech.configuration_granite_speech import GraniteSpeechConfig, GraniteSpeechEncoderConfig
|
| 27 |
+
from ..granite_speech.modeling_granite_speech import (
|
| 28 |
+
GraniteSpeechCTCEncoder,
|
| 29 |
+
GraniteSpeechForConditionalGeneration,
|
| 30 |
+
GraniteSpeechPreTrainedModel,
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
@auto_docstring(checkpoint="ibm-granite/granite-speech-4.1-2b-plus")
|
| 35 |
+
@strict
|
| 36 |
+
class GraniteSpeechPlusEncoderConfig(GraniteSpeechEncoderConfig):
|
| 37 |
+
r"""
|
| 38 |
+
feedforward_mult (`int`, *optional*, defaults to 4):
|
| 39 |
+
Multiplier for the up/down projections in the encoder's feedforward layers;
|
| 40 |
+
The projections will have intermediate dim of size `hidden_dim * feedforward_mult`.
|
| 41 |
+
output_dim (`int`, *optional*, defaults to 42):
|
| 42 |
+
Intermediate dimension of the feedforward projections in the conformer
|
| 43 |
+
to be added to every other encoder block's output.
|
| 44 |
+
context_size (`int`, *optional*, defaults to 200):
|
| 45 |
+
Context size to be used in conformer attention.
|
| 46 |
+
max_pos_emb (`int`, *optional*, defaults to 512):
|
| 47 |
+
Max pos embeds to be used in attention (shaw's relative positional encoding).
|
| 48 |
+
conv_expansion_factor (`int`, *optional*, defaults to 2):
|
| 49 |
+
Intermediate dimension to be used in conformer convolutions.
|
| 50 |
+
cat_hidden_layers (`list[int]`, *optional*):
|
| 51 |
+
Indices of encoder conformer layers whose outputs are concatenated with the final encoder
|
| 52 |
+
output (along the feature dimension) before being passed to the projector. When set, the
|
| 53 |
+
projector's ``encoder_hidden_size`` must equal
|
| 54 |
+
``encoder_config.hidden_dim * (len(cat_hidden_layers) + 1)``.
|
| 55 |
+
|
| 56 |
+
Example:
|
| 57 |
+
|
| 58 |
+
```python
|
| 59 |
+
>>> from transformers import GraniteSpeechPlusEncoderConfig, GraniteSpeechPlusCTCEncoder
|
| 60 |
+
|
| 61 |
+
>>> # Initializing a GraniteSpeechPlusEncoderConfig
|
| 62 |
+
>>> configuration = GraniteSpeechPlusEncoderConfig()
|
| 63 |
+
|
| 64 |
+
>>> # Initializing a GraniteSpeechPlusCTCEncoder (with random weights)
|
| 65 |
+
>>> model = GraniteSpeechPlusCTCEncoder(configuration)
|
| 66 |
+
|
| 67 |
+
>>> # Accessing the model configuration
|
| 68 |
+
>>> configuration = model.config
|
| 69 |
+
```"""
|
| 70 |
+
|
| 71 |
+
cat_hidden_layers: list[int] | None = None
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
@auto_docstring(checkpoint="ibm-granite/granite-speech-4.1-2b-plus")
|
| 75 |
+
@strict
|
| 76 |
+
class GraniteSpeechPlusConfig(GraniteSpeechConfig):
|
| 77 |
+
r"""
|
| 78 |
+
projector_config (`Union[AutoConfig, dict]`, *optional*, defaults to `Blip2QFormerConfig`):
|
| 79 |
+
The config object or dictionary of the audio projector.
|
| 80 |
+
has_lora_adapter (`bool`, *optional*, defaults to `True`):
|
| 81 |
+
Indicates whether or not the model has a lora adapter that should only
|
| 82 |
+
be activate when processing audio inputs.
|
| 83 |
+
downsample_rate (`int`, *optional*, defaults to 5):
|
| 84 |
+
Downsample rate for the audio feature extractor.
|
| 85 |
+
window_size (`int`, *optional*, defaults to 15):
|
| 86 |
+
Window size for the audio feature projector.
|
| 87 |
+
|
| 88 |
+
Example:
|
| 89 |
+
|
| 90 |
+
```python
|
| 91 |
+
>>> from transformers import GraniteSpeechPlusConfig, GraniteSpeechPlusForConditionalGeneration
|
| 92 |
+
|
| 93 |
+
>>> # Initializing a GraniteSpeechPlusConfig
|
| 94 |
+
>>> configuration = GraniteSpeechPlusConfig()
|
| 95 |
+
|
| 96 |
+
>>> # Initializing a GraniteSpeechPlusForConditionalGeneration (with random weights)
|
| 97 |
+
>>> model = GraniteSpeechPlusForConditionalGeneration(configuration)
|
| 98 |
+
|
| 99 |
+
>>> # Accessing the model configuration
|
| 100 |
+
>>> configuration = model.config
|
| 101 |
+
```"""
|
| 102 |
+
|
| 103 |
+
def __post_init__(self, **kwargs):
|
| 104 |
+
super().__post_init__(**kwargs)
|
| 105 |
+
|
| 106 |
+
if self.encoder_config.cat_hidden_layers is not None:
|
| 107 |
+
for idx in self.encoder_config.cat_hidden_layers:
|
| 108 |
+
if idx < 0 or idx >= self.encoder_config.num_layers:
|
| 109 |
+
raise ValueError(
|
| 110 |
+
f"cat_hidden_layers index {idx} is out of range [0, {self.encoder_config.num_layers})."
|
| 111 |
+
)
|
| 112 |
+
if self.encoder_config.cat_hidden_layers is not None:
|
| 113 |
+
num_concat = len(self.encoder_config.cat_hidden_layers) + 1
|
| 114 |
+
if self.projector_config.encoder_hidden_size != self.encoder_config.hidden_dim * num_concat:
|
| 115 |
+
raise ValueError(
|
| 116 |
+
f"projector encoder_hidden_size {self.projector_config.encoder_hidden_size} "
|
| 117 |
+
f"must equal encoder hidden_dim * {num_concat} = "
|
| 118 |
+
f"{self.encoder_config.hidden_dim * num_concat}."
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
class GraniteSpeechPlusPreTrainedModel(GraniteSpeechPreTrainedModel): ...
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
class GraniteSpeechPlusCTCEncoder(GraniteSpeechCTCEncoder):
|
| 126 |
+
@merge_with_config_defaults
|
| 127 |
+
@capture_outputs
|
| 128 |
+
def forward(
|
| 129 |
+
self,
|
| 130 |
+
hidden_states: torch.Tensor,
|
| 131 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 132 |
+
) -> BaseModelOutputWithPooling:
|
| 133 |
+
hidden_states = self.input_linear(hidden_states)
|
| 134 |
+
cat_layers = set(self.config.cat_hidden_layers or [])
|
| 135 |
+
exported_hidden_states = []
|
| 136 |
+
|
| 137 |
+
if 0 in cat_layers:
|
| 138 |
+
exported_hidden_states.append(hidden_states)
|
| 139 |
+
|
| 140 |
+
for idx, layer in enumerate(self.layers, start=1):
|
| 141 |
+
hidden_states = layer(hidden_states, attention_dists=self.attention_dists)
|
| 142 |
+
|
| 143 |
+
if idx in cat_layers:
|
| 144 |
+
exported_hidden_states.append(hidden_states)
|
| 145 |
+
|
| 146 |
+
if idx == self.num_layers // 2:
|
| 147 |
+
hidden_states_mid = hidden_states.clone()
|
| 148 |
+
hidden_states_mid = self.out(hidden_states_mid)
|
| 149 |
+
hidden_states += self.out_mid(nn.Softmax(dim=-1)(hidden_states_mid))
|
| 150 |
+
|
| 151 |
+
if exported_hidden_states:
|
| 152 |
+
hidden_states = torch.cat([*exported_hidden_states, hidden_states], dim=-1)
|
| 153 |
+
|
| 154 |
+
return BaseModelOutputWithPooling(last_hidden_state=hidden_states)
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
@auto_docstring(
|
| 158 |
+
custom_intro="""
|
| 159 |
+
The Granite Speech Plus model, a Granite Speech variant whose projector consumes the concatenation of the
|
| 160 |
+
encoder's final hidden states with an arbitrary subset of its intermediate hidden states.
|
| 161 |
+
"""
|
| 162 |
+
)
|
| 163 |
+
class GraniteSpeechPlusForConditionalGeneration(GraniteSpeechForConditionalGeneration): ...
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
__all__ = [
|
| 167 |
+
"GraniteSpeechPlusConfig",
|
| 168 |
+
"GraniteSpeechPlusEncoderConfig",
|
| 169 |
+
"GraniteSpeechPlusCTCEncoder",
|
| 170 |
+
"GraniteSpeechPlusForConditionalGeneration",
|
| 171 |
+
"GraniteSpeechPlusPreTrainedModel",
|
| 172 |
+
]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/granitemoe/configuration_granitemoe.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2024 EleutherAI and the HuggingFace Inc. team. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
|
| 4 |
+
# and OPT implementations in this library. It has been modified from its
|
| 5 |
+
# original forms to accommodate minor architectural differences compared
|
| 6 |
+
# to GPT-NeoX and OPT used by the Meta AI team that trained the model.
|
| 7 |
+
#
|
| 8 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 9 |
+
# you may not use this file except in compliance with the License.
|
| 10 |
+
# You may obtain a copy of the License at
|
| 11 |
+
#
|
| 12 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 13 |
+
#
|
| 14 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 15 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 16 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 17 |
+
# See the License for the specific language governing permissions and
|
| 18 |
+
# limitations under the License.
|
| 19 |
+
"""GraniteMoe model configuration"""
|
| 20 |
+
|
| 21 |
+
from huggingface_hub.dataclasses import strict
|
| 22 |
+
|
| 23 |
+
from ...configuration_utils import PreTrainedConfig
|
| 24 |
+
from ...modeling_rope_utils import RopeParameters
|
| 25 |
+
from ...utils import auto_docstring
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
@auto_docstring(checkpoint="ibm-granite/granite-speech-3.2-8b")
|
| 29 |
+
@strict
|
| 30 |
+
class GraniteMoeConfig(PreTrainedConfig):
|
| 31 |
+
r"""
|
| 32 |
+
```python
|
| 33 |
+
>>> from transformers import GraniteMoeModel, GraniteMoeConfig
|
| 34 |
+
|
| 35 |
+
>>> # Initializing a GraniteMoe granitemoe-3b style configuration
|
| 36 |
+
>>> configuration = GraniteMoeConfig()
|
| 37 |
+
|
| 38 |
+
>>> # Initializing a model from the granitemoe-7b style configuration
|
| 39 |
+
>>> model = GraniteMoeModel(configuration)
|
| 40 |
+
|
| 41 |
+
>>> # Accessing the model configuration
|
| 42 |
+
>>> configuration = model.config
|
| 43 |
+
```
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
+
model_type = "granitemoe"
|
| 47 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 48 |
+
|
| 49 |
+
vocab_size: int = 32000
|
| 50 |
+
hidden_size: int = 4096
|
| 51 |
+
intermediate_size: int = 11008
|
| 52 |
+
num_hidden_layers: int = 32
|
| 53 |
+
num_attention_heads: int = 32
|
| 54 |
+
num_key_value_heads: int | None = None
|
| 55 |
+
hidden_act: str = "silu"
|
| 56 |
+
max_position_embeddings: int = 2048
|
| 57 |
+
initializer_range: float = 0.02
|
| 58 |
+
rms_norm_eps: float = 1e-6
|
| 59 |
+
use_cache: bool = True
|
| 60 |
+
pad_token_id: int | None = None
|
| 61 |
+
bos_token_id: int | None = 1
|
| 62 |
+
eos_token_id: int | list[int] | None = 2
|
| 63 |
+
tie_word_embeddings: bool = False
|
| 64 |
+
rope_parameters: RopeParameters | dict | None = None
|
| 65 |
+
attention_bias: bool = False
|
| 66 |
+
attention_dropout: float | int | None = 0.0
|
| 67 |
+
embedding_multiplier: float | int | None = 1.0
|
| 68 |
+
logits_scaling: float | int | None = 1.0
|
| 69 |
+
residual_multiplier: float | int | None = 1.0
|
| 70 |
+
attention_multiplier: float | int | None = 1.0
|
| 71 |
+
num_local_experts: int | None = 8
|
| 72 |
+
num_experts_per_tok: int | None = 2
|
| 73 |
+
output_router_logits: bool | None = False
|
| 74 |
+
router_aux_loss_coef: float | None = 0.001
|
| 75 |
+
|
| 76 |
+
def __post_init__(self, **kwargs):
|
| 77 |
+
# for backward compatibility
|
| 78 |
+
if self.num_key_value_heads is None:
|
| 79 |
+
self.num_key_value_heads = self.num_attention_heads
|
| 80 |
+
|
| 81 |
+
super().__post_init__(**kwargs)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
__all__ = ["GraniteMoeConfig"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/granitemoe/modular_granitemoe.py
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2024 IBM and the HuggingFace Inc. team. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
|
| 16 |
+
import torch
|
| 17 |
+
from torch import nn
|
| 18 |
+
|
| 19 |
+
from ... import initialization as init
|
| 20 |
+
from ...activations import ACT2FN
|
| 21 |
+
from ...cache_utils import Cache, DynamicCache
|
| 22 |
+
from ...masking_utils import create_causal_mask
|
| 23 |
+
from ...modeling_outputs import MoeCausalLMOutputWithPast, MoeModelOutputWithPast
|
| 24 |
+
from ...modeling_utils import PreTrainedModel
|
| 25 |
+
from ...processing_utils import Unpack
|
| 26 |
+
from ...utils import TransformersKwargs, auto_docstring
|
| 27 |
+
from ...utils.generic import can_return_tuple, merge_with_config_defaults
|
| 28 |
+
from ...utils.output_capturing import capture_outputs
|
| 29 |
+
from ..granite.modeling_granite import GraniteRMSNorm, GraniteRotaryEmbedding
|
| 30 |
+
from ..jetmoe.modeling_jetmoe import JetMoeParallelExperts, JetMoeTopKGating
|
| 31 |
+
from ..llama.modeling_llama import LlamaAttention, LlamaPreTrainedModel
|
| 32 |
+
from ..mixtral.modeling_mixtral import MixtralDecoderLayer, MixtralForCausalLM, MixtralModel, load_balancing_loss_func
|
| 33 |
+
from .configuration_granitemoe import GraniteMoeConfig
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class GraniteMoeRMSNorm(GraniteRMSNorm):
|
| 37 |
+
pass
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class GraniteMoeRotaryEmbedding(GraniteRotaryEmbedding):
|
| 41 |
+
pass
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class GraniteMoeParallelExperts(JetMoeParallelExperts):
|
| 45 |
+
pass
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class GraniteMoeTopKGating(JetMoeTopKGating):
|
| 49 |
+
pass
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class GraniteMoeMoE(nn.Module):
|
| 53 |
+
"""
|
| 54 |
+
A Sparsely gated mixture of experts layer with 1-layer Feed-Forward networks as experts.
|
| 55 |
+
|
| 56 |
+
Args:
|
| 57 |
+
config:
|
| 58 |
+
Configuration object with model hyperparameters.
|
| 59 |
+
"""
|
| 60 |
+
|
| 61 |
+
def __init__(self, config: GraniteMoeConfig):
|
| 62 |
+
super().__init__()
|
| 63 |
+
|
| 64 |
+
self.input_size = config.hidden_size
|
| 65 |
+
self.hidden_size = config.intermediate_size
|
| 66 |
+
self.activation = ACT2FN[config.hidden_act]
|
| 67 |
+
self.input_linear = GraniteMoeParallelExperts(config.num_local_experts, self.input_size, self.hidden_size * 2)
|
| 68 |
+
self.output_linear = GraniteMoeParallelExperts(config.num_local_experts, self.hidden_size, self.input_size)
|
| 69 |
+
|
| 70 |
+
self.router = GraniteMoeTopKGating(
|
| 71 |
+
input_size=self.input_size,
|
| 72 |
+
num_experts=config.num_local_experts,
|
| 73 |
+
top_k=config.num_experts_per_tok,
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
def forward(self, layer_input):
|
| 77 |
+
bsz, length, emb_size = layer_input.size()
|
| 78 |
+
layer_input = layer_input.reshape(-1, emb_size)
|
| 79 |
+
_, batch_index, batch_gates, expert_size, _ = self.router(layer_input)
|
| 80 |
+
|
| 81 |
+
expert_inputs = layer_input[batch_index]
|
| 82 |
+
hidden_states = self.input_linear(expert_inputs, expert_size)
|
| 83 |
+
chunked_hidden_states = hidden_states.chunk(2, dim=-1)
|
| 84 |
+
hidden_states = self.activation(chunked_hidden_states[0]) * chunked_hidden_states[1]
|
| 85 |
+
expert_outputs = self.output_linear(hidden_states, expert_size)
|
| 86 |
+
|
| 87 |
+
expert_outputs = expert_outputs * batch_gates[:, None]
|
| 88 |
+
|
| 89 |
+
zeros = torch.zeros((bsz * length, self.input_size), dtype=expert_outputs.dtype, device=expert_outputs.device)
|
| 90 |
+
layer_output = zeros.index_add(0, batch_index, expert_outputs)
|
| 91 |
+
layer_output = layer_output.view(bsz, length, self.input_size)
|
| 92 |
+
return layer_output
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
class GraniteMoeAttention(LlamaAttention):
|
| 96 |
+
def __init__(self, config: GraniteMoeConfig, layer_idx: int):
|
| 97 |
+
super().__init__(self, config, layer_idx)
|
| 98 |
+
self.scaling = config.attention_multiplier # Only diff with llama
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
class GraniteMoeDecoderLayer(MixtralDecoderLayer):
|
| 102 |
+
def __init__(self, config: GraniteMoeConfig, layer_idx: int):
|
| 103 |
+
super().__init__(config, layer_idx)
|
| 104 |
+
self.self_attn = GraniteMoeAttention(config=config, layer_idx=layer_idx)
|
| 105 |
+
self.block_sparse_moe = GraniteMoeMoE(config)
|
| 106 |
+
self.input_layernorm = GraniteMoeRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 107 |
+
self.post_attention_layernorm = GraniteMoeRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 108 |
+
del self.mlp
|
| 109 |
+
self.block_sparse_moe = GraniteMoeMoE(config)
|
| 110 |
+
self.residual_multiplier = config.residual_multiplier # Only diff with mixtral!
|
| 111 |
+
|
| 112 |
+
def forward(
|
| 113 |
+
self,
|
| 114 |
+
hidden_states: torch.Tensor,
|
| 115 |
+
attention_mask: torch.Tensor | None = None,
|
| 116 |
+
past_key_values: Cache | None = None,
|
| 117 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor] | None = None,
|
| 118 |
+
**kwargs,
|
| 119 |
+
) -> torch.Tensor:
|
| 120 |
+
residual = hidden_states
|
| 121 |
+
hidden_states = self.input_layernorm(hidden_states)
|
| 122 |
+
hidden_states, _ = self.self_attn(
|
| 123 |
+
hidden_states=hidden_states,
|
| 124 |
+
attention_mask=attention_mask,
|
| 125 |
+
past_key_values=past_key_values,
|
| 126 |
+
position_embeddings=position_embeddings,
|
| 127 |
+
**kwargs,
|
| 128 |
+
)
|
| 129 |
+
hidden_states = residual + hidden_states * self.residual_multiplier # diff
|
| 130 |
+
residual = hidden_states
|
| 131 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 132 |
+
hidden_states = self.block_sparse_moe(hidden_states)
|
| 133 |
+
hidden_states = residual + hidden_states * self.residual_multiplier # diff
|
| 134 |
+
return hidden_states
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
@auto_docstring
|
| 138 |
+
class GraniteMoePreTrainedModel(LlamaPreTrainedModel, PreTrainedModel):
|
| 139 |
+
config: GraniteMoeConfig
|
| 140 |
+
base_model_prefix = "model"
|
| 141 |
+
supports_gradient_checkpointing = True
|
| 142 |
+
_no_split_modules = ["GraniteMoeDecoderLayer"]
|
| 143 |
+
_skip_keys_device_placement = ["past_key_values"]
|
| 144 |
+
_supports_flash_attn = True
|
| 145 |
+
_supports_sdpa = True
|
| 146 |
+
_can_compile_fullgraph = False # TopK gating fails fullgraph compilation at "expert_size = expert_size.tolist()"
|
| 147 |
+
|
| 148 |
+
@torch.no_grad()
|
| 149 |
+
def _init_weights(self, module):
|
| 150 |
+
PreTrainedModel._init_weights(self, module)
|
| 151 |
+
if isinstance(module, GraniteMoeParallelExperts):
|
| 152 |
+
init.normal_(module.weight, mean=0.0, std=self.config.initializer_range)
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
@auto_docstring
|
| 156 |
+
class GraniteMoeModel(MixtralModel):
|
| 157 |
+
def __init__(self, config: GraniteMoeConfig):
|
| 158 |
+
super().__init__(config)
|
| 159 |
+
self.layers = nn.ModuleList(
|
| 160 |
+
[GraniteMoeDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
|
| 161 |
+
)
|
| 162 |
+
self.norm = GraniteMoeRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 163 |
+
self.embedding_multiplier = config.embedding_multiplier
|
| 164 |
+
|
| 165 |
+
@merge_with_config_defaults
|
| 166 |
+
@capture_outputs
|
| 167 |
+
@auto_docstring
|
| 168 |
+
def forward(
|
| 169 |
+
self,
|
| 170 |
+
input_ids: torch.LongTensor | None = None,
|
| 171 |
+
attention_mask: torch.Tensor | None = None,
|
| 172 |
+
position_ids: torch.LongTensor | None = None,
|
| 173 |
+
past_key_values: Cache | None = None,
|
| 174 |
+
inputs_embeds: torch.FloatTensor | None = None,
|
| 175 |
+
use_cache: bool | None = None,
|
| 176 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 177 |
+
) -> MoeModelOutputWithPast:
|
| 178 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 179 |
+
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
| 180 |
+
|
| 181 |
+
if use_cache and past_key_values is None:
|
| 182 |
+
past_key_values = DynamicCache(config=self.config)
|
| 183 |
+
|
| 184 |
+
if inputs_embeds is None:
|
| 185 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 186 |
+
|
| 187 |
+
if position_ids is None:
|
| 188 |
+
past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
|
| 189 |
+
position_ids = torch.arange(inputs_embeds.shape[1], device=inputs_embeds.device) + past_seen_tokens
|
| 190 |
+
position_ids = position_ids.unsqueeze(0)
|
| 191 |
+
|
| 192 |
+
causal_mask = create_causal_mask( # ONLY DIFF WITH MIXTRAL: NO SLIDING
|
| 193 |
+
config=self.config,
|
| 194 |
+
inputs_embeds=inputs_embeds,
|
| 195 |
+
attention_mask=attention_mask,
|
| 196 |
+
past_key_values=past_key_values,
|
| 197 |
+
position_ids=position_ids,
|
| 198 |
+
)
|
| 199 |
+
inputs_embeds = inputs_embeds * self.embedding_multiplier
|
| 200 |
+
hidden_states = inputs_embeds
|
| 201 |
+
|
| 202 |
+
# create position embeddings to be shared across the decoder layers
|
| 203 |
+
position_embeddings = self.rotary_emb(hidden_states, position_ids)
|
| 204 |
+
|
| 205 |
+
for decoder_layer in self.layers[: self.config.num_hidden_layers]:
|
| 206 |
+
hidden_states = decoder_layer(
|
| 207 |
+
hidden_states,
|
| 208 |
+
position_embeddings=position_embeddings,
|
| 209 |
+
attention_mask=causal_mask,
|
| 210 |
+
position_ids=position_ids,
|
| 211 |
+
past_key_values=past_key_values,
|
| 212 |
+
use_cache=use_cache,
|
| 213 |
+
**kwargs,
|
| 214 |
+
)
|
| 215 |
+
|
| 216 |
+
hidden_states = self.norm(hidden_states)
|
| 217 |
+
|
| 218 |
+
return MoeModelOutputWithPast( # only diff with Mistral is the output type, we need MoE
|
| 219 |
+
last_hidden_state=hidden_states,
|
| 220 |
+
past_key_values=past_key_values,
|
| 221 |
+
)
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
class GraniteMoeForCausalLM(MixtralForCausalLM):
|
| 225 |
+
def __init__(self, config: GraniteMoeConfig):
|
| 226 |
+
super().__init__(config)
|
| 227 |
+
self.model = GraniteMoeModel(config)
|
| 228 |
+
self.logits_scaling = config.logits_scaling
|
| 229 |
+
|
| 230 |
+
@auto_docstring
|
| 231 |
+
@can_return_tuple
|
| 232 |
+
def forward(
|
| 233 |
+
self,
|
| 234 |
+
input_ids: torch.LongTensor | None = None,
|
| 235 |
+
attention_mask: torch.Tensor | None = None,
|
| 236 |
+
position_ids: torch.LongTensor | None = None,
|
| 237 |
+
past_key_values: Cache | None = None,
|
| 238 |
+
inputs_embeds: torch.FloatTensor | None = None,
|
| 239 |
+
labels: torch.LongTensor | None = None,
|
| 240 |
+
output_router_logits: bool | None = None,
|
| 241 |
+
logits_to_keep: int | torch.Tensor = 0,
|
| 242 |
+
**kwargs,
|
| 243 |
+
) -> tuple | MoeCausalLMOutputWithPast:
|
| 244 |
+
r"""
|
| 245 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 246 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
| 247 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
| 248 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
| 249 |
+
|
| 250 |
+
Example:
|
| 251 |
+
|
| 252 |
+
```python
|
| 253 |
+
>>> from transformers import AutoTokenizer, GraniteMoeForCausalLM
|
| 254 |
+
|
| 255 |
+
>>> model = GraniteMoeForCausalLM.from_pretrained("ibm/PowerMoE-3b")
|
| 256 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("ibm/PowerMoE-3b")
|
| 257 |
+
|
| 258 |
+
>>> prompt = "Hey, are you conscious? Can you talk to me?"
|
| 259 |
+
>>> inputs = tokenizer(prompt, return_tensors="pt")
|
| 260 |
+
|
| 261 |
+
>>> # Generate
|
| 262 |
+
>>> generate_ids = model.generate(inputs.input_ids, max_length=30)
|
| 263 |
+
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 264 |
+
"Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
|
| 265 |
+
```"""
|
| 266 |
+
output_router_logits = (
|
| 267 |
+
output_router_logits if output_router_logits is not None else self.config.output_router_logits
|
| 268 |
+
)
|
| 269 |
+
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
| 270 |
+
outputs = self.model(
|
| 271 |
+
input_ids=input_ids,
|
| 272 |
+
attention_mask=attention_mask,
|
| 273 |
+
position_ids=position_ids,
|
| 274 |
+
past_key_values=past_key_values,
|
| 275 |
+
inputs_embeds=inputs_embeds,
|
| 276 |
+
**kwargs,
|
| 277 |
+
)
|
| 278 |
+
|
| 279 |
+
# Only compute necessary logits
|
| 280 |
+
hidden_states = outputs.last_hidden_state
|
| 281 |
+
slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
|
| 282 |
+
logits = self.lm_head(hidden_states[:, slice_indices, :])
|
| 283 |
+
logits = logits / self.config.logits_scaling
|
| 284 |
+
|
| 285 |
+
loss = None
|
| 286 |
+
if labels is not None:
|
| 287 |
+
# Flatten the tokens
|
| 288 |
+
loss = self.loss_function(
|
| 289 |
+
logits,
|
| 290 |
+
labels,
|
| 291 |
+
vocab_size=self.config.vocab_size,
|
| 292 |
+
**kwargs,
|
| 293 |
+
)
|
| 294 |
+
|
| 295 |
+
aux_loss = None
|
| 296 |
+
if output_router_logits:
|
| 297 |
+
aux_loss = load_balancing_loss_func(
|
| 298 |
+
outputs.router_logits,
|
| 299 |
+
self.num_experts,
|
| 300 |
+
self.num_experts_per_tok,
|
| 301 |
+
attention_mask,
|
| 302 |
+
)
|
| 303 |
+
if labels is not None:
|
| 304 |
+
loss += self.router_aux_loss_coef * aux_loss.to(loss.device) # make sure to reside in the same device
|
| 305 |
+
return MoeCausalLMOutputWithPast(
|
| 306 |
+
loss=loss,
|
| 307 |
+
aux_loss=aux_loss,
|
| 308 |
+
logits=logits,
|
| 309 |
+
past_key_values=outputs.past_key_values,
|
| 310 |
+
hidden_states=outputs.hidden_states,
|
| 311 |
+
attentions=outputs.attentions,
|
| 312 |
+
router_logits=outputs.router_logits,
|
| 313 |
+
)
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
__all__ = ["GraniteMoeForCausalLM", "GraniteMoeModel", "GraniteMoePreTrainedModel"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/llava/__init__.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2024 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_llava import *
|
| 22 |
+
from .image_processing_llava import *
|
| 23 |
+
from .image_processing_pil_llava import *
|
| 24 |
+
from .modeling_llava import *
|
| 25 |
+
from .processing_llava import *
|
| 26 |
+
else:
|
| 27 |
+
import sys
|
| 28 |
+
|
| 29 |
+
_file = globals()["__file__"]
|
| 30 |
+
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/processing_utils.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/pytorch_utils.py
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2022 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 __future__ import annotations
|
| 15 |
+
|
| 16 |
+
import inspect
|
| 17 |
+
from collections.abc import Callable
|
| 18 |
+
from functools import lru_cache, wraps
|
| 19 |
+
|
| 20 |
+
import torch
|
| 21 |
+
from safetensors.torch import storage_ptr, storage_size
|
| 22 |
+
from torch import nn
|
| 23 |
+
|
| 24 |
+
from .utils import (
|
| 25 |
+
is_torch_greater_or_equal,
|
| 26 |
+
is_torch_xla_available,
|
| 27 |
+
is_torchdynamo_compiling,
|
| 28 |
+
logging,
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
ALL_LAYERNORM_LAYERS = [nn.LayerNorm]
|
| 33 |
+
|
| 34 |
+
logger = logging.get_logger(__name__)
|
| 35 |
+
|
| 36 |
+
is_torch_greater_or_equal_than_2_8 = is_torch_greater_or_equal("2.8", accept_dev=True)
|
| 37 |
+
is_torch_greater_or_equal_than_2_6 = is_torch_greater_or_equal("2.6", accept_dev=True)
|
| 38 |
+
|
| 39 |
+
# For backwards compatibility (e.g. some remote codes on Hub using those variables).
|
| 40 |
+
is_torch_greater_or_equal_than_2_4 = is_torch_greater_or_equal("2.4", accept_dev=True)
|
| 41 |
+
is_torch_greater_or_equal_than_2_3 = is_torch_greater_or_equal("2.3", accept_dev=True)
|
| 42 |
+
is_torch_greater_or_equal_than_2_2 = is_torch_greater_or_equal("2.2", accept_dev=True)
|
| 43 |
+
is_torch_greater_or_equal_than_2_1 = is_torch_greater_or_equal("2.1", accept_dev=True)
|
| 44 |
+
is_torch_greater_or_equal_than_2_0 = is_torch_greater_or_equal("2.0", accept_dev=True)
|
| 45 |
+
is_torch_greater_or_equal_than_1_13 = is_torch_greater_or_equal("1.13", accept_dev=True)
|
| 46 |
+
is_torch_greater_or_equal_than_1_12 = is_torch_greater_or_equal("1.12", accept_dev=True)
|
| 47 |
+
|
| 48 |
+
# Cache this result has it's a C FFI call which can be pretty time-consuming
|
| 49 |
+
_torch_distributed_available = torch.distributed.is_available()
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def softmax_backward_data(parent, grad_output, output):
|
| 53 |
+
"""
|
| 54 |
+
A function that calls the internal `_softmax_backward_data` PyTorch method and that adjusts the arguments according
|
| 55 |
+
to the torch version detected.
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
from torch import _softmax_backward_data
|
| 59 |
+
|
| 60 |
+
return _softmax_backward_data(grad_output, output, parent.dim, output.dtype)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def prune_linear_layer(layer: nn.Linear, index: torch.LongTensor, dim: int = 0) -> nn.Linear:
|
| 64 |
+
"""
|
| 65 |
+
Prune a linear layer to keep only entries in index.
|
| 66 |
+
|
| 67 |
+
Used to remove heads.
|
| 68 |
+
|
| 69 |
+
Args:
|
| 70 |
+
layer (`torch.nn.Linear`): The layer to prune.
|
| 71 |
+
index (`torch.LongTensor`): The indices to keep in the layer.
|
| 72 |
+
dim (`int`, *optional*, defaults to 0): The dimension on which to keep the indices.
|
| 73 |
+
|
| 74 |
+
Returns:
|
| 75 |
+
`torch.nn.Linear`: The pruned layer as a new layer with `requires_grad=True`.
|
| 76 |
+
"""
|
| 77 |
+
index = index.to(layer.weight.device)
|
| 78 |
+
W = layer.weight.index_select(dim, index).detach().clone()
|
| 79 |
+
if layer.bias is not None:
|
| 80 |
+
if dim == 1:
|
| 81 |
+
b = layer.bias.detach().clone()
|
| 82 |
+
else:
|
| 83 |
+
b = layer.bias[index].detach().clone()
|
| 84 |
+
new_size = list(layer.weight.size())
|
| 85 |
+
new_size[dim] = len(index)
|
| 86 |
+
new_layer = nn.Linear(new_size[1], new_size[0], bias=layer.bias is not None).to(layer.weight.device)
|
| 87 |
+
new_layer.weight.requires_grad = False
|
| 88 |
+
new_layer.weight.copy_(W.contiguous())
|
| 89 |
+
new_layer.weight.requires_grad = True
|
| 90 |
+
if layer.bias is not None:
|
| 91 |
+
new_layer.bias.requires_grad = False
|
| 92 |
+
new_layer.bias.copy_(b.contiguous())
|
| 93 |
+
new_layer.bias.requires_grad = True
|
| 94 |
+
return new_layer
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class Conv1D(nn.Module):
|
| 98 |
+
"""
|
| 99 |
+
1D-convolutional layer as defined by Radford et al. for OpenAI GPT (and also used in GPT-2).
|
| 100 |
+
|
| 101 |
+
Basically works like a linear layer but the weights are transposed.
|
| 102 |
+
|
| 103 |
+
Args:
|
| 104 |
+
nf (`int`): The number of output features.
|
| 105 |
+
nx (`int`): The number of input features.
|
| 106 |
+
"""
|
| 107 |
+
|
| 108 |
+
def __init__(self, nf, nx):
|
| 109 |
+
super().__init__()
|
| 110 |
+
self.nf = nf
|
| 111 |
+
self.nx = nx
|
| 112 |
+
self.weight = nn.Parameter(torch.empty(nx, nf))
|
| 113 |
+
self.bias = nn.Parameter(torch.zeros(nf))
|
| 114 |
+
nn.init.normal_(self.weight, std=0.02)
|
| 115 |
+
|
| 116 |
+
def __repr__(self) -> str:
|
| 117 |
+
return "Conv1D(nf={nf}, nx={nx})".format(**self.__dict__)
|
| 118 |
+
|
| 119 |
+
def forward(self, x):
|
| 120 |
+
size_out = x.size()[:-1] + (self.nf,)
|
| 121 |
+
x = torch.addmm(self.bias, x.view(-1, x.size(-1)), self.weight)
|
| 122 |
+
x = x.view(size_out)
|
| 123 |
+
return x
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def apply_chunking_to_forward(
|
| 127 |
+
forward_fn: Callable[..., torch.Tensor],
|
| 128 |
+
chunk_size: int,
|
| 129 |
+
chunk_dim: int,
|
| 130 |
+
*input_tensors,
|
| 131 |
+
) -> torch.Tensor:
|
| 132 |
+
"""
|
| 133 |
+
This function chunks the `input_tensors` into smaller input tensor parts of size `chunk_size` over the dimension
|
| 134 |
+
`chunk_dim`. It then applies a layer `forward_fn` to each chunk independently to save memory.
|
| 135 |
+
|
| 136 |
+
If the `forward_fn` is independent across the `chunk_dim` this function will yield the same result as directly
|
| 137 |
+
applying `forward_fn` to `input_tensors`.
|
| 138 |
+
|
| 139 |
+
Args:
|
| 140 |
+
forward_fn (`Callable[..., torch.Tensor]`):
|
| 141 |
+
The forward function of the model.
|
| 142 |
+
chunk_size (`int`):
|
| 143 |
+
The chunk size of a chunked tensor: `num_chunks = len(input_tensors[0]) / chunk_size`.
|
| 144 |
+
chunk_dim (`int`):
|
| 145 |
+
The dimension over which the `input_tensors` should be chunked.
|
| 146 |
+
input_tensors (`tuple[torch.Tensor]`):
|
| 147 |
+
The input tensors of `forward_fn` which will be chunked
|
| 148 |
+
|
| 149 |
+
Returns:
|
| 150 |
+
`torch.Tensor`: A tensor with the same shape as the `forward_fn` would have given if applied`.
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
Examples:
|
| 154 |
+
|
| 155 |
+
```python
|
| 156 |
+
# rename the usual forward() fn to forward_chunk()
|
| 157 |
+
def forward_chunk(self, hidden_states):
|
| 158 |
+
hidden_states = self.decoder(hidden_states)
|
| 159 |
+
return hidden_states
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
# implement a chunked forward function
|
| 163 |
+
def forward(self, hidden_states):
|
| 164 |
+
return apply_chunking_to_forward(self.forward_chunk, self.chunk_size_lm_head, self.seq_len_dim, hidden_states)
|
| 165 |
+
```"""
|
| 166 |
+
|
| 167 |
+
assert len(input_tensors) > 0, f"{input_tensors} has to be a tuple/list of tensors"
|
| 168 |
+
|
| 169 |
+
# inspect.signature exist since python 3.5 and is a python method -> no problem with backward compatibility
|
| 170 |
+
num_args_in_forward_chunk_fn = len(inspect.signature(forward_fn).parameters)
|
| 171 |
+
if num_args_in_forward_chunk_fn != len(input_tensors):
|
| 172 |
+
raise ValueError(
|
| 173 |
+
f"forward_chunk_fn expects {num_args_in_forward_chunk_fn} arguments, but only {len(input_tensors)} input "
|
| 174 |
+
"tensors are given"
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
if chunk_size > 0:
|
| 178 |
+
tensor_shape = input_tensors[0].shape[chunk_dim]
|
| 179 |
+
for input_tensor in input_tensors:
|
| 180 |
+
if input_tensor.shape[chunk_dim] != tensor_shape:
|
| 181 |
+
raise ValueError(
|
| 182 |
+
f"All input tenors have to be of the same shape: {tensor_shape}, "
|
| 183 |
+
f"found shape {input_tensor.shape[chunk_dim]}"
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
if input_tensors[0].shape[chunk_dim] % chunk_size != 0:
|
| 187 |
+
raise ValueError(
|
| 188 |
+
f"The dimension to be chunked {input_tensors[0].shape[chunk_dim]} has to be a multiple of the chunk "
|
| 189 |
+
f"size {chunk_size}"
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
num_chunks = input_tensors[0].shape[chunk_dim] // chunk_size
|
| 193 |
+
|
| 194 |
+
# chunk input tensor into tuples
|
| 195 |
+
input_tensors_chunks = tuple(input_tensor.chunk(num_chunks, dim=chunk_dim) for input_tensor in input_tensors)
|
| 196 |
+
# apply forward fn to every tuple
|
| 197 |
+
output_chunks = tuple(forward_fn(*input_tensors_chunk) for input_tensors_chunk in zip(*input_tensors_chunks))
|
| 198 |
+
# concatenate output at same dimension
|
| 199 |
+
return torch.cat(output_chunks, dim=chunk_dim)
|
| 200 |
+
|
| 201 |
+
return forward_fn(*input_tensors)
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def meshgrid(*tensors: torch.Tensor | list[torch.Tensor], indexing: str | None = None) -> tuple[torch.Tensor, ...]:
|
| 205 |
+
"""
|
| 206 |
+
Wrapper around torch.meshgrid to avoid warning messages about the introduced `indexing` argument.
|
| 207 |
+
|
| 208 |
+
Reference: https://pytorch.org/docs/1.13/generated/torch.meshgrid.html
|
| 209 |
+
"""
|
| 210 |
+
return torch.meshgrid(*tensors, indexing=indexing)
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def id_tensor_storage(tensor: torch.Tensor) -> tuple[torch.device, int, int]:
|
| 214 |
+
"""
|
| 215 |
+
Unique identifier to a tensor storage. Multiple different tensors can share the same underlying storage. For
|
| 216 |
+
example, "meta" tensors all share the same storage, and thus their identifier will all be equal. This identifier is
|
| 217 |
+
guaranteed to be unique and constant for this tensor's storage during its lifetime. Two tensor storages with
|
| 218 |
+
non-overlapping lifetimes may have the same id.
|
| 219 |
+
"""
|
| 220 |
+
if _torch_distributed_available and is_torch_greater_or_equal("2.5"):
|
| 221 |
+
from torch.distributed.tensor import DTensor
|
| 222 |
+
|
| 223 |
+
if isinstance(tensor, DTensor):
|
| 224 |
+
local_tensor = tensor.to_local()
|
| 225 |
+
return tensor.device, local_tensor.storage().data_ptr(), tensor.nbytes
|
| 226 |
+
|
| 227 |
+
if tensor.device.type == "xla" and is_torch_xla_available():
|
| 228 |
+
# NOTE: xla tensors dont have storage
|
| 229 |
+
# use some other unique id to distinguish.
|
| 230 |
+
# this is a XLA tensor, it must be created using torch_xla's
|
| 231 |
+
# device. So the following import is safe:
|
| 232 |
+
import torch_xla
|
| 233 |
+
|
| 234 |
+
unique_id = torch_xla._XLAC._xla_get_tensor_id(tensor)
|
| 235 |
+
else:
|
| 236 |
+
unique_id = storage_ptr(tensor)
|
| 237 |
+
|
| 238 |
+
return tensor.device, unique_id, storage_size(tensor)
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
@wraps(lru_cache)
|
| 242 |
+
def compile_compatible_method_lru_cache(*lru_args, **lru_kwargs):
|
| 243 |
+
"""
|
| 244 |
+
LRU cache decorator from standard functools library, but with a workaround to disable
|
| 245 |
+
caching when torchdynamo is compiling. Expected to work with class methods.
|
| 246 |
+
"""
|
| 247 |
+
|
| 248 |
+
def decorator(func):
|
| 249 |
+
func_with_cache = lru_cache(*lru_args, **lru_kwargs)(func)
|
| 250 |
+
|
| 251 |
+
@wraps(func)
|
| 252 |
+
def wrapper(*args, **kwargs):
|
| 253 |
+
if is_torchdynamo_compiling():
|
| 254 |
+
return func(*args, **kwargs)
|
| 255 |
+
else:
|
| 256 |
+
return func_with_cache(*args, **kwargs)
|
| 257 |
+
|
| 258 |
+
return wrapper
|
| 259 |
+
|
| 260 |
+
return decorator
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/trainer_optimizer.py
ADDED
|
@@ -0,0 +1,615 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2024 The 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 |
+
Optimizer utilities for the Trainer class.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
from __future__ import annotations
|
| 19 |
+
|
| 20 |
+
import importlib.metadata
|
| 21 |
+
import logging
|
| 22 |
+
from collections.abc import Callable
|
| 23 |
+
from dataclasses import dataclass
|
| 24 |
+
from typing import TYPE_CHECKING, Any
|
| 25 |
+
|
| 26 |
+
import torch
|
| 27 |
+
from packaging import version
|
| 28 |
+
from torch import nn
|
| 29 |
+
|
| 30 |
+
from .optimization import Adafactor
|
| 31 |
+
from .trainer_pt_utils import LayerWiseDummyOptimizer
|
| 32 |
+
from .trainer_utils import check_target_module_exists
|
| 33 |
+
from .training_args import OptimizerNames, ParallelMode
|
| 34 |
+
from .utils import (
|
| 35 |
+
is_apollo_torch_available,
|
| 36 |
+
is_bitsandbytes_available,
|
| 37 |
+
is_galore_torch_available,
|
| 38 |
+
is_grokadamw_available,
|
| 39 |
+
is_lomo_available,
|
| 40 |
+
is_schedulefree_available,
|
| 41 |
+
is_torch_optimi_available,
|
| 42 |
+
is_torchao_available,
|
| 43 |
+
strtobool,
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
if TYPE_CHECKING:
|
| 48 |
+
from .modeling_utils import PreTrainedModel
|
| 49 |
+
from .training_args import TrainingArguments
|
| 50 |
+
|
| 51 |
+
logger = logging.getLogger(__name__)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
@dataclass
|
| 55 |
+
class OptimizerContext:
|
| 56 |
+
"""Context object passed to all optimizer handlers."""
|
| 57 |
+
|
| 58 |
+
args: TrainingArguments
|
| 59 |
+
model: PreTrainedModel | None
|
| 60 |
+
optimizer_kwargs: dict[str, Any]
|
| 61 |
+
adam_kwargs: dict[str, Any]
|
| 62 |
+
optim_args: dict[str, str]
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def _parse_optim_args(optim_args_str: str | None) -> dict[str, str]:
|
| 66 |
+
"""Parse optimizer arguments from a comma-separated string."""
|
| 67 |
+
if not optim_args_str:
|
| 68 |
+
return {}
|
| 69 |
+
optim_args = {}
|
| 70 |
+
for mapping in optim_args_str.replace(" ", "").split(","):
|
| 71 |
+
key, value = mapping.split("=")
|
| 72 |
+
optim_args[key] = value
|
| 73 |
+
return optim_args
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
# Type alias for optimizer handler functions
|
| 77 |
+
OptimizerHandler = Callable[[OptimizerContext], tuple[Any, dict[str, Any]]]
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def is_optimizer_factory(optimizer_cls_or_factory: Any) -> bool:
|
| 81 |
+
"""
|
| 82 |
+
Check if the returned value from a handler is a factory rather than an Optimizer class.
|
| 83 |
+
|
| 84 |
+
Factory callables are used for complex optimizers like Muon or Dion that need to:
|
| 85 |
+
- Split parameters between multiple internal optimizers
|
| 86 |
+
- Handle complex sharding logic
|
| 87 |
+
- Access the full model structure for parameter grouping
|
| 88 |
+
|
| 89 |
+
Args:
|
| 90 |
+
optimizer_cls_or_factory: The first element returned by an optimizer handler.
|
| 91 |
+
|
| 92 |
+
Returns:
|
| 93 |
+
`bool`: True if it's not an Optimizer class (i.e., likely a factory), False if it's an Optimizer class.
|
| 94 |
+
"""
|
| 95 |
+
# If it's a class that's a subclass of torch.optim.Optimizer, it's not a factory
|
| 96 |
+
if isinstance(optimizer_cls_or_factory, type) and issubclass(optimizer_cls_or_factory, torch.optim.Optimizer):
|
| 97 |
+
return False
|
| 98 |
+
return True
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def _setup_low_rank_optimizer(
|
| 102 |
+
args: TrainingArguments,
|
| 103 |
+
model: PreTrainedModel,
|
| 104 |
+
optimizer_name: str,
|
| 105 |
+
optimizer_mapping: dict[str, Any],
|
| 106 |
+
optim_kwargs: dict[str, Any],
|
| 107 |
+
optimizer_kwargs: dict[str, Any],
|
| 108 |
+
is_layerwise_supported: bool = True,
|
| 109 |
+
) -> tuple[Any, dict[str, Any]]:
|
| 110 |
+
"""
|
| 111 |
+
Helper function to set up low-rank optimizers like GaLore and Apollo.
|
| 112 |
+
|
| 113 |
+
These optimizers apply low-rank projections to specific target modules (typically linear layers).
|
| 114 |
+
"""
|
| 115 |
+
is_layerwise = optimizer_name.lower().endswith("layerwise")
|
| 116 |
+
if is_layerwise and args.parallel_mode == ParallelMode.DISTRIBUTED and is_layerwise_supported:
|
| 117 |
+
raise NotImplementedError(f"Layer-wise {optimizer_name} does not support DDP at this time")
|
| 118 |
+
|
| 119 |
+
optimizer_cls = optimizer_mapping[optimizer_name]
|
| 120 |
+
|
| 121 |
+
if args.optim_target_modules is None:
|
| 122 |
+
raise ValueError(f"You need to define `optim_target_modules` to use {optimizer_name} optimizers")
|
| 123 |
+
|
| 124 |
+
if not isinstance(args.optim_target_modules, (list, str)):
|
| 125 |
+
raise TypeError(
|
| 126 |
+
f"`optim_target_modules` must be a list of strings, a regex string, or 'all-linear'. "
|
| 127 |
+
f"Got: {args.optim_target_modules}"
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
if model is None:
|
| 131 |
+
raise ValueError(f"You need to pass a model to initialize {optimizer_name} optimizer.")
|
| 132 |
+
|
| 133 |
+
all_linear = (
|
| 134 |
+
isinstance(args.optim_target_modules, str) and args.optim_target_modules.replace("_", "-") == "all-linear"
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
target_params_names = []
|
| 138 |
+
for module_name, module in model.named_modules():
|
| 139 |
+
target_module_exists, is_regex = check_target_module_exists(
|
| 140 |
+
args.optim_target_modules, module_name, return_is_regex=True
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
if not isinstance(module, nn.Linear):
|
| 144 |
+
if target_module_exists and not is_regex:
|
| 145 |
+
logger.warning(f"{module_name} matched but ignored. {optimizer_name} only supports linear layers.")
|
| 146 |
+
continue
|
| 147 |
+
|
| 148 |
+
if not target_module_exists and not all_linear:
|
| 149 |
+
continue
|
| 150 |
+
|
| 151 |
+
target_params_names.append(module_name + ".weight")
|
| 152 |
+
|
| 153 |
+
if len(target_params_names) == 0:
|
| 154 |
+
raise ValueError(f"No target modules found for {optimizer_name} ({args.optim_target_modules}).")
|
| 155 |
+
|
| 156 |
+
target_params = [p for n, p in model.named_parameters() if n in target_params_names]
|
| 157 |
+
non_target_params = [p for n, p in model.named_parameters() if n not in target_params_names]
|
| 158 |
+
|
| 159 |
+
param_groups = [
|
| 160 |
+
{"params": non_target_params},
|
| 161 |
+
{"params": target_params, **optim_kwargs},
|
| 162 |
+
]
|
| 163 |
+
|
| 164 |
+
if is_layerwise:
|
| 165 |
+
if args.gradient_accumulation_steps != 1:
|
| 166 |
+
raise ValueError(f"Layerwise {optimizer_name} does not support gradient accumulation!")
|
| 167 |
+
|
| 168 |
+
optimizer_dict = {}
|
| 169 |
+
for param in non_target_params:
|
| 170 |
+
optimizer_dict[param] = optimizer_cls([{"params": [param]}], **optimizer_kwargs)
|
| 171 |
+
for param in target_params:
|
| 172 |
+
optimizer_dict[param] = optimizer_cls([{"params": [param], **optim_kwargs}], **optimizer_kwargs)
|
| 173 |
+
|
| 174 |
+
def optimizer_hook(param):
|
| 175 |
+
if param.grad is not None:
|
| 176 |
+
optimizer_dict[param].step()
|
| 177 |
+
optimizer_dict[param].zero_grad()
|
| 178 |
+
|
| 179 |
+
for param in model.parameters():
|
| 180 |
+
if param.requires_grad:
|
| 181 |
+
param.register_post_accumulate_grad_hook(optimizer_hook)
|
| 182 |
+
|
| 183 |
+
optimizer_cls = LayerWiseDummyOptimizer
|
| 184 |
+
optimizer_kwargs.update({"optimizer_dict": optimizer_dict})
|
| 185 |
+
|
| 186 |
+
optimizer_kwargs.update({"params": param_groups})
|
| 187 |
+
return optimizer_cls, optimizer_kwargs
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
# =============================================================================
|
| 191 |
+
# Individual optimizer handlers
|
| 192 |
+
# =============================================================================
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def _get_adafactor(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 196 |
+
"""Get Adafactor optimizer."""
|
| 197 |
+
ctx.optimizer_kwargs.update({"scale_parameter": False, "relative_step": False})
|
| 198 |
+
return Adafactor, ctx.optimizer_kwargs
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def _get_adamw_torch(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 202 |
+
"""Get PyTorch AdamW optimizer (regular or fused)."""
|
| 203 |
+
from torch.optim import AdamW
|
| 204 |
+
|
| 205 |
+
ctx.optimizer_kwargs.update(ctx.adam_kwargs)
|
| 206 |
+
if ctx.args.optim == OptimizerNames.ADAMW_TORCH_FUSED:
|
| 207 |
+
ctx.optimizer_kwargs.update({"fused": True})
|
| 208 |
+
return AdamW, ctx.optimizer_kwargs
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def _get_adamw_torch_xla(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 212 |
+
"""Get Torch XLA syncfree AdamW optimizer."""
|
| 213 |
+
try:
|
| 214 |
+
from torch_xla.amp.syncfree import AdamW
|
| 215 |
+
|
| 216 |
+
ctx.optimizer_kwargs.update(ctx.adam_kwargs)
|
| 217 |
+
return AdamW, ctx.optimizer_kwargs
|
| 218 |
+
except ImportError:
|
| 219 |
+
raise ValueError("Trainer failed to import syncfree AdamW from torch_xla.")
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def _get_adamw_torch_npu_fused(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 223 |
+
"""Get NPU Fused AdamW optimizer."""
|
| 224 |
+
try:
|
| 225 |
+
from torch_npu.optim import NpuFusedAdamW
|
| 226 |
+
|
| 227 |
+
ctx.optimizer_kwargs.update(ctx.adam_kwargs)
|
| 228 |
+
return NpuFusedAdamW, ctx.optimizer_kwargs
|
| 229 |
+
except ImportError:
|
| 230 |
+
raise ValueError("Trainer failed to import FusedAdamW from torch_npu.")
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def _get_bitsandbytes_optimizer(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 234 |
+
"""Get bitsandbytes optimizer (AdamW, Lion, RMSprop variants)."""
|
| 235 |
+
if not is_bitsandbytes_available():
|
| 236 |
+
raise ImportError(
|
| 237 |
+
"You need to install `bitsandbytes` in order to use bitsandbytes optimizers: `pip install -U bitsandbytes`"
|
| 238 |
+
)
|
| 239 |
+
|
| 240 |
+
from bitsandbytes.optim import AdamW, Lion, RMSprop
|
| 241 |
+
|
| 242 |
+
optim_name = ctx.args.optim
|
| 243 |
+
is_paged = "paged" in optim_name
|
| 244 |
+
optim_bits = 8 if "8bit" in optim_name else 32
|
| 245 |
+
optimizer_cls = None
|
| 246 |
+
additional_optim_kwargs = ctx.adam_kwargs
|
| 247 |
+
|
| 248 |
+
if "adam" in optim_name:
|
| 249 |
+
optimizer_cls = AdamW
|
| 250 |
+
elif "lion" in optim_name:
|
| 251 |
+
optimizer_cls = Lion
|
| 252 |
+
additional_optim_kwargs = {"betas": (ctx.args.adam_beta1, ctx.args.adam_beta2)}
|
| 253 |
+
elif "rmsprop" in optim_name:
|
| 254 |
+
optimizer_cls = RMSprop
|
| 255 |
+
additional_optim_kwargs = ctx.optim_args
|
| 256 |
+
elif "ademamix" in optim_name:
|
| 257 |
+
from bitsandbytes.optim import AdEMAMix
|
| 258 |
+
|
| 259 |
+
optimizer_cls = AdEMAMix
|
| 260 |
+
additional_optim_kwargs = {
|
| 261 |
+
"betas": (
|
| 262 |
+
float(ctx.optim_args.get("beta1", ctx.args.adam_beta1)),
|
| 263 |
+
float(ctx.optim_args.get("beta2", ctx.args.adam_beta2)),
|
| 264 |
+
float(ctx.optim_args.get("beta3", 0.9999)),
|
| 265 |
+
),
|
| 266 |
+
"alpha": float(ctx.optim_args.get("alpha", 5.0)),
|
| 267 |
+
"eps": float(ctx.optim_args.get("eps", ctx.args.adam_epsilon)),
|
| 268 |
+
}
|
| 269 |
+
if "t_alpha" in ctx.optim_args:
|
| 270 |
+
additional_optim_kwargs["t_alpha"] = int(ctx.optim_args["t_alpha"])
|
| 271 |
+
if "t_beta3" in ctx.optim_args:
|
| 272 |
+
additional_optim_kwargs["t_beta3"] = int(ctx.optim_args["t_beta3"])
|
| 273 |
+
|
| 274 |
+
bnb_kwargs = {"optim_bits": optim_bits}
|
| 275 |
+
if "rmsprop" not in optim_name:
|
| 276 |
+
bnb_kwargs["is_paged"] = is_paged
|
| 277 |
+
|
| 278 |
+
ctx.optimizer_kwargs.update(additional_optim_kwargs)
|
| 279 |
+
ctx.optimizer_kwargs.update(bnb_kwargs)
|
| 280 |
+
return optimizer_cls, ctx.optimizer_kwargs
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
def _get_adamw_anyprecision(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 284 |
+
"""Get AnyPrecision AdamW optimizer."""
|
| 285 |
+
try:
|
| 286 |
+
from torchdistx.optimizers import AnyPrecisionAdamW
|
| 287 |
+
|
| 288 |
+
ctx.optimizer_kwargs.update(ctx.adam_kwargs)
|
| 289 |
+
ctx.optimizer_kwargs.update(
|
| 290 |
+
{
|
| 291 |
+
"use_kahan_summation": strtobool(ctx.optim_args.get("use_kahan_summation", "False")),
|
| 292 |
+
"momentum_dtype": getattr(torch, ctx.optim_args.get("momentum_dtype", "float32")),
|
| 293 |
+
"variance_dtype": getattr(torch, ctx.optim_args.get("variance_dtype", "float32")),
|
| 294 |
+
"compensation_buffer_dtype": getattr(
|
| 295 |
+
torch, ctx.optim_args.get("compensation_buffer_dtype", "bfloat16")
|
| 296 |
+
),
|
| 297 |
+
}
|
| 298 |
+
)
|
| 299 |
+
return AnyPrecisionAdamW, ctx.optimizer_kwargs
|
| 300 |
+
except ImportError:
|
| 301 |
+
raise ValueError("Please install https://github.com/pytorch/torchdistx")
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
def _get_sgd(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 305 |
+
"""Get SGD optimizer."""
|
| 306 |
+
kwargs = ctx.optimizer_kwargs.copy()
|
| 307 |
+
if ctx.optim_args:
|
| 308 |
+
for key in ("momentum", "dampening", "weight_decay"):
|
| 309 |
+
if key in ctx.optim_args:
|
| 310 |
+
kwargs[key] = float(ctx.optim_args[key])
|
| 311 |
+
if "nesterov" in ctx.optim_args:
|
| 312 |
+
kwargs["nesterov"] = ctx.optim_args["nesterov"].lower() in ("true", "1", "yes")
|
| 313 |
+
return torch.optim.SGD, kwargs
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def _get_adagrad(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 317 |
+
"""Get Adagrad optimizer."""
|
| 318 |
+
kwargs = ctx.optimizer_kwargs.copy()
|
| 319 |
+
if ctx.optim_args:
|
| 320 |
+
for key in ("lr_decay", "weight_decay", "eps"):
|
| 321 |
+
if key in ctx.optim_args:
|
| 322 |
+
kwargs[key] = float(ctx.optim_args[key])
|
| 323 |
+
return torch.optim.Adagrad, kwargs
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
def _get_rmsprop(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 327 |
+
"""Get RMSprop optimizer."""
|
| 328 |
+
kwargs = ctx.optimizer_kwargs.copy()
|
| 329 |
+
if ctx.optim_args:
|
| 330 |
+
for key in ("momentum", "alpha", "eps", "weight_decay"):
|
| 331 |
+
if key in ctx.optim_args:
|
| 332 |
+
kwargs[key] = float(ctx.optim_args[key])
|
| 333 |
+
if "centered" in ctx.optim_args:
|
| 334 |
+
kwargs["centered"] = ctx.optim_args["centered"].lower() in ("true", "1", "yes")
|
| 335 |
+
return torch.optim.RMSprop, kwargs
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def _get_galore_optimizer(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 339 |
+
"""Get GaLore optimizer."""
|
| 340 |
+
if not is_galore_torch_available():
|
| 341 |
+
raise ImportError(
|
| 342 |
+
"You need to install `galore_torch` in order to use GaLore optimizers. "
|
| 343 |
+
"Install it with `pip install git+https://github.com/jiaweizzhao/GaLore`"
|
| 344 |
+
)
|
| 345 |
+
from galore_torch import GaLoreAdafactor, GaLoreAdamW, GaLoreAdamW8bit
|
| 346 |
+
|
| 347 |
+
optimizer_mapping = {
|
| 348 |
+
OptimizerNames.GALORE_ADAMW: GaLoreAdamW,
|
| 349 |
+
OptimizerNames.GALORE_ADAMW_8BIT: GaLoreAdamW8bit,
|
| 350 |
+
OptimizerNames.GALORE_ADAFACTOR: GaLoreAdafactor,
|
| 351 |
+
OptimizerNames.GALORE_ADAMW_LAYERWISE: GaLoreAdamW,
|
| 352 |
+
OptimizerNames.GALORE_ADAMW_8BIT_LAYERWISE: GaLoreAdamW8bit,
|
| 353 |
+
OptimizerNames.GALORE_ADAFACTOR_LAYERWISE: GaLoreAdafactor,
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
galore_optim_kwargs = {
|
| 357 |
+
"rank": int(ctx.optim_args.pop("rank", 128)),
|
| 358 |
+
"update_proj_gap": int(ctx.optim_args.pop("update_proj_gap", 200)),
|
| 359 |
+
"scale": float(ctx.optim_args.pop("scale", 0.25)),
|
| 360 |
+
"proj_type": ctx.optim_args.pop("proj_type", "std"),
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
optimizer_cls, optimizer_kwargs = _setup_low_rank_optimizer(
|
| 364 |
+
ctx.args, ctx.model, ctx.args.optim, optimizer_mapping, galore_optim_kwargs, ctx.optimizer_kwargs
|
| 365 |
+
)
|
| 366 |
+
if ctx.args.optim == OptimizerNames.GALORE_ADAFACTOR:
|
| 367 |
+
optimizer_kwargs.update({"scale_parameter": False, "relative_step": False})
|
| 368 |
+
return optimizer_cls, optimizer_kwargs
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
def _get_apollo_optimizer(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 372 |
+
"""Get Apollo optimizer."""
|
| 373 |
+
if not is_apollo_torch_available():
|
| 374 |
+
raise ImportError(
|
| 375 |
+
"You need to install `apollo_torch` in order to use APOLLO optimizers. "
|
| 376 |
+
"Install it with `pip install git+https://github.com/zhuhanqing/APOLLO`"
|
| 377 |
+
)
|
| 378 |
+
from apollo_torch import APOLLOAdamW
|
| 379 |
+
|
| 380 |
+
optimizer_mapping = {
|
| 381 |
+
OptimizerNames.APOLLO_ADAMW: APOLLOAdamW,
|
| 382 |
+
OptimizerNames.APOLLO_ADAMW_LAYERWISE: APOLLOAdamW,
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
apollo_optim_kwargs = {
|
| 386 |
+
"rank": int(ctx.optim_args.pop("rank", 128)),
|
| 387 |
+
"proj": ctx.optim_args.pop("proj", "random"),
|
| 388 |
+
"scale_type": ctx.optim_args.pop("scale_type", "channel"),
|
| 389 |
+
"update_proj_gap": int(ctx.optim_args.pop("update_proj_gap", 200)),
|
| 390 |
+
"scale": float(ctx.optim_args.pop("scale", 1.0)),
|
| 391 |
+
"proj_type": ctx.optim_args.pop("proj_type", "std"),
|
| 392 |
+
}
|
| 393 |
+
apollo_optim_kwargs.update(ctx.adam_kwargs)
|
| 394 |
+
|
| 395 |
+
return _setup_low_rank_optimizer(
|
| 396 |
+
ctx.args, ctx.model, ctx.args.optim, optimizer_mapping, apollo_optim_kwargs, ctx.optimizer_kwargs
|
| 397 |
+
)
|
| 398 |
+
|
| 399 |
+
|
| 400 |
+
def _get_lomo_optimizer(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 401 |
+
"""Get LOMO optimizer."""
|
| 402 |
+
if not is_lomo_available():
|
| 403 |
+
raise ImportError(
|
| 404 |
+
"You need to install `lomo_optim` in order to use LOMO optimizers. "
|
| 405 |
+
"Install it with `pip install lomo-optim`"
|
| 406 |
+
)
|
| 407 |
+
|
| 408 |
+
if ctx.model is None:
|
| 409 |
+
raise ValueError("You need to pass a `model` in order to correctly initialize a LOMO optimizer.")
|
| 410 |
+
|
| 411 |
+
from lomo_optim import AdaLomo, Lomo
|
| 412 |
+
|
| 413 |
+
optimizer_cls = AdaLomo if "ada" in ctx.args.optim else Lomo
|
| 414 |
+
ctx.optimizer_kwargs.update({"model": ctx.model})
|
| 415 |
+
return optimizer_cls, ctx.optimizer_kwargs
|
| 416 |
+
|
| 417 |
+
|
| 418 |
+
def _get_grokadamw(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 419 |
+
"""Get GrokAdamW optimizer."""
|
| 420 |
+
if not is_grokadamw_available():
|
| 421 |
+
raise ValueError("Please install grokadamw with `pip install grokadamw`")
|
| 422 |
+
|
| 423 |
+
from grokadamw import GrokAdamW
|
| 424 |
+
|
| 425 |
+
ctx.optimizer_kwargs.update(
|
| 426 |
+
{
|
| 427 |
+
"alpha_init": float(ctx.optim_args.get("alpha_init", 0.98)),
|
| 428 |
+
"lamb": float(ctx.optim_args.get("lamb", 2.0)),
|
| 429 |
+
"gamma": float(ctx.optim_args.get("gamma", 0.1)),
|
| 430 |
+
"grokking_signal_decay_rate": float(ctx.optim_args.get("grokking_signal_decay_rate", 0.1)),
|
| 431 |
+
"gradient_clipping": float(ctx.optim_args.get("gradient_clipping", 1.0)),
|
| 432 |
+
}
|
| 433 |
+
)
|
| 434 |
+
return GrokAdamW, ctx.optimizer_kwargs
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
def _get_torchao_optimizer(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 438 |
+
"""Get TorchAO 4-bit or 8-bit optimizer."""
|
| 439 |
+
if not is_torchao_available() or version.parse(importlib.metadata.version("torchao")) < version.parse("0.4.0"):
|
| 440 |
+
raise ImportError(
|
| 441 |
+
"You need to have `torchao>=0.4.0` in order to use torch 4-bit optimizers. "
|
| 442 |
+
"Install it with `pip install torchao` or follow the instructions here: "
|
| 443 |
+
"https://github.com/pytorch/ao"
|
| 444 |
+
)
|
| 445 |
+
if version.parse(importlib.metadata.version("torch")) <= version.parse("2.4"):
|
| 446 |
+
raise ImportError(
|
| 447 |
+
"You need to have `torch>2.4` in order to use torch 4-bit optimizers. "
|
| 448 |
+
"Install it with `pip install --upgrade torch` it is available on pipy. "
|
| 449 |
+
"Otherwise, you need to install torch nightly."
|
| 450 |
+
)
|
| 451 |
+
|
| 452 |
+
if version.parse(importlib.metadata.version("torchao")) >= version.parse("0.11.0"):
|
| 453 |
+
from torchao.optim import AdamW4bit, AdamW8bit
|
| 454 |
+
else:
|
| 455 |
+
from torchao.prototype.low_bit_optim import AdamW4bit, AdamW8bit
|
| 456 |
+
|
| 457 |
+
if ctx.args.optim == OptimizerNames.ADAMW_TORCH_4BIT:
|
| 458 |
+
optimizer_cls = AdamW4bit
|
| 459 |
+
else:
|
| 460 |
+
optimizer_cls = AdamW8bit
|
| 461 |
+
|
| 462 |
+
ctx.optimizer_kwargs.update(
|
| 463 |
+
{
|
| 464 |
+
"block_size": ctx.optim_args.get("block_size", 256),
|
| 465 |
+
"bf16_stochastic_round": strtobool(ctx.optim_args.get("bf16_stochastic_round", "False")),
|
| 466 |
+
}
|
| 467 |
+
)
|
| 468 |
+
ctx.optimizer_kwargs.update(ctx.adam_kwargs)
|
| 469 |
+
return optimizer_cls, ctx.optimizer_kwargs
|
| 470 |
+
|
| 471 |
+
|
| 472 |
+
def _get_schedule_free_optimizer(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 473 |
+
"""Get ScheduleFree optimizer."""
|
| 474 |
+
if not is_schedulefree_available():
|
| 475 |
+
raise ImportError(
|
| 476 |
+
"You need to install `schedulefree` in order to use schedulefree optimizers. "
|
| 477 |
+
"Install it with `pip install schedulefree.`"
|
| 478 |
+
)
|
| 479 |
+
from schedulefree import AdamWScheduleFree, SGDScheduleFree
|
| 480 |
+
|
| 481 |
+
additional_optim_kwargs = {}
|
| 482 |
+
require_warmup = True
|
| 483 |
+
|
| 484 |
+
if ctx.args.optim == OptimizerNames.SCHEDULE_FREE_RADAM:
|
| 485 |
+
if not is_schedulefree_available("1.4.0"):
|
| 486 |
+
raise ImportError(
|
| 487 |
+
"You need to install `schedulefree>=1.4.0` in order to use RAdamScheduleFree optimizer. "
|
| 488 |
+
"Install it with `pip install schedulefree.`"
|
| 489 |
+
)
|
| 490 |
+
from schedulefree import RAdamScheduleFree
|
| 491 |
+
|
| 492 |
+
optimizer_cls = RAdamScheduleFree
|
| 493 |
+
additional_optim_kwargs = ctx.adam_kwargs
|
| 494 |
+
require_warmup = False
|
| 495 |
+
elif ctx.args.optim == OptimizerNames.SCHEDULE_FREE_ADAMW:
|
| 496 |
+
optimizer_cls = AdamWScheduleFree
|
| 497 |
+
additional_optim_kwargs = ctx.adam_kwargs
|
| 498 |
+
elif ctx.args.optim == OptimizerNames.SCHEDULE_FREE_SGD:
|
| 499 |
+
optimizer_cls = SGDScheduleFree
|
| 500 |
+
else:
|
| 501 |
+
raise ValueError("Invalid schedulefree optimizer")
|
| 502 |
+
|
| 503 |
+
additional_optim_kwargs["weight_decay"] = ctx.args.weight_decay
|
| 504 |
+
if require_warmup:
|
| 505 |
+
additional_optim_kwargs["warmup_steps"] = ctx.args.warmup_steps
|
| 506 |
+
additional_optim_kwargs.update(
|
| 507 |
+
{
|
| 508 |
+
"weight_lr_power": float(ctx.optim_args.get("weight_lr_power", 2.0)),
|
| 509 |
+
"r": float(ctx.optim_args.get("r", 0.0)),
|
| 510 |
+
}
|
| 511 |
+
)
|
| 512 |
+
ctx.optimizer_kwargs.update(additional_optim_kwargs)
|
| 513 |
+
return optimizer_cls, ctx.optimizer_kwargs
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
def _get_stable_adamw(ctx: OptimizerContext) -> tuple[Any, dict[str, Any]]:
|
| 517 |
+
"""Get StableAdamW optimizer from torch-optimi."""
|
| 518 |
+
if not is_torch_optimi_available():
|
| 519 |
+
raise ImportError(
|
| 520 |
+
"You need to install `torch-optimi` in order to use stable_adamw optimizers. "
|
| 521 |
+
"Install it with `pip install torch-optimi`."
|
| 522 |
+
)
|
| 523 |
+
from optimi import StableAdamW
|
| 524 |
+
|
| 525 |
+
max_lr = ctx.optim_args.pop("max_lr", None)
|
| 526 |
+
if max_lr is not None:
|
| 527 |
+
max_lr = float(max_lr)
|
| 528 |
+
|
| 529 |
+
kahan_sum = ctx.optim_args.pop("kahan_sum", None)
|
| 530 |
+
if kahan_sum is not None:
|
| 531 |
+
kahan_sum = bool(kahan_sum)
|
| 532 |
+
|
| 533 |
+
ctx.adam_kwargs["weight_decay"] = ctx.args.weight_decay
|
| 534 |
+
stable_adamw_kwargs = {
|
| 535 |
+
"decouple_lr": bool(ctx.optim_args.pop("decouple_lr", False)),
|
| 536 |
+
"max_lr": max_lr,
|
| 537 |
+
"kahan_sum": kahan_sum,
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
ctx.optimizer_kwargs.update(ctx.adam_kwargs)
|
| 541 |
+
ctx.optimizer_kwargs.update(stable_adamw_kwargs)
|
| 542 |
+
return StableAdamW, ctx.optimizer_kwargs
|
| 543 |
+
|
| 544 |
+
|
| 545 |
+
# =============================================================================
|
| 546 |
+
# Dispatch table
|
| 547 |
+
# =============================================================================
|
| 548 |
+
|
| 549 |
+
_BITSANDBYTES_OPTIMIZERS = [
|
| 550 |
+
OptimizerNames.ADAMW_BNB,
|
| 551 |
+
OptimizerNames.ADAMW_8BIT,
|
| 552 |
+
OptimizerNames.PAGED_ADAMW,
|
| 553 |
+
OptimizerNames.PAGED_ADAMW_8BIT,
|
| 554 |
+
OptimizerNames.ADEMAMIX,
|
| 555 |
+
OptimizerNames.ADEMAMIX_8BIT,
|
| 556 |
+
OptimizerNames.PAGED_ADEMAMIX,
|
| 557 |
+
OptimizerNames.PAGED_ADEMAMIX_8BIT,
|
| 558 |
+
OptimizerNames.LION,
|
| 559 |
+
OptimizerNames.LION_8BIT,
|
| 560 |
+
OptimizerNames.PAGED_LION,
|
| 561 |
+
OptimizerNames.PAGED_LION_8BIT,
|
| 562 |
+
OptimizerNames.RMSPROP_BNB,
|
| 563 |
+
OptimizerNames.RMSPROP_8BIT,
|
| 564 |
+
OptimizerNames.RMSPROP_32BIT,
|
| 565 |
+
]
|
| 566 |
+
|
| 567 |
+
_GALORE_OPTIMIZERS = [
|
| 568 |
+
OptimizerNames.GALORE_ADAMW,
|
| 569 |
+
OptimizerNames.GALORE_ADAMW_8BIT,
|
| 570 |
+
OptimizerNames.GALORE_ADAFACTOR,
|
| 571 |
+
OptimizerNames.GALORE_ADAMW_LAYERWISE,
|
| 572 |
+
OptimizerNames.GALORE_ADAMW_8BIT_LAYERWISE,
|
| 573 |
+
OptimizerNames.GALORE_ADAFACTOR_LAYERWISE,
|
| 574 |
+
]
|
| 575 |
+
|
| 576 |
+
_APOLLO_OPTIMIZERS = [
|
| 577 |
+
OptimizerNames.APOLLO_ADAMW,
|
| 578 |
+
OptimizerNames.APOLLO_ADAMW_LAYERWISE,
|
| 579 |
+
]
|
| 580 |
+
|
| 581 |
+
_TORCHAO_OPTIMIZERS = [
|
| 582 |
+
OptimizerNames.ADAMW_TORCH_4BIT,
|
| 583 |
+
OptimizerNames.ADAMW_TORCH_8BIT,
|
| 584 |
+
]
|
| 585 |
+
|
| 586 |
+
_SCHEDULE_FREE_OPTIMIZERS = [
|
| 587 |
+
OptimizerNames.SCHEDULE_FREE_RADAM,
|
| 588 |
+
OptimizerNames.SCHEDULE_FREE_ADAMW,
|
| 589 |
+
OptimizerNames.SCHEDULE_FREE_SGD,
|
| 590 |
+
]
|
| 591 |
+
|
| 592 |
+
# =============================================================================
|
| 593 |
+
# Built-in optimizer handlers registry
|
| 594 |
+
# =============================================================================
|
| 595 |
+
|
| 596 |
+
_OPTIMIZER_HANDLERS: dict[str, OptimizerHandler] = {
|
| 597 |
+
OptimizerNames.ADAFACTOR: _get_adafactor,
|
| 598 |
+
OptimizerNames.ADAMW_TORCH: _get_adamw_torch,
|
| 599 |
+
OptimizerNames.ADAMW_TORCH_FUSED: _get_adamw_torch,
|
| 600 |
+
OptimizerNames.ADAMW_TORCH_XLA: _get_adamw_torch_xla,
|
| 601 |
+
OptimizerNames.ADAMW_TORCH_NPU_FUSED: _get_adamw_torch_npu_fused,
|
| 602 |
+
OptimizerNames.ADAMW_ANYPRECISION: _get_adamw_anyprecision,
|
| 603 |
+
OptimizerNames.SGD: _get_sgd,
|
| 604 |
+
OptimizerNames.ADAGRAD: _get_adagrad,
|
| 605 |
+
OptimizerNames.RMSPROP: _get_rmsprop,
|
| 606 |
+
OptimizerNames.GROKADAMW: _get_grokadamw,
|
| 607 |
+
OptimizerNames.STABLE_ADAMW: _get_stable_adamw,
|
| 608 |
+
OptimizerNames.LOMO: _get_lomo_optimizer,
|
| 609 |
+
OptimizerNames.ADALOMO: _get_lomo_optimizer,
|
| 610 |
+
**dict.fromkeys(_BITSANDBYTES_OPTIMIZERS, _get_bitsandbytes_optimizer),
|
| 611 |
+
**dict.fromkeys(_GALORE_OPTIMIZERS, _get_galore_optimizer),
|
| 612 |
+
**dict.fromkeys(_APOLLO_OPTIMIZERS, _get_apollo_optimizer),
|
| 613 |
+
**dict.fromkeys(_TORCHAO_OPTIMIZERS, _get_torchao_optimizer),
|
| 614 |
+
**dict.fromkeys(_SCHEDULE_FREE_OPTIMIZERS, _get_schedule_free_optimizer),
|
| 615 |
+
}
|