Upload folder using huggingface_hub
Browse files- global_step700/bf16_zero_pp_rank_0_mp_rank_00_optim_states.pt +3 -0
- global_step700/bf16_zero_pp_rank_1_mp_rank_00_optim_states.pt +3 -0
- global_step700/bf16_zero_pp_rank_2_mp_rank_00_optim_states.pt +3 -0
- global_step700/bf16_zero_pp_rank_3_mp_rank_00_optim_states.pt +3 -0
- global_step700/zero_pp_rank_0_mp_rank_00_model_states.pt +3 -0
- global_step700/zero_pp_rank_1_mp_rank_00_model_states.pt +3 -0
- global_step700/zero_pp_rank_2_mp_rank_00_model_states.pt +3 -0
- global_step700/zero_pp_rank_3_mp_rank_00_model_states.pt +3 -0
- latest +1 -0
- rng_state_0.pth +3 -0
- rng_state_1.pth +3 -0
- rng_state_2.pth +3 -0
- rng_state_3.pth +3 -0
- scheduler.pt +3 -0
- trainer_state.json +664 -0
- zero_to_fp32.py +760 -0
global_step700/bf16_zero_pp_rank_0_mp_rank_00_optim_states.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5eeec11714b0fee5900be6302e5949a82d2928c45a552c3d1d6993694e059567
|
| 3 |
+
size 25613049823
|
global_step700/bf16_zero_pp_rank_1_mp_rank_00_optim_states.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d0e89aa7ae75adffe0676555363831ce6ecd7570b59b0963f6477098cb44900a
|
| 3 |
+
size 25613049823
|
global_step700/bf16_zero_pp_rank_2_mp_rank_00_optim_states.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b48ed2174a7b35d02653977a43bc7125ddf9e97e2ee706b365652ad3f12821a9
|
| 3 |
+
size 25613049823
|
global_step700/bf16_zero_pp_rank_3_mp_rank_00_optim_states.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:57df57eb9481893414a1e7e268894871130612875c5c128bf129ec2c1d6a0437
|
| 3 |
+
size 25613049823
|
global_step700/zero_pp_rank_0_mp_rank_00_model_states.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:991a6e32a3f05fd89870c84801e3c5e92452e33006fcd446aef3690ce5e180e0
|
| 3 |
+
size 131199
|
global_step700/zero_pp_rank_1_mp_rank_00_model_states.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:12b7c28a806d3ad014a060e21b2ee3c0bc2c98a0c333792f951585906dd3da32
|
| 3 |
+
size 131135
|
global_step700/zero_pp_rank_2_mp_rank_00_model_states.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:503c0eac64e9948c7a474f4c35247f3a112a6f8daa5f3dcd84caa7729432d04f
|
| 3 |
+
size 131135
|
global_step700/zero_pp_rank_3_mp_rank_00_model_states.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bb23420badf7250a50ee10795d14f55bb1a1cf2f1fe0c4b83bbfea9b065a690a
|
| 3 |
+
size 131135
|
latest
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
global_step700
|
rng_state_0.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:659b1cdee2219458dd84ce6a632a595465680b8080e5c44bd600ff97eca8d752
|
| 3 |
+
size 15429
|
rng_state_1.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:86accf27064cdd503053e90476a6bd10de333d4ff0594535ad55ea13a473c91d
|
| 3 |
+
size 15429
|
rng_state_2.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:18ca8d714ef40be035404c1957b5a4dee84e1f43980408393f8aa710552ee6f6
|
| 3 |
+
size 15429
|
rng_state_3.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2cfdebe99e40accc9c9d8f09c63136a14abda997d9b501969ec8e16e9d183179
|
| 3 |
+
size 15429
|
scheduler.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3f5b0a08026753faf278ef077908a9ba17630202b616bbd23f16e30e79245d6a
|
| 3 |
+
size 1465
|
trainer_state.json
ADDED
|
@@ -0,0 +1,664 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"best_global_step": null,
|
| 3 |
+
"best_metric": null,
|
| 4 |
+
"best_model_checkpoint": null,
|
| 5 |
+
"epoch": 1.0,
|
| 6 |
+
"eval_steps": 500,
|
| 7 |
+
"global_step": 700,
|
| 8 |
+
"is_hyper_param_search": false,
|
| 9 |
+
"is_local_process_zero": true,
|
| 10 |
+
"is_world_process_zero": true,
|
| 11 |
+
"log_history": [
|
| 12 |
+
{
|
| 13 |
+
"epoch": 0.014295925661186561,
|
| 14 |
+
"grad_norm": 16.642337799072266,
|
| 15 |
+
"learning_rate": 1.9742857142857144e-05,
|
| 16 |
+
"loss": 4.2448,
|
| 17 |
+
"mean_token_accuracy": 0.44755197104532274,
|
| 18 |
+
"num_tokens": 63714.0,
|
| 19 |
+
"step": 10
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"epoch": 0.028591851322373123,
|
| 23 |
+
"grad_norm": 12.869135856628418,
|
| 24 |
+
"learning_rate": 1.945714285714286e-05,
|
| 25 |
+
"loss": 1.9287,
|
| 26 |
+
"mean_token_accuracy": 0.5766903940588236,
|
| 27 |
+
"num_tokens": 128528.0,
|
| 28 |
+
"step": 20
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"epoch": 0.04288777698355969,
|
| 32 |
+
"grad_norm": 18.376684188842773,
|
| 33 |
+
"learning_rate": 1.9171428571428573e-05,
|
| 34 |
+
"loss": 1.6956,
|
| 35 |
+
"mean_token_accuracy": 0.597195016592741,
|
| 36 |
+
"num_tokens": 191200.0,
|
| 37 |
+
"step": 30
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"epoch": 0.057183702644746245,
|
| 41 |
+
"grad_norm": 17.71656036376953,
|
| 42 |
+
"learning_rate": 1.888571428571429e-05,
|
| 43 |
+
"loss": 1.6076,
|
| 44 |
+
"mean_token_accuracy": 0.6067132025957107,
|
| 45 |
+
"num_tokens": 255728.0,
|
| 46 |
+
"step": 40
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"epoch": 0.07147962830593281,
|
| 50 |
+
"grad_norm": 21.026283264160156,
|
| 51 |
+
"learning_rate": 1.86e-05,
|
| 52 |
+
"loss": 1.5728,
|
| 53 |
+
"mean_token_accuracy": 0.612850959226489,
|
| 54 |
+
"num_tokens": 319058.0,
|
| 55 |
+
"step": 50
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"epoch": 0.08577555396711938,
|
| 59 |
+
"grad_norm": 46.10198974609375,
|
| 60 |
+
"learning_rate": 1.8314285714285714e-05,
|
| 61 |
+
"loss": 1.5977,
|
| 62 |
+
"mean_token_accuracy": 0.6111391615122557,
|
| 63 |
+
"num_tokens": 384900.0,
|
| 64 |
+
"step": 60
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"epoch": 0.10007147962830593,
|
| 68 |
+
"grad_norm": 14.742942810058594,
|
| 69 |
+
"learning_rate": 1.802857142857143e-05,
|
| 70 |
+
"loss": 1.5649,
|
| 71 |
+
"mean_token_accuracy": 0.6097237385809422,
|
| 72 |
+
"num_tokens": 450346.0,
|
| 73 |
+
"step": 70
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"epoch": 0.11436740528949249,
|
| 77 |
+
"grad_norm": 43.62748718261719,
|
| 78 |
+
"learning_rate": 1.7742857142857143e-05,
|
| 79 |
+
"loss": 1.5184,
|
| 80 |
+
"mean_token_accuracy": 0.6210372049361468,
|
| 81 |
+
"num_tokens": 515018.0,
|
| 82 |
+
"step": 80
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"epoch": 0.12866333095067906,
|
| 86 |
+
"grad_norm": 15.469511032104492,
|
| 87 |
+
"learning_rate": 1.745714285714286e-05,
|
| 88 |
+
"loss": 1.4736,
|
| 89 |
+
"mean_token_accuracy": 0.6270900748670101,
|
| 90 |
+
"num_tokens": 576955.0,
|
| 91 |
+
"step": 90
|
| 92 |
+
},
|
| 93 |
+
{
|
| 94 |
+
"epoch": 0.14295925661186562,
|
| 95 |
+
"grad_norm": 19.448793411254883,
|
| 96 |
+
"learning_rate": 1.717142857142857e-05,
|
| 97 |
+
"loss": 1.4637,
|
| 98 |
+
"mean_token_accuracy": 0.6368957210332156,
|
| 99 |
+
"num_tokens": 641295.0,
|
| 100 |
+
"step": 100
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"epoch": 0.15725518227305219,
|
| 104 |
+
"grad_norm": 37.31778335571289,
|
| 105 |
+
"learning_rate": 1.6885714285714288e-05,
|
| 106 |
+
"loss": 1.5303,
|
| 107 |
+
"mean_token_accuracy": 0.6210926879197359,
|
| 108 |
+
"num_tokens": 706683.0,
|
| 109 |
+
"step": 110
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"epoch": 0.17155110793423875,
|
| 113 |
+
"grad_norm": 9.722342491149902,
|
| 114 |
+
"learning_rate": 1.66e-05,
|
| 115 |
+
"loss": 1.4596,
|
| 116 |
+
"mean_token_accuracy": 0.6298462159931659,
|
| 117 |
+
"num_tokens": 771285.0,
|
| 118 |
+
"step": 120
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
"epoch": 0.18584703359542531,
|
| 122 |
+
"grad_norm": 9.656769752502441,
|
| 123 |
+
"learning_rate": 1.6314285714285716e-05,
|
| 124 |
+
"loss": 1.5281,
|
| 125 |
+
"mean_token_accuracy": 0.6251190695911646,
|
| 126 |
+
"num_tokens": 840678.0,
|
| 127 |
+
"step": 130
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"epoch": 0.20014295925661185,
|
| 131 |
+
"grad_norm": 9.608354568481445,
|
| 132 |
+
"learning_rate": 1.602857142857143e-05,
|
| 133 |
+
"loss": 1.4438,
|
| 134 |
+
"mean_token_accuracy": 0.6370445918291807,
|
| 135 |
+
"num_tokens": 905832.0,
|
| 136 |
+
"step": 140
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"epoch": 0.21443888491779842,
|
| 140 |
+
"grad_norm": 9.842904090881348,
|
| 141 |
+
"learning_rate": 1.5742857142857145e-05,
|
| 142 |
+
"loss": 1.5379,
|
| 143 |
+
"mean_token_accuracy": 0.6172758720815181,
|
| 144 |
+
"num_tokens": 972946.0,
|
| 145 |
+
"step": 150
|
| 146 |
+
},
|
| 147 |
+
{
|
| 148 |
+
"epoch": 0.22873481057898498,
|
| 149 |
+
"grad_norm": 18.17994499206543,
|
| 150 |
+
"learning_rate": 1.545714285714286e-05,
|
| 151 |
+
"loss": 1.4322,
|
| 152 |
+
"mean_token_accuracy": 0.6351331725716591,
|
| 153 |
+
"num_tokens": 1034427.0,
|
| 154 |
+
"step": 160
|
| 155 |
+
},
|
| 156 |
+
{
|
| 157 |
+
"epoch": 0.24303073624017155,
|
| 158 |
+
"grad_norm": 8.876994132995605,
|
| 159 |
+
"learning_rate": 1.5171428571428572e-05,
|
| 160 |
+
"loss": 1.4343,
|
| 161 |
+
"mean_token_accuracy": 0.6313620086759328,
|
| 162 |
+
"num_tokens": 1101359.0,
|
| 163 |
+
"step": 170
|
| 164 |
+
},
|
| 165 |
+
{
|
| 166 |
+
"epoch": 0.2573266619013581,
|
| 167 |
+
"grad_norm": 10.895979881286621,
|
| 168 |
+
"learning_rate": 1.4885714285714288e-05,
|
| 169 |
+
"loss": 1.4537,
|
| 170 |
+
"mean_token_accuracy": 0.633945481479168,
|
| 171 |
+
"num_tokens": 1166538.0,
|
| 172 |
+
"step": 180
|
| 173 |
+
},
|
| 174 |
+
{
|
| 175 |
+
"epoch": 0.27162258756254465,
|
| 176 |
+
"grad_norm": 12.30453872680664,
|
| 177 |
+
"learning_rate": 1.46e-05,
|
| 178 |
+
"loss": 1.5363,
|
| 179 |
+
"mean_token_accuracy": 0.6255367647856473,
|
| 180 |
+
"num_tokens": 1235118.0,
|
| 181 |
+
"step": 190
|
| 182 |
+
},
|
| 183 |
+
{
|
| 184 |
+
"epoch": 0.28591851322373124,
|
| 185 |
+
"grad_norm": 10.28065299987793,
|
| 186 |
+
"learning_rate": 1.4314285714285717e-05,
|
| 187 |
+
"loss": 1.4199,
|
| 188 |
+
"mean_token_accuracy": 0.635765865072608,
|
| 189 |
+
"num_tokens": 1300601.0,
|
| 190 |
+
"step": 200
|
| 191 |
+
},
|
| 192 |
+
{
|
| 193 |
+
"epoch": 0.3002144388849178,
|
| 194 |
+
"grad_norm": 11.893675804138184,
|
| 195 |
+
"learning_rate": 1.402857142857143e-05,
|
| 196 |
+
"loss": 1.3881,
|
| 197 |
+
"mean_token_accuracy": 0.6449477795511485,
|
| 198 |
+
"num_tokens": 1362732.0,
|
| 199 |
+
"step": 210
|
| 200 |
+
},
|
| 201 |
+
{
|
| 202 |
+
"epoch": 0.31451036454610437,
|
| 203 |
+
"grad_norm": 11.485602378845215,
|
| 204 |
+
"learning_rate": 1.3742857142857144e-05,
|
| 205 |
+
"loss": 1.3647,
|
| 206 |
+
"mean_token_accuracy": 0.6486451178789139,
|
| 207 |
+
"num_tokens": 1424780.0,
|
| 208 |
+
"step": 220
|
| 209 |
+
},
|
| 210 |
+
{
|
| 211 |
+
"epoch": 0.3288062902072909,
|
| 212 |
+
"grad_norm": 8.882689476013184,
|
| 213 |
+
"learning_rate": 1.3457142857142858e-05,
|
| 214 |
+
"loss": 1.3915,
|
| 215 |
+
"mean_token_accuracy": 0.6436454936861992,
|
| 216 |
+
"num_tokens": 1490808.0,
|
| 217 |
+
"step": 230
|
| 218 |
+
},
|
| 219 |
+
{
|
| 220 |
+
"epoch": 0.3431022158684775,
|
| 221 |
+
"grad_norm": 18.272981643676758,
|
| 222 |
+
"learning_rate": 1.3171428571428573e-05,
|
| 223 |
+
"loss": 1.4796,
|
| 224 |
+
"mean_token_accuracy": 0.6283955980092287,
|
| 225 |
+
"num_tokens": 1556933.0,
|
| 226 |
+
"step": 240
|
| 227 |
+
},
|
| 228 |
+
{
|
| 229 |
+
"epoch": 0.35739814152966404,
|
| 230 |
+
"grad_norm": 11.947668075561523,
|
| 231 |
+
"learning_rate": 1.2885714285714285e-05,
|
| 232 |
+
"loss": 1.4398,
|
| 233 |
+
"mean_token_accuracy": 0.638329004868865,
|
| 234 |
+
"num_tokens": 1621053.0,
|
| 235 |
+
"step": 250
|
| 236 |
+
},
|
| 237 |
+
{
|
| 238 |
+
"epoch": 0.37169406719085063,
|
| 239 |
+
"grad_norm": 23.547773361206055,
|
| 240 |
+
"learning_rate": 1.2600000000000001e-05,
|
| 241 |
+
"loss": 1.3801,
|
| 242 |
+
"mean_token_accuracy": 0.6448216594755649,
|
| 243 |
+
"num_tokens": 1686747.0,
|
| 244 |
+
"step": 260
|
| 245 |
+
},
|
| 246 |
+
{
|
| 247 |
+
"epoch": 0.38598999285203717,
|
| 248 |
+
"grad_norm": 16.82425880432129,
|
| 249 |
+
"learning_rate": 1.2314285714285716e-05,
|
| 250 |
+
"loss": 1.3891,
|
| 251 |
+
"mean_token_accuracy": 0.6475608512759209,
|
| 252 |
+
"num_tokens": 1751946.0,
|
| 253 |
+
"step": 270
|
| 254 |
+
},
|
| 255 |
+
{
|
| 256 |
+
"epoch": 0.4002859185132237,
|
| 257 |
+
"grad_norm": 11.931357383728027,
|
| 258 |
+
"learning_rate": 1.202857142857143e-05,
|
| 259 |
+
"loss": 1.3768,
|
| 260 |
+
"mean_token_accuracy": 0.6439446356147528,
|
| 261 |
+
"num_tokens": 1816123.0,
|
| 262 |
+
"step": 280
|
| 263 |
+
},
|
| 264 |
+
{
|
| 265 |
+
"epoch": 0.4145818441744103,
|
| 266 |
+
"grad_norm": 14.375319480895996,
|
| 267 |
+
"learning_rate": 1.1742857142857144e-05,
|
| 268 |
+
"loss": 1.315,
|
| 269 |
+
"mean_token_accuracy": 0.6517576463520527,
|
| 270 |
+
"num_tokens": 1879227.0,
|
| 271 |
+
"step": 290
|
| 272 |
+
},
|
| 273 |
+
{
|
| 274 |
+
"epoch": 0.42887776983559683,
|
| 275 |
+
"grad_norm": 10.699817657470703,
|
| 276 |
+
"learning_rate": 1.1457142857142857e-05,
|
| 277 |
+
"loss": 1.3519,
|
| 278 |
+
"mean_token_accuracy": 0.6487406313419342,
|
| 279 |
+
"num_tokens": 1944238.0,
|
| 280 |
+
"step": 300
|
| 281 |
+
},
|
| 282 |
+
{
|
| 283 |
+
"epoch": 0.4431736954967834,
|
| 284 |
+
"grad_norm": 12.067941665649414,
|
| 285 |
+
"learning_rate": 1.1171428571428573e-05,
|
| 286 |
+
"loss": 1.2784,
|
| 287 |
+
"mean_token_accuracy": 0.6627866499125957,
|
| 288 |
+
"num_tokens": 2007629.0,
|
| 289 |
+
"step": 310
|
| 290 |
+
},
|
| 291 |
+
{
|
| 292 |
+
"epoch": 0.45746962115796996,
|
| 293 |
+
"grad_norm": 15.550559997558594,
|
| 294 |
+
"learning_rate": 1.0885714285714286e-05,
|
| 295 |
+
"loss": 1.3495,
|
| 296 |
+
"mean_token_accuracy": 0.6514371998608113,
|
| 297 |
+
"num_tokens": 2076666.0,
|
| 298 |
+
"step": 320
|
| 299 |
+
},
|
| 300 |
+
{
|
| 301 |
+
"epoch": 0.47176554681915656,
|
| 302 |
+
"grad_norm": 30.000173568725586,
|
| 303 |
+
"learning_rate": 1.0600000000000002e-05,
|
| 304 |
+
"loss": 1.3358,
|
| 305 |
+
"mean_token_accuracy": 0.6507035464048385,
|
| 306 |
+
"num_tokens": 2140860.0,
|
| 307 |
+
"step": 330
|
| 308 |
+
},
|
| 309 |
+
{
|
| 310 |
+
"epoch": 0.4860614724803431,
|
| 311 |
+
"grad_norm": 7.962319850921631,
|
| 312 |
+
"learning_rate": 1.0314285714285715e-05,
|
| 313 |
+
"loss": 1.3231,
|
| 314 |
+
"mean_token_accuracy": 0.6570919144898653,
|
| 315 |
+
"num_tokens": 2204773.0,
|
| 316 |
+
"step": 340
|
| 317 |
+
},
|
| 318 |
+
{
|
| 319 |
+
"epoch": 0.5003573981415297,
|
| 320 |
+
"grad_norm": 24.023008346557617,
|
| 321 |
+
"learning_rate": 1.002857142857143e-05,
|
| 322 |
+
"loss": 1.3936,
|
| 323 |
+
"mean_token_accuracy": 0.6455658808350563,
|
| 324 |
+
"num_tokens": 2270923.0,
|
| 325 |
+
"step": 350
|
| 326 |
+
},
|
| 327 |
+
{
|
| 328 |
+
"epoch": 0.5146533238027162,
|
| 329 |
+
"grad_norm": 8.74783706665039,
|
| 330 |
+
"learning_rate": 9.742857142857143e-06,
|
| 331 |
+
"loss": 1.3383,
|
| 332 |
+
"mean_token_accuracy": 0.6552599217742682,
|
| 333 |
+
"num_tokens": 2337009.0,
|
| 334 |
+
"step": 360
|
| 335 |
+
},
|
| 336 |
+
{
|
| 337 |
+
"epoch": 0.5289492494639028,
|
| 338 |
+
"grad_norm": 17.01344108581543,
|
| 339 |
+
"learning_rate": 9.457142857142858e-06,
|
| 340 |
+
"loss": 1.3524,
|
| 341 |
+
"mean_token_accuracy": 0.6488417606800795,
|
| 342 |
+
"num_tokens": 2405973.0,
|
| 343 |
+
"step": 370
|
| 344 |
+
},
|
| 345 |
+
{
|
| 346 |
+
"epoch": 0.5432451751250893,
|
| 347 |
+
"grad_norm": 9.353411674499512,
|
| 348 |
+
"learning_rate": 9.171428571428572e-06,
|
| 349 |
+
"loss": 1.2638,
|
| 350 |
+
"mean_token_accuracy": 0.6636200629174709,
|
| 351 |
+
"num_tokens": 2469824.0,
|
| 352 |
+
"step": 380
|
| 353 |
+
},
|
| 354 |
+
{
|
| 355 |
+
"epoch": 0.557541100786276,
|
| 356 |
+
"grad_norm": 13.265799522399902,
|
| 357 |
+
"learning_rate": 8.885714285714286e-06,
|
| 358 |
+
"loss": 1.2254,
|
| 359 |
+
"mean_token_accuracy": 0.6689145911484957,
|
| 360 |
+
"num_tokens": 2535167.0,
|
| 361 |
+
"step": 390
|
| 362 |
+
},
|
| 363 |
+
{
|
| 364 |
+
"epoch": 0.5718370264474625,
|
| 365 |
+
"grad_norm": 19.46824836730957,
|
| 366 |
+
"learning_rate": 8.6e-06,
|
| 367 |
+
"loss": 1.3844,
|
| 368 |
+
"mean_token_accuracy": 0.6483918268233537,
|
| 369 |
+
"num_tokens": 2607759.0,
|
| 370 |
+
"step": 400
|
| 371 |
+
},
|
| 372 |
+
{
|
| 373 |
+
"epoch": 0.586132952108649,
|
| 374 |
+
"grad_norm": 15.773782730102539,
|
| 375 |
+
"learning_rate": 8.314285714285715e-06,
|
| 376 |
+
"loss": 1.2708,
|
| 377 |
+
"mean_token_accuracy": 0.6655503377318382,
|
| 378 |
+
"num_tokens": 2670580.0,
|
| 379 |
+
"step": 410
|
| 380 |
+
},
|
| 381 |
+
{
|
| 382 |
+
"epoch": 0.6004288777698356,
|
| 383 |
+
"grad_norm": 8.917901039123535,
|
| 384 |
+
"learning_rate": 8.02857142857143e-06,
|
| 385 |
+
"loss": 1.2726,
|
| 386 |
+
"mean_token_accuracy": 0.6589578501880169,
|
| 387 |
+
"num_tokens": 2737272.0,
|
| 388 |
+
"step": 420
|
| 389 |
+
},
|
| 390 |
+
{
|
| 391 |
+
"epoch": 0.6147248034310222,
|
| 392 |
+
"grad_norm": 8.988587379455566,
|
| 393 |
+
"learning_rate": 7.742857142857144e-06,
|
| 394 |
+
"loss": 1.221,
|
| 395 |
+
"mean_token_accuracy": 0.664219357818365,
|
| 396 |
+
"num_tokens": 2803875.0,
|
| 397 |
+
"step": 430
|
| 398 |
+
},
|
| 399 |
+
{
|
| 400 |
+
"epoch": 0.6290207290922087,
|
| 401 |
+
"grad_norm": 12.661059379577637,
|
| 402 |
+
"learning_rate": 7.457142857142857e-06,
|
| 403 |
+
"loss": 1.2658,
|
| 404 |
+
"mean_token_accuracy": 0.662236025184393,
|
| 405 |
+
"num_tokens": 2869457.0,
|
| 406 |
+
"step": 440
|
| 407 |
+
},
|
| 408 |
+
{
|
| 409 |
+
"epoch": 0.6433166547533953,
|
| 410 |
+
"grad_norm": 8.545147895812988,
|
| 411 |
+
"learning_rate": 7.1714285714285725e-06,
|
| 412 |
+
"loss": 1.2778,
|
| 413 |
+
"mean_token_accuracy": 0.6622273363173008,
|
| 414 |
+
"num_tokens": 2931790.0,
|
| 415 |
+
"step": 450
|
| 416 |
+
},
|
| 417 |
+
{
|
| 418 |
+
"epoch": 0.6576125804145818,
|
| 419 |
+
"grad_norm": 20.769514083862305,
|
| 420 |
+
"learning_rate": 6.885714285714287e-06,
|
| 421 |
+
"loss": 1.2951,
|
| 422 |
+
"mean_token_accuracy": 0.6606701787561178,
|
| 423 |
+
"num_tokens": 2997229.0,
|
| 424 |
+
"step": 460
|
| 425 |
+
},
|
| 426 |
+
{
|
| 427 |
+
"epoch": 0.6719085060757684,
|
| 428 |
+
"grad_norm": 12.466110229492188,
|
| 429 |
+
"learning_rate": 6.600000000000001e-06,
|
| 430 |
+
"loss": 1.1754,
|
| 431 |
+
"mean_token_accuracy": 0.6822692640125751,
|
| 432 |
+
"num_tokens": 3063485.0,
|
| 433 |
+
"step": 470
|
| 434 |
+
},
|
| 435 |
+
{
|
| 436 |
+
"epoch": 0.686204431736955,
|
| 437 |
+
"grad_norm": 8.45051383972168,
|
| 438 |
+
"learning_rate": 6.314285714285715e-06,
|
| 439 |
+
"loss": 1.2102,
|
| 440 |
+
"mean_token_accuracy": 0.6759132348001003,
|
| 441 |
+
"num_tokens": 3127984.0,
|
| 442 |
+
"step": 480
|
| 443 |
+
},
|
| 444 |
+
{
|
| 445 |
+
"epoch": 0.7005003573981415,
|
| 446 |
+
"grad_norm": 12.029594421386719,
|
| 447 |
+
"learning_rate": 6.028571428571429e-06,
|
| 448 |
+
"loss": 1.3355,
|
| 449 |
+
"mean_token_accuracy": 0.6649406619369984,
|
| 450 |
+
"num_tokens": 3194219.0,
|
| 451 |
+
"step": 490
|
| 452 |
+
},
|
| 453 |
+
{
|
| 454 |
+
"epoch": 0.7147962830593281,
|
| 455 |
+
"grad_norm": 8.824553489685059,
|
| 456 |
+
"learning_rate": 5.742857142857143e-06,
|
| 457 |
+
"loss": 1.2317,
|
| 458 |
+
"mean_token_accuracy": 0.6705160938203335,
|
| 459 |
+
"num_tokens": 3259068.0,
|
| 460 |
+
"step": 500
|
| 461 |
+
},
|
| 462 |
+
{
|
| 463 |
+
"epoch": 0.7290922087205146,
|
| 464 |
+
"grad_norm": 16.150766372680664,
|
| 465 |
+
"learning_rate": 5.457142857142858e-06,
|
| 466 |
+
"loss": 1.1558,
|
| 467 |
+
"mean_token_accuracy": 0.6850677601993084,
|
| 468 |
+
"num_tokens": 3324070.0,
|
| 469 |
+
"step": 510
|
| 470 |
+
},
|
| 471 |
+
{
|
| 472 |
+
"epoch": 0.7433881343817013,
|
| 473 |
+
"grad_norm": 7.721499919891357,
|
| 474 |
+
"learning_rate": 5.171428571428571e-06,
|
| 475 |
+
"loss": 1.168,
|
| 476 |
+
"mean_token_accuracy": 0.6747931383550168,
|
| 477 |
+
"num_tokens": 3386885.0,
|
| 478 |
+
"step": 520
|
| 479 |
+
},
|
| 480 |
+
{
|
| 481 |
+
"epoch": 0.7576840600428878,
|
| 482 |
+
"grad_norm": 9.311972618103027,
|
| 483 |
+
"learning_rate": 4.885714285714286e-06,
|
| 484 |
+
"loss": 1.1645,
|
| 485 |
+
"mean_token_accuracy": 0.6775478422641754,
|
| 486 |
+
"num_tokens": 3448602.0,
|
| 487 |
+
"step": 530
|
| 488 |
+
},
|
| 489 |
+
{
|
| 490 |
+
"epoch": 0.7719799857040743,
|
| 491 |
+
"grad_norm": 9.636552810668945,
|
| 492 |
+
"learning_rate": 4.600000000000001e-06,
|
| 493 |
+
"loss": 1.2542,
|
| 494 |
+
"mean_token_accuracy": 0.6680241461843253,
|
| 495 |
+
"num_tokens": 3516481.0,
|
| 496 |
+
"step": 540
|
| 497 |
+
},
|
| 498 |
+
{
|
| 499 |
+
"epoch": 0.7862759113652609,
|
| 500 |
+
"grad_norm": 36.31599044799805,
|
| 501 |
+
"learning_rate": 4.314285714285714e-06,
|
| 502 |
+
"loss": 1.1866,
|
| 503 |
+
"mean_token_accuracy": 0.6768352195620537,
|
| 504 |
+
"num_tokens": 3580217.0,
|
| 505 |
+
"step": 550
|
| 506 |
+
},
|
| 507 |
+
{
|
| 508 |
+
"epoch": 0.8005718370264474,
|
| 509 |
+
"grad_norm": 7.471230506896973,
|
| 510 |
+
"learning_rate": 4.028571428571429e-06,
|
| 511 |
+
"loss": 1.1705,
|
| 512 |
+
"mean_token_accuracy": 0.6818295098841191,
|
| 513 |
+
"num_tokens": 3643021.0,
|
| 514 |
+
"step": 560
|
| 515 |
+
},
|
| 516 |
+
{
|
| 517 |
+
"epoch": 0.8148677626876341,
|
| 518 |
+
"grad_norm": 48.099830627441406,
|
| 519 |
+
"learning_rate": 3.742857142857143e-06,
|
| 520 |
+
"loss": 1.1602,
|
| 521 |
+
"mean_token_accuracy": 0.6852999441325665,
|
| 522 |
+
"num_tokens": 3710116.0,
|
| 523 |
+
"step": 570
|
| 524 |
+
},
|
| 525 |
+
{
|
| 526 |
+
"epoch": 0.8291636883488206,
|
| 527 |
+
"grad_norm": 13.096914291381836,
|
| 528 |
+
"learning_rate": 3.4571428571428574e-06,
|
| 529 |
+
"loss": 1.1942,
|
| 530 |
+
"mean_token_accuracy": 0.6752621583640576,
|
| 531 |
+
"num_tokens": 3775926.0,
|
| 532 |
+
"step": 580
|
| 533 |
+
},
|
| 534 |
+
{
|
| 535 |
+
"epoch": 0.8434596140100071,
|
| 536 |
+
"grad_norm": 11.580378532409668,
|
| 537 |
+
"learning_rate": 3.1714285714285714e-06,
|
| 538 |
+
"loss": 1.1277,
|
| 539 |
+
"mean_token_accuracy": 0.6849311918020249,
|
| 540 |
+
"num_tokens": 3840218.0,
|
| 541 |
+
"step": 590
|
| 542 |
+
},
|
| 543 |
+
{
|
| 544 |
+
"epoch": 0.8577555396711937,
|
| 545 |
+
"grad_norm": 9.58252239227295,
|
| 546 |
+
"learning_rate": 2.885714285714286e-06,
|
| 547 |
+
"loss": 1.187,
|
| 548 |
+
"mean_token_accuracy": 0.6740429483354091,
|
| 549 |
+
"num_tokens": 3904300.0,
|
| 550 |
+
"step": 600
|
| 551 |
+
},
|
| 552 |
+
{
|
| 553 |
+
"epoch": 0.8720514653323803,
|
| 554 |
+
"grad_norm": 9.778560638427734,
|
| 555 |
+
"learning_rate": 2.6e-06,
|
| 556 |
+
"loss": 1.2088,
|
| 557 |
+
"mean_token_accuracy": 0.6759266927838326,
|
| 558 |
+
"num_tokens": 3970409.0,
|
| 559 |
+
"step": 610
|
| 560 |
+
},
|
| 561 |
+
{
|
| 562 |
+
"epoch": 0.8863473909935669,
|
| 563 |
+
"grad_norm": 9.931038856506348,
|
| 564 |
+
"learning_rate": 2.3142857142857145e-06,
|
| 565 |
+
"loss": 1.1766,
|
| 566 |
+
"mean_token_accuracy": 0.6766778022050858,
|
| 567 |
+
"num_tokens": 4038742.0,
|
| 568 |
+
"step": 620
|
| 569 |
+
},
|
| 570 |
+
{
|
| 571 |
+
"epoch": 0.9006433166547534,
|
| 572 |
+
"grad_norm": 7.126023769378662,
|
| 573 |
+
"learning_rate": 2.028571428571429e-06,
|
| 574 |
+
"loss": 1.0968,
|
| 575 |
+
"mean_token_accuracy": 0.6913008309900761,
|
| 576 |
+
"num_tokens": 4103374.0,
|
| 577 |
+
"step": 630
|
| 578 |
+
},
|
| 579 |
+
{
|
| 580 |
+
"epoch": 0.9149392423159399,
|
| 581 |
+
"grad_norm": 7.73612642288208,
|
| 582 |
+
"learning_rate": 1.7428571428571432e-06,
|
| 583 |
+
"loss": 1.1254,
|
| 584 |
+
"mean_token_accuracy": 0.6863209947943687,
|
| 585 |
+
"num_tokens": 4170239.0,
|
| 586 |
+
"step": 640
|
| 587 |
+
},
|
| 588 |
+
{
|
| 589 |
+
"epoch": 0.9292351679771265,
|
| 590 |
+
"grad_norm": 6.532904148101807,
|
| 591 |
+
"learning_rate": 1.4571428571428573e-06,
|
| 592 |
+
"loss": 1.1586,
|
| 593 |
+
"mean_token_accuracy": 0.6804635964334012,
|
| 594 |
+
"num_tokens": 4237810.0,
|
| 595 |
+
"step": 650
|
| 596 |
+
},
|
| 597 |
+
{
|
| 598 |
+
"epoch": 0.9435310936383131,
|
| 599 |
+
"grad_norm": 7.370081901550293,
|
| 600 |
+
"learning_rate": 1.1714285714285715e-06,
|
| 601 |
+
"loss": 1.174,
|
| 602 |
+
"mean_token_accuracy": 0.6809860028326511,
|
| 603 |
+
"num_tokens": 4302937.0,
|
| 604 |
+
"step": 660
|
| 605 |
+
},
|
| 606 |
+
{
|
| 607 |
+
"epoch": 0.9578270192994996,
|
| 608 |
+
"grad_norm": 7.471885681152344,
|
| 609 |
+
"learning_rate": 8.857142857142857e-07,
|
| 610 |
+
"loss": 1.1755,
|
| 611 |
+
"mean_token_accuracy": 0.6858656518161297,
|
| 612 |
+
"num_tokens": 4368704.0,
|
| 613 |
+
"step": 670
|
| 614 |
+
},
|
| 615 |
+
{
|
| 616 |
+
"epoch": 0.9721229449606862,
|
| 617 |
+
"grad_norm": 9.739863395690918,
|
| 618 |
+
"learning_rate": 6.000000000000001e-07,
|
| 619 |
+
"loss": 1.1052,
|
| 620 |
+
"mean_token_accuracy": 0.6904201626777648,
|
| 621 |
+
"num_tokens": 4431384.0,
|
| 622 |
+
"step": 680
|
| 623 |
+
},
|
| 624 |
+
{
|
| 625 |
+
"epoch": 0.9864188706218727,
|
| 626 |
+
"grad_norm": 11.182050704956055,
|
| 627 |
+
"learning_rate": 3.1428571428571433e-07,
|
| 628 |
+
"loss": 1.1422,
|
| 629 |
+
"mean_token_accuracy": 0.688240597397089,
|
| 630 |
+
"num_tokens": 4500182.0,
|
| 631 |
+
"step": 690
|
| 632 |
+
},
|
| 633 |
+
{
|
| 634 |
+
"epoch": 1.0,
|
| 635 |
+
"grad_norm": 11.066879272460938,
|
| 636 |
+
"learning_rate": 2.8571428571428575e-08,
|
| 637 |
+
"loss": 1.131,
|
| 638 |
+
"mean_token_accuracy": 0.6868848518321389,
|
| 639 |
+
"num_tokens": 4559091.0,
|
| 640 |
+
"step": 700
|
| 641 |
+
}
|
| 642 |
+
],
|
| 643 |
+
"logging_steps": 10,
|
| 644 |
+
"max_steps": 700,
|
| 645 |
+
"num_input_tokens_seen": 0,
|
| 646 |
+
"num_train_epochs": 1,
|
| 647 |
+
"save_steps": 500,
|
| 648 |
+
"stateful_callbacks": {
|
| 649 |
+
"TrainerControl": {
|
| 650 |
+
"args": {
|
| 651 |
+
"should_epoch_stop": false,
|
| 652 |
+
"should_evaluate": false,
|
| 653 |
+
"should_log": false,
|
| 654 |
+
"should_save": true,
|
| 655 |
+
"should_training_stop": true
|
| 656 |
+
},
|
| 657 |
+
"attributes": {}
|
| 658 |
+
}
|
| 659 |
+
},
|
| 660 |
+
"total_flos": 4791381278720.0,
|
| 661 |
+
"train_batch_size": 1,
|
| 662 |
+
"trial_name": null,
|
| 663 |
+
"trial_params": null
|
| 664 |
+
}
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
|
| 3 |
+
# Copyright (c) Microsoft Corporation.
|
| 4 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
|
| 6 |
+
# DeepSpeed Team
|
| 7 |
+
|
| 8 |
+
# This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets
|
| 9 |
+
# copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
|
| 10 |
+
# the future. Once extracted, the weights don't require DeepSpeed and can be used in any
|
| 11 |
+
# application.
|
| 12 |
+
#
|
| 13 |
+
# example:
|
| 14 |
+
# python zero_to_fp32.py . output_dir/
|
| 15 |
+
# or
|
| 16 |
+
# python zero_to_fp32.py . output_dir/ --safe_serialization
|
| 17 |
+
|
| 18 |
+
import argparse
|
| 19 |
+
import torch
|
| 20 |
+
import glob
|
| 21 |
+
import math
|
| 22 |
+
import os
|
| 23 |
+
import re
|
| 24 |
+
import gc
|
| 25 |
+
import json
|
| 26 |
+
import numpy as np
|
| 27 |
+
from tqdm import tqdm
|
| 28 |
+
from collections import OrderedDict
|
| 29 |
+
from dataclasses import dataclass
|
| 30 |
+
|
| 31 |
+
# while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
|
| 32 |
+
# DeepSpeed data structures it has to be available in the current python environment.
|
| 33 |
+
from deepspeed.utils import logger
|
| 34 |
+
from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
|
| 35 |
+
FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
|
| 36 |
+
FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
@dataclass
|
| 40 |
+
class zero_model_state:
|
| 41 |
+
buffers: dict()
|
| 42 |
+
param_shapes: dict()
|
| 43 |
+
shared_params: list
|
| 44 |
+
ds_version: int
|
| 45 |
+
frozen_param_shapes: dict()
|
| 46 |
+
frozen_param_fragments: dict()
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
debug = 0
|
| 50 |
+
|
| 51 |
+
# load to cpu
|
| 52 |
+
device = torch.device('cpu')
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def atoi(text):
|
| 56 |
+
return int(text) if text.isdigit() else text
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def natural_keys(text):
|
| 60 |
+
'''
|
| 61 |
+
alist.sort(key=natural_keys) sorts in human order
|
| 62 |
+
http://nedbatchelder.com/blog/200712/human_sorting.html
|
| 63 |
+
(See Toothy's implementation in the comments)
|
| 64 |
+
'''
|
| 65 |
+
return [atoi(c) for c in re.split(r'(\d+)', text)]
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def get_model_state_file(checkpoint_dir, zero_stage):
|
| 69 |
+
if not os.path.isdir(checkpoint_dir):
|
| 70 |
+
raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
|
| 71 |
+
|
| 72 |
+
# there should be only one file
|
| 73 |
+
if zero_stage <= 2:
|
| 74 |
+
file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
|
| 75 |
+
elif zero_stage == 3:
|
| 76 |
+
file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
|
| 77 |
+
|
| 78 |
+
if not os.path.exists(file):
|
| 79 |
+
raise FileNotFoundError(f"can't find model states file at '{file}'")
|
| 80 |
+
|
| 81 |
+
return file
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def get_checkpoint_files(checkpoint_dir, glob_pattern):
|
| 85 |
+
# XXX: need to test that this simple glob rule works for multi-node setup too
|
| 86 |
+
ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
|
| 87 |
+
|
| 88 |
+
if len(ckpt_files) == 0:
|
| 89 |
+
raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
|
| 90 |
+
|
| 91 |
+
return ckpt_files
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def get_optim_files(checkpoint_dir):
|
| 95 |
+
return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def get_model_state_files(checkpoint_dir):
|
| 99 |
+
return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def parse_model_states(files):
|
| 103 |
+
zero_model_states = []
|
| 104 |
+
for file in files:
|
| 105 |
+
state_dict = torch.load(file, map_location=device, weights_only=False)
|
| 106 |
+
|
| 107 |
+
if BUFFER_NAMES not in state_dict:
|
| 108 |
+
raise ValueError(f"{file} is not a model state checkpoint")
|
| 109 |
+
buffer_names = state_dict[BUFFER_NAMES]
|
| 110 |
+
if debug:
|
| 111 |
+
print("Found buffers:", buffer_names)
|
| 112 |
+
|
| 113 |
+
# recover just the buffers while restoring them to fp32 if they were saved in fp16
|
| 114 |
+
buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
|
| 115 |
+
param_shapes = state_dict[PARAM_SHAPES]
|
| 116 |
+
|
| 117 |
+
# collect parameters that are included in param_shapes
|
| 118 |
+
param_names = []
|
| 119 |
+
for s in param_shapes:
|
| 120 |
+
for name in s.keys():
|
| 121 |
+
param_names.append(name)
|
| 122 |
+
|
| 123 |
+
# update with frozen parameters
|
| 124 |
+
frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
|
| 125 |
+
if frozen_param_shapes is not None:
|
| 126 |
+
if debug:
|
| 127 |
+
print(f"Found frozen_param_shapes: {frozen_param_shapes}")
|
| 128 |
+
param_names += list(frozen_param_shapes.keys())
|
| 129 |
+
|
| 130 |
+
# handle shared params
|
| 131 |
+
shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
|
| 132 |
+
|
| 133 |
+
ds_version = state_dict.get(DS_VERSION, None)
|
| 134 |
+
|
| 135 |
+
frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
|
| 136 |
+
|
| 137 |
+
z_model_state = zero_model_state(buffers=buffers,
|
| 138 |
+
param_shapes=param_shapes,
|
| 139 |
+
shared_params=shared_params,
|
| 140 |
+
ds_version=ds_version,
|
| 141 |
+
frozen_param_shapes=frozen_param_shapes,
|
| 142 |
+
frozen_param_fragments=frozen_param_fragments)
|
| 143 |
+
zero_model_states.append(z_model_state)
|
| 144 |
+
|
| 145 |
+
return zero_model_states
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def parse_optim_states(files, ds_checkpoint_dir):
|
| 149 |
+
total_files = len(files)
|
| 150 |
+
state_dicts = []
|
| 151 |
+
for f in tqdm(files, desc='Loading checkpoint shards'):
|
| 152 |
+
state_dict = torch.load(f, map_location=device, mmap=True, weights_only=False)
|
| 153 |
+
# immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
|
| 154 |
+
# and also handle the case where it was already removed by another helper script
|
| 155 |
+
state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
|
| 156 |
+
state_dicts.append(state_dict)
|
| 157 |
+
|
| 158 |
+
if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
|
| 159 |
+
raise ValueError(f"{files[0]} is not a zero checkpoint")
|
| 160 |
+
zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
|
| 161 |
+
world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
|
| 162 |
+
|
| 163 |
+
# For ZeRO-2 each param group can have different partition_count as data parallelism for expert
|
| 164 |
+
# parameters can be different from data parallelism for non-expert parameters. So we can just
|
| 165 |
+
# use the max of the partition_count to get the dp world_size.
|
| 166 |
+
|
| 167 |
+
if type(world_size) is list:
|
| 168 |
+
world_size = max(world_size)
|
| 169 |
+
|
| 170 |
+
if world_size != total_files:
|
| 171 |
+
raise ValueError(
|
| 172 |
+
f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
|
| 173 |
+
"Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
# the groups are named differently in each stage
|
| 177 |
+
if zero_stage <= 2:
|
| 178 |
+
fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
|
| 179 |
+
elif zero_stage == 3:
|
| 180 |
+
fp32_groups_key = FP32_FLAT_GROUPS
|
| 181 |
+
else:
|
| 182 |
+
raise ValueError(f"unknown zero stage {zero_stage}")
|
| 183 |
+
|
| 184 |
+
fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
|
| 185 |
+
return zero_stage, world_size, fp32_flat_groups
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters):
|
| 189 |
+
"""
|
| 190 |
+
Returns fp32 state_dict reconstructed from ds checkpoint
|
| 191 |
+
|
| 192 |
+
Args:
|
| 193 |
+
- ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
|
| 194 |
+
|
| 195 |
+
"""
|
| 196 |
+
print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
|
| 197 |
+
|
| 198 |
+
optim_files = get_optim_files(ds_checkpoint_dir)
|
| 199 |
+
zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
|
| 200 |
+
print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
|
| 201 |
+
|
| 202 |
+
model_files = get_model_state_files(ds_checkpoint_dir)
|
| 203 |
+
|
| 204 |
+
zero_model_states = parse_model_states(model_files)
|
| 205 |
+
print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
|
| 206 |
+
|
| 207 |
+
if zero_stage <= 2:
|
| 208 |
+
return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
|
| 209 |
+
exclude_frozen_parameters)
|
| 210 |
+
elif zero_stage == 3:
|
| 211 |
+
return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
|
| 212 |
+
exclude_frozen_parameters)
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def _zero2_merge_frozen_params(state_dict, zero_model_states):
|
| 216 |
+
if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
|
| 217 |
+
return
|
| 218 |
+
|
| 219 |
+
frozen_param_shapes = zero_model_states[0].frozen_param_shapes
|
| 220 |
+
frozen_param_fragments = zero_model_states[0].frozen_param_fragments
|
| 221 |
+
|
| 222 |
+
if debug:
|
| 223 |
+
num_elem = sum(s.numel() for s in frozen_param_shapes.values())
|
| 224 |
+
print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
|
| 225 |
+
|
| 226 |
+
wanted_params = len(frozen_param_shapes)
|
| 227 |
+
wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
|
| 228 |
+
avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
|
| 229 |
+
print(f'Frozen params: Have {avail_numel} numels to process.')
|
| 230 |
+
print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
|
| 231 |
+
|
| 232 |
+
total_params = 0
|
| 233 |
+
total_numel = 0
|
| 234 |
+
for name, shape in frozen_param_shapes.items():
|
| 235 |
+
total_params += 1
|
| 236 |
+
unpartitioned_numel = shape.numel()
|
| 237 |
+
total_numel += unpartitioned_numel
|
| 238 |
+
|
| 239 |
+
state_dict[name] = frozen_param_fragments[name]
|
| 240 |
+
|
| 241 |
+
if debug:
|
| 242 |
+
print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
|
| 243 |
+
|
| 244 |
+
print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def _has_callable(obj, fn):
|
| 248 |
+
attr = getattr(obj, fn, None)
|
| 249 |
+
return callable(attr)
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
|
| 253 |
+
param_shapes = zero_model_states[0].param_shapes
|
| 254 |
+
|
| 255 |
+
# Reconstruction protocol:
|
| 256 |
+
#
|
| 257 |
+
# XXX: document this
|
| 258 |
+
|
| 259 |
+
if debug:
|
| 260 |
+
for i in range(world_size):
|
| 261 |
+
for j in range(len(fp32_flat_groups[0])):
|
| 262 |
+
print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
|
| 263 |
+
|
| 264 |
+
# XXX: memory usage doubles here (zero2)
|
| 265 |
+
num_param_groups = len(fp32_flat_groups[0])
|
| 266 |
+
merged_single_partition_of_fp32_groups = []
|
| 267 |
+
for i in range(num_param_groups):
|
| 268 |
+
merged_partitions = [sd[i] for sd in fp32_flat_groups]
|
| 269 |
+
full_single_fp32_vector = torch.cat(merged_partitions, 0)
|
| 270 |
+
merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
|
| 271 |
+
avail_numel = sum(
|
| 272 |
+
[full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
|
| 273 |
+
|
| 274 |
+
if debug:
|
| 275 |
+
wanted_params = sum([len(shapes) for shapes in param_shapes])
|
| 276 |
+
wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
|
| 277 |
+
# not asserting if there is a mismatch due to possible padding
|
| 278 |
+
print(f"Have {avail_numel} numels to process.")
|
| 279 |
+
print(f"Need {wanted_numel} numels in {wanted_params} params.")
|
| 280 |
+
|
| 281 |
+
# params
|
| 282 |
+
# XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
|
| 283 |
+
# out-of-core computing solution
|
| 284 |
+
total_numel = 0
|
| 285 |
+
total_params = 0
|
| 286 |
+
for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
|
| 287 |
+
offset = 0
|
| 288 |
+
avail_numel = full_single_fp32_vector.numel()
|
| 289 |
+
for name, shape in shapes.items():
|
| 290 |
+
|
| 291 |
+
unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
|
| 292 |
+
total_numel += unpartitioned_numel
|
| 293 |
+
total_params += 1
|
| 294 |
+
|
| 295 |
+
if debug:
|
| 296 |
+
print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
|
| 297 |
+
state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
|
| 298 |
+
offset += unpartitioned_numel
|
| 299 |
+
|
| 300 |
+
# Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
|
| 301 |
+
# avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
|
| 302 |
+
# paddings performed in the code it's almost impossible to predict the exact numbers w/o the
|
| 303 |
+
# live optimizer object, so we are checking that the numbers are within the right range
|
| 304 |
+
align_to = 2 * world_size
|
| 305 |
+
|
| 306 |
+
def zero2_align(x):
|
| 307 |
+
return align_to * math.ceil(x / align_to)
|
| 308 |
+
|
| 309 |
+
if debug:
|
| 310 |
+
print(f"original offset={offset}, avail_numel={avail_numel}")
|
| 311 |
+
|
| 312 |
+
offset = zero2_align(offset)
|
| 313 |
+
avail_numel = zero2_align(avail_numel)
|
| 314 |
+
|
| 315 |
+
if debug:
|
| 316 |
+
print(f"aligned offset={offset}, avail_numel={avail_numel}")
|
| 317 |
+
|
| 318 |
+
# Sanity check
|
| 319 |
+
if offset != avail_numel:
|
| 320 |
+
raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
|
| 321 |
+
|
| 322 |
+
print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
|
| 326 |
+
exclude_frozen_parameters):
|
| 327 |
+
state_dict = OrderedDict()
|
| 328 |
+
|
| 329 |
+
# buffers
|
| 330 |
+
buffers = zero_model_states[0].buffers
|
| 331 |
+
state_dict.update(buffers)
|
| 332 |
+
if debug:
|
| 333 |
+
print(f"added {len(buffers)} buffers")
|
| 334 |
+
|
| 335 |
+
if not exclude_frozen_parameters:
|
| 336 |
+
_zero2_merge_frozen_params(state_dict, zero_model_states)
|
| 337 |
+
|
| 338 |
+
_zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
|
| 339 |
+
|
| 340 |
+
# recover shared parameters
|
| 341 |
+
for pair in zero_model_states[0].shared_params:
|
| 342 |
+
if pair[1] in state_dict:
|
| 343 |
+
state_dict[pair[0]] = state_dict[pair[1]]
|
| 344 |
+
|
| 345 |
+
return state_dict
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
def zero3_partitioned_param_info(unpartitioned_numel, world_size):
|
| 349 |
+
remainder = unpartitioned_numel % world_size
|
| 350 |
+
padding_numel = (world_size - remainder) if remainder else 0
|
| 351 |
+
partitioned_numel = math.ceil(unpartitioned_numel / world_size)
|
| 352 |
+
return partitioned_numel, padding_numel
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
|
| 356 |
+
if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
|
| 357 |
+
return
|
| 358 |
+
|
| 359 |
+
if debug:
|
| 360 |
+
for i in range(world_size):
|
| 361 |
+
num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
|
| 362 |
+
print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
|
| 363 |
+
|
| 364 |
+
frozen_param_shapes = zero_model_states[0].frozen_param_shapes
|
| 365 |
+
wanted_params = len(frozen_param_shapes)
|
| 366 |
+
wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
|
| 367 |
+
avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
|
| 368 |
+
print(f'Frozen params: Have {avail_numel} numels to process.')
|
| 369 |
+
print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
|
| 370 |
+
|
| 371 |
+
total_params = 0
|
| 372 |
+
total_numel = 0
|
| 373 |
+
for name, shape in zero_model_states[0].frozen_param_shapes.items():
|
| 374 |
+
total_params += 1
|
| 375 |
+
unpartitioned_numel = shape.numel()
|
| 376 |
+
total_numel += unpartitioned_numel
|
| 377 |
+
|
| 378 |
+
param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
|
| 379 |
+
state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
|
| 380 |
+
|
| 381 |
+
partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
|
| 382 |
+
|
| 383 |
+
if debug:
|
| 384 |
+
print(
|
| 385 |
+
f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
|
| 386 |
+
)
|
| 387 |
+
|
| 388 |
+
print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
class GatheredTensor:
|
| 392 |
+
"""
|
| 393 |
+
A pseudo tensor that collects partitioned weights.
|
| 394 |
+
It is more memory efficient when there are multiple groups.
|
| 395 |
+
"""
|
| 396 |
+
|
| 397 |
+
def __init__(self, flat_groups, flat_groups_offset, offset, partitioned_numel, shape):
|
| 398 |
+
self.flat_groups = flat_groups
|
| 399 |
+
self.flat_groups_offset = flat_groups_offset
|
| 400 |
+
self.offset = offset
|
| 401 |
+
self.partitioned_numel = partitioned_numel
|
| 402 |
+
self.shape = shape
|
| 403 |
+
self.dtype = self.flat_groups[0][0].dtype
|
| 404 |
+
|
| 405 |
+
def contiguous(self):
|
| 406 |
+
"""
|
| 407 |
+
Merge partitioned weights from flat_groups into a single tensor.
|
| 408 |
+
"""
|
| 409 |
+
end_idx = self.offset + self.partitioned_numel
|
| 410 |
+
world_size = len(self.flat_groups)
|
| 411 |
+
pad_flat_param_chunks = []
|
| 412 |
+
|
| 413 |
+
for rank_i in range(world_size):
|
| 414 |
+
# for each rank, we need to collect weights from related group/groups
|
| 415 |
+
flat_groups_at_rank_i = self.flat_groups[rank_i]
|
| 416 |
+
start_group_id = None
|
| 417 |
+
end_group_id = None
|
| 418 |
+
for group_id in range(len(self.flat_groups_offset)):
|
| 419 |
+
if self.flat_groups_offset[group_id] <= self.offset < self.flat_groups_offset[group_id + 1]:
|
| 420 |
+
start_group_id = group_id
|
| 421 |
+
if self.flat_groups_offset[group_id] < end_idx <= self.flat_groups_offset[group_id + 1]:
|
| 422 |
+
end_group_id = group_id
|
| 423 |
+
break
|
| 424 |
+
# collect weights from related group/groups
|
| 425 |
+
for group_id in range(start_group_id, end_group_id + 1):
|
| 426 |
+
flat_tensor = flat_groups_at_rank_i[group_id]
|
| 427 |
+
start_offset = self.offset - self.flat_groups_offset[group_id]
|
| 428 |
+
end_offset = min(end_idx, self.flat_groups_offset[group_id + 1]) - self.flat_groups_offset[group_id]
|
| 429 |
+
pad_flat_param_chunks.append(flat_tensor[start_offset:end_offset])
|
| 430 |
+
|
| 431 |
+
# collect weights from all ranks
|
| 432 |
+
pad_flat_param = torch.cat(pad_flat_param_chunks, dim=0)
|
| 433 |
+
param = pad_flat_param[:self.shape.numel()].view(self.shape).contiguous()
|
| 434 |
+
return param
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
|
| 438 |
+
param_shapes = zero_model_states[0].param_shapes
|
| 439 |
+
avail_numel = sum([flat_group.numel() for flat_group in fp32_flat_groups[0]]) * world_size
|
| 440 |
+
|
| 441 |
+
# Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
|
| 442 |
+
# param, re-consolidating each param, while dealing with padding if any
|
| 443 |
+
|
| 444 |
+
# merge list of dicts, preserving order
|
| 445 |
+
param_shapes = {k: v for d in param_shapes for k, v in d.items()}
|
| 446 |
+
|
| 447 |
+
if debug:
|
| 448 |
+
for i in range(world_size):
|
| 449 |
+
print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
|
| 450 |
+
|
| 451 |
+
wanted_params = len(param_shapes)
|
| 452 |
+
wanted_numel = sum(shape.numel() for shape in param_shapes.values())
|
| 453 |
+
# not asserting if there is a mismatch due to possible padding
|
| 454 |
+
avail_numel = fp32_flat_groups[0].numel() * world_size
|
| 455 |
+
print(f"Trainable params: Have {avail_numel} numels to process.")
|
| 456 |
+
print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
|
| 457 |
+
|
| 458 |
+
# params
|
| 459 |
+
# XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
|
| 460 |
+
# out-of-core computing solution
|
| 461 |
+
offset = 0
|
| 462 |
+
total_numel = 0
|
| 463 |
+
total_params = 0
|
| 464 |
+
flat_groups_offset = [0] + list(np.cumsum([flat_tensor.numel() for flat_tensor in fp32_flat_groups[0]]))
|
| 465 |
+
for name, shape in tqdm(param_shapes.items(), desc='Gathering sharded weights'):
|
| 466 |
+
unpartitioned_numel = shape.numel()
|
| 467 |
+
total_numel += unpartitioned_numel
|
| 468 |
+
total_params += 1
|
| 469 |
+
partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
|
| 470 |
+
|
| 471 |
+
if debug:
|
| 472 |
+
print(
|
| 473 |
+
f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
|
| 474 |
+
)
|
| 475 |
+
|
| 476 |
+
# memory efficient tensor
|
| 477 |
+
tensor = GatheredTensor(fp32_flat_groups, flat_groups_offset, offset, partitioned_numel, shape)
|
| 478 |
+
state_dict[name] = tensor
|
| 479 |
+
offset += partitioned_numel
|
| 480 |
+
|
| 481 |
+
offset *= world_size
|
| 482 |
+
|
| 483 |
+
# Sanity check
|
| 484 |
+
if offset != avail_numel:
|
| 485 |
+
raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
|
| 486 |
+
|
| 487 |
+
print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
|
| 491 |
+
exclude_frozen_parameters):
|
| 492 |
+
state_dict = OrderedDict()
|
| 493 |
+
|
| 494 |
+
# buffers
|
| 495 |
+
buffers = zero_model_states[0].buffers
|
| 496 |
+
state_dict.update(buffers)
|
| 497 |
+
if debug:
|
| 498 |
+
print(f"added {len(buffers)} buffers")
|
| 499 |
+
|
| 500 |
+
if not exclude_frozen_parameters:
|
| 501 |
+
_zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
|
| 502 |
+
|
| 503 |
+
_zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
|
| 504 |
+
|
| 505 |
+
# recover shared parameters
|
| 506 |
+
for pair in zero_model_states[0].shared_params:
|
| 507 |
+
if pair[1] in state_dict:
|
| 508 |
+
state_dict[pair[0]] = state_dict[pair[1]]
|
| 509 |
+
|
| 510 |
+
return state_dict
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
def to_torch_tensor(state_dict, return_empty_tensor=False):
|
| 514 |
+
"""
|
| 515 |
+
Convert state_dict of GatheredTensor to torch tensor
|
| 516 |
+
"""
|
| 517 |
+
torch_state_dict = {}
|
| 518 |
+
converted_tensors = {}
|
| 519 |
+
for name, tensor in state_dict.items():
|
| 520 |
+
tensor_id = id(tensor)
|
| 521 |
+
if tensor_id in converted_tensors: # shared tensors
|
| 522 |
+
shared_tensor = torch_state_dict[converted_tensors[tensor_id]]
|
| 523 |
+
torch_state_dict[name] = shared_tensor
|
| 524 |
+
else:
|
| 525 |
+
converted_tensors[tensor_id] = name
|
| 526 |
+
if return_empty_tensor:
|
| 527 |
+
torch_state_dict[name] = torch.empty(tensor.shape, dtype=tensor.dtype)
|
| 528 |
+
else:
|
| 529 |
+
torch_state_dict[name] = tensor.contiguous()
|
| 530 |
+
return torch_state_dict
|
| 531 |
+
|
| 532 |
+
|
| 533 |
+
def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir,
|
| 534 |
+
tag=None,
|
| 535 |
+
exclude_frozen_parameters=False,
|
| 536 |
+
lazy_mode=False):
|
| 537 |
+
"""
|
| 538 |
+
Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
|
| 539 |
+
``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
|
| 540 |
+
via a model hub.
|
| 541 |
+
|
| 542 |
+
Args:
|
| 543 |
+
- ``checkpoint_dir``: path to the desired checkpoint folder
|
| 544 |
+
- ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in 'latest' file. e.g., ``global_step14``
|
| 545 |
+
- ``exclude_frozen_parameters``: exclude frozen parameters
|
| 546 |
+
- ``lazy_mode``: get state_dict in lazy mode. It returns a dict of pesduo tensor instead of torch tensor, which is more memory efficient.
|
| 547 |
+
Convert the pesduo tensor to torch tensor by ``.contiguous()``
|
| 548 |
+
|
| 549 |
+
Returns:
|
| 550 |
+
- pytorch ``state_dict``
|
| 551 |
+
|
| 552 |
+
A typical usage might be ::
|
| 553 |
+
|
| 554 |
+
from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
|
| 555 |
+
# do the training and checkpoint saving
|
| 556 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
|
| 557 |
+
model = model.cpu() # move to cpu
|
| 558 |
+
model.load_state_dict(state_dict)
|
| 559 |
+
# submit to model hub or save the model to share with others
|
| 560 |
+
|
| 561 |
+
In this example the ``model`` will no longer be usable in the deepspeed context of the same
|
| 562 |
+
application. i.e. you will need to re-initialize the deepspeed engine, since
|
| 563 |
+
``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
|
| 564 |
+
|
| 565 |
+
If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
|
| 566 |
+
|
| 567 |
+
Note: the above usage may not work if your application doesn't have sufficient free CPU memory.
|
| 568 |
+
You may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
|
| 569 |
+
the checkpoint. Or you can load state_dict in lazy mode ::
|
| 570 |
+
|
| 571 |
+
from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
|
| 572 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, lazy_mode=True) # not on cpu
|
| 573 |
+
for name, lazy_tensor in state_dict.item():
|
| 574 |
+
tensor = lazy_tensor.contiguous() # to cpu
|
| 575 |
+
print(name, tensor)
|
| 576 |
+
# del tensor to release memory if it no longer in use
|
| 577 |
+
"""
|
| 578 |
+
if tag is None:
|
| 579 |
+
latest_path = os.path.join(checkpoint_dir, 'latest')
|
| 580 |
+
if os.path.isfile(latest_path):
|
| 581 |
+
with open(latest_path, 'r') as fd:
|
| 582 |
+
tag = fd.read().strip()
|
| 583 |
+
else:
|
| 584 |
+
raise ValueError(f"Unable to find 'latest' file at {latest_path}")
|
| 585 |
+
|
| 586 |
+
ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
|
| 587 |
+
|
| 588 |
+
if not os.path.isdir(ds_checkpoint_dir):
|
| 589 |
+
raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
|
| 590 |
+
|
| 591 |
+
state_dict = _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters)
|
| 592 |
+
if lazy_mode:
|
| 593 |
+
return state_dict
|
| 594 |
+
else:
|
| 595 |
+
return to_torch_tensor(state_dict)
|
| 596 |
+
|
| 597 |
+
|
| 598 |
+
def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir,
|
| 599 |
+
output_dir,
|
| 600 |
+
max_shard_size="5GB",
|
| 601 |
+
safe_serialization=False,
|
| 602 |
+
tag=None,
|
| 603 |
+
exclude_frozen_parameters=False):
|
| 604 |
+
"""
|
| 605 |
+
Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
|
| 606 |
+
loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
|
| 607 |
+
|
| 608 |
+
Args:
|
| 609 |
+
- ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
|
| 610 |
+
- ``output_dir``: directory to the pytorch fp32 state_dict output files
|
| 611 |
+
- ``max_shard_size``: the maximum size for a checkpoint before being sharded, default value is 5GB
|
| 612 |
+
- ``safe_serialization``: whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).
|
| 613 |
+
- ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
|
| 614 |
+
- ``exclude_frozen_parameters``: exclude frozen parameters
|
| 615 |
+
"""
|
| 616 |
+
|
| 617 |
+
# Dependency pre-check
|
| 618 |
+
if safe_serialization:
|
| 619 |
+
try:
|
| 620 |
+
from safetensors.torch import save_file
|
| 621 |
+
except ImportError:
|
| 622 |
+
print('If you want to use `safe_serialization`, please `pip install safetensors`')
|
| 623 |
+
raise
|
| 624 |
+
if max_shard_size is not None:
|
| 625 |
+
try:
|
| 626 |
+
from huggingface_hub import split_torch_state_dict_into_shards
|
| 627 |
+
except ImportError:
|
| 628 |
+
print('If you want to use `max_shard_size`, please `pip install huggingface_hub`')
|
| 629 |
+
raise
|
| 630 |
+
|
| 631 |
+
# Convert zero checkpoint to state_dict
|
| 632 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir,
|
| 633 |
+
tag,
|
| 634 |
+
exclude_frozen_parameters,
|
| 635 |
+
lazy_mode=True)
|
| 636 |
+
|
| 637 |
+
# Shard the model if it is too big.
|
| 638 |
+
weights_name = "model.safetensors" if safe_serialization else "pytorch_model.bin"
|
| 639 |
+
if max_shard_size is not None:
|
| 640 |
+
filename_pattern = weights_name.replace(".bin", "{suffix}.bin").replace(".safetensors", "{suffix}.safetensors")
|
| 641 |
+
# an memory-efficient approach for sharding
|
| 642 |
+
empty_state_dict = to_torch_tensor(state_dict, return_empty_tensor=True)
|
| 643 |
+
state_dict_split = split_torch_state_dict_into_shards(empty_state_dict,
|
| 644 |
+
filename_pattern=filename_pattern,
|
| 645 |
+
max_shard_size=max_shard_size)
|
| 646 |
+
else:
|
| 647 |
+
from collections import namedtuple
|
| 648 |
+
StateDictSplit = namedtuple("StateDictSplit", ["is_sharded", "filename_to_tensors"])
|
| 649 |
+
state_dict_split = StateDictSplit(is_sharded=False,
|
| 650 |
+
filename_to_tensors={weights_name: list(state_dict.keys())})
|
| 651 |
+
|
| 652 |
+
# Save the model by shard
|
| 653 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 654 |
+
filename_to_tensors = state_dict_split.filename_to_tensors.items()
|
| 655 |
+
for shard_file, tensors in tqdm(filename_to_tensors, desc="Saving checkpoint shards"):
|
| 656 |
+
shard_state_dict = {tensor_name: state_dict[tensor_name] for tensor_name in tensors}
|
| 657 |
+
shard_state_dict = to_torch_tensor(shard_state_dict)
|
| 658 |
+
output_path = os.path.join(output_dir, shard_file)
|
| 659 |
+
if safe_serialization:
|
| 660 |
+
save_file(shard_state_dict, output_path, metadata={"format": "pt"})
|
| 661 |
+
else:
|
| 662 |
+
torch.save(shard_state_dict, output_path)
|
| 663 |
+
# release the memory of current shard
|
| 664 |
+
for tensor_name in list(shard_state_dict.keys()):
|
| 665 |
+
del state_dict[tensor_name]
|
| 666 |
+
del shard_state_dict[tensor_name]
|
| 667 |
+
del shard_state_dict
|
| 668 |
+
gc.collect()
|
| 669 |
+
|
| 670 |
+
# Save index if sharded
|
| 671 |
+
if state_dict_split.is_sharded:
|
| 672 |
+
index = {
|
| 673 |
+
"metadata": state_dict_split.metadata,
|
| 674 |
+
"weight_map": state_dict_split.tensor_to_filename,
|
| 675 |
+
}
|
| 676 |
+
save_index_file = "model.safetensors.index.json" if safe_serialization else "pytorch_model.bin.index.json"
|
| 677 |
+
save_index_file = os.path.join(output_dir, save_index_file)
|
| 678 |
+
with open(save_index_file, "w", encoding="utf-8") as f:
|
| 679 |
+
content = json.dumps(index, indent=2, sort_keys=True) + "\n"
|
| 680 |
+
f.write(content)
|
| 681 |
+
|
| 682 |
+
|
| 683 |
+
def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
|
| 684 |
+
"""
|
| 685 |
+
1. Put the provided model to cpu
|
| 686 |
+
2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
|
| 687 |
+
3. Load it into the provided model
|
| 688 |
+
|
| 689 |
+
Args:
|
| 690 |
+
- ``model``: the model object to update
|
| 691 |
+
- ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
|
| 692 |
+
- ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
|
| 693 |
+
|
| 694 |
+
Returns:
|
| 695 |
+
- ``model`: modified model
|
| 696 |
+
|
| 697 |
+
Make sure you have plenty of CPU memory available before you call this function. If you don't
|
| 698 |
+
have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
|
| 699 |
+
conveniently placed for you in the checkpoint folder.
|
| 700 |
+
|
| 701 |
+
A typical usage might be ::
|
| 702 |
+
|
| 703 |
+
from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
|
| 704 |
+
model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
|
| 705 |
+
# submit to model hub or save the model to share with others
|
| 706 |
+
|
| 707 |
+
Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
|
| 708 |
+
of the same application. i.e. you will need to re-initialize the deepspeed engine, since
|
| 709 |
+
``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
|
| 710 |
+
|
| 711 |
+
"""
|
| 712 |
+
logger.info(f"Extracting fp32 weights")
|
| 713 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
|
| 714 |
+
|
| 715 |
+
logger.info(f"Overwriting model with fp32 weights")
|
| 716 |
+
model = model.cpu()
|
| 717 |
+
model.load_state_dict(state_dict, strict=False)
|
| 718 |
+
|
| 719 |
+
return model
|
| 720 |
+
|
| 721 |
+
|
| 722 |
+
if __name__ == "__main__":
|
| 723 |
+
parser = argparse.ArgumentParser()
|
| 724 |
+
parser.add_argument("checkpoint_dir",
|
| 725 |
+
type=str,
|
| 726 |
+
help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
|
| 727 |
+
parser.add_argument("output_dir",
|
| 728 |
+
type=str,
|
| 729 |
+
help="directory to the pytorch fp32 state_dict output files"
|
| 730 |
+
"(e.g. path/checkpoint-12-output/)")
|
| 731 |
+
parser.add_argument(
|
| 732 |
+
"--max_shard_size",
|
| 733 |
+
type=str,
|
| 734 |
+
default="5GB",
|
| 735 |
+
help="The maximum size for a checkpoint before being sharded. Checkpoints shard will then be each of size"
|
| 736 |
+
"lower than this size. If expressed as a string, needs to be digits followed by a unit (like `5MB`"
|
| 737 |
+
"We default it to 5GB in order for models to be able to run easily on free-tier google colab instances"
|
| 738 |
+
"without CPU OOM issues.")
|
| 739 |
+
parser.add_argument(
|
| 740 |
+
"--safe_serialization",
|
| 741 |
+
default=False,
|
| 742 |
+
action='store_true',
|
| 743 |
+
help="Whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).")
|
| 744 |
+
parser.add_argument("-t",
|
| 745 |
+
"--tag",
|
| 746 |
+
type=str,
|
| 747 |
+
default=None,
|
| 748 |
+
help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
|
| 749 |
+
parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters")
|
| 750 |
+
parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
|
| 751 |
+
args = parser.parse_args()
|
| 752 |
+
|
| 753 |
+
debug = args.debug
|
| 754 |
+
|
| 755 |
+
convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir,
|
| 756 |
+
args.output_dir,
|
| 757 |
+
max_shard_size=args.max_shard_size,
|
| 758 |
+
safe_serialization=args.safe_serialization,
|
| 759 |
+
tag=args.tag,
|
| 760 |
+
exclude_frozen_parameters=args.exclude_frozen_parameters)
|