chitanda commited on
Commit
2b3e9f1
1 Parent(s): ab6bbd3

Upload folder using huggingface_hub

Browse files
added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "[PAD]": 32000
3
+ }
config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/tmp/open-llama-7b-preview-300bt",
3
+ "architectures": [
4
+ "LlamaForConditionalGeneration"
5
+ ],
6
+ "bos_token_id": 1,
7
+ "eos_token_id": 2,
8
+ "hidden_act": "silu",
9
+ "hidden_size": 4096,
10
+ "initializer_range": 0.02,
11
+ "intermediate_size": 11008,
12
+ "max_position_embeddings": 2048,
13
+ "model_type": "llama",
14
+ "num_attention_heads": 32,
15
+ "num_hidden_layers": 32,
16
+ "pad_token_id": 32000,
17
+ "rms_norm_eps": 1e-06,
18
+ "tie_word_embeddings": false,
19
+ "torch_dtype": "bfloat16",
20
+ "transformers_version": "4.28.1",
21
+ "use_cache": true,
22
+ "vocab_size": 32001
23
+ }
generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 2,
5
+ "pad_token_id": 0,
6
+ "transformers_version": "4.28.1"
7
+ }
latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step1750
pytorch_model-00001-of-00002.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:29d4d797c428720e7a9730d2952946f548c562dcbc12599099ea7aee7728429d
3
+ size 13476889433
pytorch_model-00002-of-00002.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:42d9b4baa6444df320b6b4d50375d6eccba3fe06e4928364ee927a04a08f1dd5
3
+ size 13476861946
pytorch_model.bin.index.json ADDED
@@ -0,0 +1,330 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 13476851712
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "pytorch_model-00002-of-00002.bin",
7
+ "model.embed_tokens.weight": "pytorch_model-00001-of-00002.bin",
8
+ "model.layers.0.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
9
+ "model.layers.0.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
10
+ "model.layers.0.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
11
+ "model.layers.0.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
12
+ "model.layers.0.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
13
+ "model.layers.0.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
14
+ "model.layers.0.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
15
+ "model.layers.0.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
16
+ "model.layers.0.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
17
+ "model.layers.0.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
18
+ "model.layers.1.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
19
+ "model.layers.1.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
20
+ "model.layers.1.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
21
+ "model.layers.1.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
22
+ "model.layers.1.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
23
+ "model.layers.1.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
24
+ "model.layers.1.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
25
+ "model.layers.1.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
26
+ "model.layers.1.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
27
+ "model.layers.1.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
28
+ "model.layers.10.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
29
+ "model.layers.10.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
30
+ "model.layers.10.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
31
+ "model.layers.10.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
32
+ "model.layers.10.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
33
+ "model.layers.10.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
34
+ "model.layers.10.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
35
+ "model.layers.10.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
36
+ "model.layers.10.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
37
+ "model.layers.10.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
38
+ "model.layers.11.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
39
+ "model.layers.11.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
40
+ "model.layers.11.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
41
+ "model.layers.11.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
42
+ "model.layers.11.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
43
+ "model.layers.11.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
44
+ "model.layers.11.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
45
+ "model.layers.11.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
46
+ "model.layers.11.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
47
+ "model.layers.11.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
48
+ "model.layers.12.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
49
+ "model.layers.12.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
50
+ "model.layers.12.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
51
+ "model.layers.12.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
52
+ "model.layers.12.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
53
+ "model.layers.12.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
54
+ "model.layers.12.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
55
+ "model.layers.12.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
56
+ "model.layers.12.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
57
+ "model.layers.12.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
58
+ "model.layers.13.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
59
+ "model.layers.13.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
60
+ "model.layers.13.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
61
+ "model.layers.13.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
62
+ "model.layers.13.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
63
+ "model.layers.13.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
64
+ "model.layers.13.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
65
+ "model.layers.13.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
66
+ "model.layers.13.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
67
+ "model.layers.13.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
68
+ "model.layers.14.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
69
+ "model.layers.14.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
70
+ "model.layers.14.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
71
+ "model.layers.14.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
72
+ "model.layers.14.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
73
+ "model.layers.14.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
74
+ "model.layers.14.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
75
+ "model.layers.14.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
76
+ "model.layers.14.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
77
+ "model.layers.14.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
78
+ "model.layers.15.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
79
+ "model.layers.15.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
80
+ "model.layers.15.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
81
+ "model.layers.15.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
82
+ "model.layers.15.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
83
+ "model.layers.15.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
84
+ "model.layers.15.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
85
+ "model.layers.15.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
86
+ "model.layers.15.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
87
+ "model.layers.15.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
88
+ "model.layers.16.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
89
+ "model.layers.16.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
90
+ "model.layers.16.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
91
+ "model.layers.16.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
92
+ "model.layers.16.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
93
+ "model.layers.16.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
94
+ "model.layers.16.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
95
+ "model.layers.16.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
96
+ "model.layers.16.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
97
+ "model.layers.16.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
98
+ "model.layers.17.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
99
+ "model.layers.17.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
100
+ "model.layers.17.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
101
+ "model.layers.17.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
102
+ "model.layers.17.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
103
+ "model.layers.17.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
104
+ "model.layers.17.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
105
+ "model.layers.17.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
106
+ "model.layers.17.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
107
+ "model.layers.17.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
108
+ "model.layers.18.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
109
+ "model.layers.18.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
110
+ "model.layers.18.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
111
+ "model.layers.18.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
112
+ "model.layers.18.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
113
+ "model.layers.18.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
114
+ "model.layers.18.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
115
+ "model.layers.18.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
116
+ "model.layers.18.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
117
+ "model.layers.18.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
118
+ "model.layers.19.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
119
+ "model.layers.19.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
120
+ "model.layers.19.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
121
+ "model.layers.19.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
122
+ "model.layers.19.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
123
+ "model.layers.19.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
124
+ "model.layers.19.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
125
+ "model.layers.19.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
126
+ "model.layers.19.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
127
+ "model.layers.19.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
128
+ "model.layers.2.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
129
+ "model.layers.2.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
130
+ "model.layers.2.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
131
+ "model.layers.2.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
132
+ "model.layers.2.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
133
+ "model.layers.2.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
134
+ "model.layers.2.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
135
+ "model.layers.2.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
136
+ "model.layers.2.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
137
+ "model.layers.2.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
138
+ "model.layers.20.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
139
+ "model.layers.20.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
140
+ "model.layers.20.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
141
+ "model.layers.20.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
142
+ "model.layers.20.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
143
+ "model.layers.20.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
144
+ "model.layers.20.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
145
+ "model.layers.20.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
146
+ "model.layers.20.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
147
+ "model.layers.20.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
148
+ "model.layers.21.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
149
+ "model.layers.21.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
150
+ "model.layers.21.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
151
+ "model.layers.21.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
152
+ "model.layers.21.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
153
+ "model.layers.21.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
154
+ "model.layers.21.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
155
+ "model.layers.21.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
156
+ "model.layers.21.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
157
+ "model.layers.21.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
158
+ "model.layers.22.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
159
+ "model.layers.22.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
160
+ "model.layers.22.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
161
+ "model.layers.22.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
162
+ "model.layers.22.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
163
+ "model.layers.22.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
164
+ "model.layers.22.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
165
+ "model.layers.22.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
166
+ "model.layers.22.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
167
+ "model.layers.22.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
168
+ "model.layers.23.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
169
+ "model.layers.23.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
170
+ "model.layers.23.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
171
+ "model.layers.23.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
172
+ "model.layers.23.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
173
+ "model.layers.23.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
174
+ "model.layers.23.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
175
+ "model.layers.23.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
176
+ "model.layers.23.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
177
+ "model.layers.23.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
178
+ "model.layers.24.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
179
+ "model.layers.24.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
180
+ "model.layers.24.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
181
+ "model.layers.24.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
182
+ "model.layers.24.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
183
+ "model.layers.24.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
184
+ "model.layers.24.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
185
+ "model.layers.24.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
186
+ "model.layers.24.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00002.bin",
187
+ "model.layers.24.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
188
+ "model.layers.25.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
189
+ "model.layers.25.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
190
+ "model.layers.25.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
191
+ "model.layers.25.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
192
+ "model.layers.25.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
193
+ "model.layers.25.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
194
+ "model.layers.25.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
195
+ "model.layers.25.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
196
+ "model.layers.25.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00002.bin",
197
+ "model.layers.25.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
198
+ "model.layers.26.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
199
+ "model.layers.26.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
200
+ "model.layers.26.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
201
+ "model.layers.26.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
202
+ "model.layers.26.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
203
+ "model.layers.26.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
204
+ "model.layers.26.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
205
+ "model.layers.26.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
206
+ "model.layers.26.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00002.bin",
207
+ "model.layers.26.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
208
+ "model.layers.27.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
209
+ "model.layers.27.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
210
+ "model.layers.27.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
211
+ "model.layers.27.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
212
+ "model.layers.27.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
213
+ "model.layers.27.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
214
+ "model.layers.27.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
215
+ "model.layers.27.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
216
+ "model.layers.27.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00002.bin",
217
+ "model.layers.27.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
218
+ "model.layers.28.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
219
+ "model.layers.28.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
220
+ "model.layers.28.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
221
+ "model.layers.28.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
222
+ "model.layers.28.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
223
+ "model.layers.28.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
224
+ "model.layers.28.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
225
+ "model.layers.28.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
226
+ "model.layers.28.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00002.bin",
227
+ "model.layers.28.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
228
+ "model.layers.29.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
229
+ "model.layers.29.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
230
+ "model.layers.29.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
231
+ "model.layers.29.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
232
+ "model.layers.29.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
233
+ "model.layers.29.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
234
+ "model.layers.29.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
235
+ "model.layers.29.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
236
+ "model.layers.29.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00002.bin",
237
+ "model.layers.29.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
238
+ "model.layers.3.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
239
+ "model.layers.3.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
240
+ "model.layers.3.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
241
+ "model.layers.3.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
242
+ "model.layers.3.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
243
+ "model.layers.3.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
244
+ "model.layers.3.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
245
+ "model.layers.3.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
246
+ "model.layers.3.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
247
+ "model.layers.3.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
248
+ "model.layers.30.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
249
+ "model.layers.30.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
250
+ "model.layers.30.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
251
+ "model.layers.30.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
252
+ "model.layers.30.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
253
+ "model.layers.30.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
254
+ "model.layers.30.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
255
+ "model.layers.30.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
256
+ "model.layers.30.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00002.bin",
257
+ "model.layers.30.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
258
+ "model.layers.31.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
259
+ "model.layers.31.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
260
+ "model.layers.31.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
261
+ "model.layers.31.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
262
+ "model.layers.31.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
263
+ "model.layers.31.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
264
+ "model.layers.31.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
265
+ "model.layers.31.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
266
+ "model.layers.31.self_attn.rotary_emb.inv_freq": "pytorch_model-00002-of-00002.bin",
267
+ "model.layers.31.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
268
+ "model.layers.4.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
269
+ "model.layers.4.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
270
+ "model.layers.4.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
271
+ "model.layers.4.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
272
+ "model.layers.4.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
273
+ "model.layers.4.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
274
+ "model.layers.4.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
275
+ "model.layers.4.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
276
+ "model.layers.4.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
277
+ "model.layers.4.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
278
+ "model.layers.5.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
279
+ "model.layers.5.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
280
+ "model.layers.5.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
281
+ "model.layers.5.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
282
+ "model.layers.5.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
283
+ "model.layers.5.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
284
+ "model.layers.5.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
285
+ "model.layers.5.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
286
+ "model.layers.5.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
287
+ "model.layers.5.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
288
+ "model.layers.6.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
289
+ "model.layers.6.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
290
+ "model.layers.6.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
291
+ "model.layers.6.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
292
+ "model.layers.6.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
293
+ "model.layers.6.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
294
+ "model.layers.6.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
295
+ "model.layers.6.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
296
+ "model.layers.6.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
297
+ "model.layers.6.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
298
+ "model.layers.7.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
299
+ "model.layers.7.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
300
+ "model.layers.7.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
301
+ "model.layers.7.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
302
+ "model.layers.7.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
303
+ "model.layers.7.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
304
+ "model.layers.7.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
305
+ "model.layers.7.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
306
+ "model.layers.7.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
307
+ "model.layers.7.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
308
+ "model.layers.8.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
309
+ "model.layers.8.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
310
+ "model.layers.8.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
311
+ "model.layers.8.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
312
+ "model.layers.8.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
313
+ "model.layers.8.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
314
+ "model.layers.8.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
315
+ "model.layers.8.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
316
+ "model.layers.8.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
317
+ "model.layers.8.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
318
+ "model.layers.9.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
319
+ "model.layers.9.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
320
+ "model.layers.9.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
321
+ "model.layers.9.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
322
+ "model.layers.9.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
323
+ "model.layers.9.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
324
+ "model.layers.9.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
325
+ "model.layers.9.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
326
+ "model.layers.9.self_attn.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
327
+ "model.layers.9.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
328
+ "model.norm.weight": "pytorch_model-00002-of-00002.bin"
329
+ }
330
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "eos_token": "</s>",
4
+ "pad_token": "[PAD]",
5
+ "unk_token": "<unk>"
6
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bc820fc43f4173d6362c16658c409ed423929a807e55a984af96cce1277d39a4
3
+ size 772031
tokenizer_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "bos_token": {
5
+ "__type": "AddedToken",
6
+ "content": "",
7
+ "lstrip": false,
8
+ "normalized": true,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "clean_up_tokenization_spaces": false,
13
+ "eos_token": {
14
+ "__type": "AddedToken",
15
+ "content": "",
16
+ "lstrip": false,
17
+ "normalized": true,
18
+ "rstrip": false,
19
+ "single_word": false
20
+ },
21
+ "model_max_length": 1000000000000000019884624838656,
22
+ "pad_token": null,
23
+ "sp_model_kwargs": {},
24
+ "tokenizer_class": "LlamaTokenizer",
25
+ "unk_token": {
26
+ "__type": "AddedToken",
27
+ "content": "",
28
+ "lstrip": false,
29
+ "normalized": true,
30
+ "rstrip": false,
31
+ "single_word": false
32
+ }
33
+ }
training_config.yaml ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aws_output_bucket: s3://sagemaker-us-east-1-107457652907/experiments/llama.open.7b.300bt.zh.10M.v1.0.seq2048.w16.adamw.NA100.0515.ds
2
+ data_dir: null
3
+ train_file: /opt/ml/input/data/train
4
+ dev_file: null
5
+ test_file: null
6
+ model:
7
+ _target_: models.llama.LlamaForConditionalGeneration.from_pretrained
8
+ vocab_size: 32001
9
+ pad_token_id: 32000
10
+ use_peft: false
11
+ gradient_checkpointing: true
12
+ read_tensor:
13
+ _target_: data.collators.zh_instruct.TextDatasetUnify
14
+ extended_vocab: null
15
+ collator:
16
+ _target_: data.collators.flan.FlanCollatorOverCollator
17
+ collator: null
18
+ max_seq_length: 2048
19
+ tokenizer: ${model_name_or_path}
20
+ decoder_only: true
21
+ num_workers: 4
22
+ prefetch_factor: 2
23
+ do_preprocess: false
24
+ model_name_or_path: /tmp/open-llama-7b-preview-300bt
25
+ pretrain: null
26
+ exp_name: llama.open.7b.300bt.zh.10M.v1.0.seq2048.w16.adamw.NA100.0515.ds
27
+ exp_notes: null
28
+ output_dir: /tmp/${exp_name}
29
+ resume: null
30
+ do_train: true
31
+ evaluate_during_training: false
32
+ do_eval: false
33
+ eval_sub_path: checkpoint-*
34
+ per_gpu_train_batch_size: 4
35
+ per_gpu_eval_batch_size: 4
36
+ learning_rate: 1.0e-05
37
+ gradient_accumulation_steps: 128
38
+ weight_decay: 0.0
39
+ adam_epsilon: 1.0e-06
40
+ adam_betas: (0.9, 0.99)
41
+ max_grad_norm: 5.0
42
+ num_train_epochs: 1
43
+ total_dataset_len: -1
44
+ max_steps: 0
45
+ warmup_proportion: 0.01
46
+ warmup_steps: 0
47
+ optimizer: null
48
+ use_nvlamb: null
49
+ bit_training: null
50
+ logging_steps: 1
51
+ save_best: false
52
+ save_steps: 250
53
+ eval_steps: 250
54
+ ddp_eval: true
55
+ no_cuda: false
56
+ seed: 42
57
+ local_rank: 0
58
+ fp16: true
59
+ fp16_opt_level: O1
60
+ fp16_bfloat16: true
61
+ prediction_cfg:
62
+ metric: acc
63
+ measure: 1
64
+ best_checkpoint: null
65
+ best_result: null
66
+ eval_forward_fn:
67
+ _target_: general_util.evaluator.DiscriminatorForwardFn
68
+ post_process: null
69
+ fairscale_config:
70
+ _target_: general_util.fsdp_utils.default_initialize
71
+ fp16: ${fp16}
72
+ move_grads_to_cpu: false
73
+ move_params_to_cpu: false
74
+ flatten_parameters: false
75
+ with_lightseq: false
76
+ ds_cfg:
77
+ train_micro_batch_size_per_gpu: ${per_gpu_train_batch_size}
78
+ gradient_accumulation_steps: ${gradient_accumulation_steps}
79
+ optimizer:
80
+ type: AdamW
81
+ params:
82
+ lr: ${learning_rate}
83
+ betas:
84
+ - 0.9
85
+ - 0.99
86
+ eps: ${adam_epsilon}
87
+ weight_decay: ${weight_decay}
88
+ scheduler:
89
+ type: WarmupLR
90
+ params:
91
+ warmup_max_lr: ${learning_rate}
92
+ warmup_num_steps: 18
93
+ warmup_type: linear
94
+ gradient_clipping: ${max_grad_norm}
95
+ bf16:
96
+ enabled: ${fp16}
97
+ zero_optimization:
98
+ stage: 1
99
+ contiguous_gradients: true
100
+ overlap_comm: true
101
+ reduce_scatter: true
102
+ reduce_bucket_size: 500000000.0
103
+ allgather_bucket_size: 500000000.0
104
+ steps_per_print: 1024
105
+ summary_helper:
106
+ _target_: general_util.tensorboard_helper.WandbWriter
107
+ batch_index_or_keys: null
108
+ outputs_index_or_keys: null
109
+ n_gpu: 1
110
+ device: cuda:0
111
+ train_batch_size: 4
112
+ eval_batch_size: null
113
+ world_size: 16
114
+ world_rank: null
zero_to_fp32.py ADDED
@@ -0,0 +1,483 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ '''Copyright The Microsoft DeepSpeed Team'''
3
+
4
+ # This script extracts fp32 consolidated weights from a zero 2 and 3 DeepSpeed checkpoints. It gets
5
+ # copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
6
+ # the future. Once extracted, the weights don't require DeepSpeed and can be used in any
7
+ # application.
8
+ #
9
+ # example: python zero_to_fp32.py . pytorch_model.bin
10
+
11
+ import argparse
12
+ import torch
13
+ import glob
14
+ import math
15
+ import os
16
+ import re
17
+ from collections import OrderedDict
18
+
19
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
20
+ # DeepSpeed data structures it has to be available in the current python environment.
21
+ from deepspeed.utils import logger
22
+ from deepspeed.checkpoint.constants import (DS_VERSION,
23
+ OPTIMIZER_STATE_DICT,
24
+ SINGLE_PARTITION_OF_FP32_GROUPS,
25
+ FP32_FLAT_GROUPS,
26
+ ZERO_STAGE,
27
+ PARTITION_COUNT,
28
+ PARAM_SHAPES,
29
+ BUFFER_NAMES)
30
+
31
+ debug = 0
32
+
33
+ # load to cpu
34
+ device = torch.device('cpu')
35
+
36
+
37
+ def atoi(text):
38
+ return int(text) if text.isdigit() else text
39
+
40
+
41
+ def natural_keys(text):
42
+ '''
43
+ alist.sort(key=natural_keys) sorts in human order
44
+ http://nedbatchelder.com/blog/200712/human_sorting.html
45
+ (See Toothy's implementation in the comments)
46
+ '''
47
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
48
+
49
+
50
+ def get_model_state_file(checkpoint_dir, zero_stage):
51
+ if not os.path.isdir(checkpoint_dir):
52
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
53
+
54
+ # there should be only one file
55
+ if zero_stage == 2:
56
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
57
+ elif zero_stage == 3:
58
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
59
+
60
+ if not os.path.exists(file):
61
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
62
+
63
+ return file
64
+
65
+
66
+ def get_optim_files(checkpoint_dir):
67
+ # XXX: need to test that this simple glob rule works for multi-node setup too
68
+ optim_files = sorted(glob.glob(os.path.join(checkpoint_dir,
69
+ "*_optim_states.pt")),
70
+ key=natural_keys)
71
+
72
+ if len(optim_files) == 0:
73
+ raise FileNotFoundError(
74
+ f"can't find '*_optim_states.pt' files in directory '{checkpoint_dir}'")
75
+
76
+ return optim_files
77
+
78
+
79
+ def parse_model_state(file):
80
+ state_dict = torch.load(file, map_location=device)
81
+
82
+ if BUFFER_NAMES not in state_dict:
83
+ raise ValueError(f"{file} is not a model state checkpoint")
84
+ buffer_names = state_dict[BUFFER_NAMES]
85
+ if debug:
86
+ print("Found buffers:", buffer_names)
87
+
88
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
89
+ buffers = {
90
+ k: v.float()
91
+ for k,
92
+ v in state_dict["module"].items() if k in buffer_names
93
+ }
94
+ param_shapes = state_dict[PARAM_SHAPES]
95
+
96
+ ds_version = state_dict.get(DS_VERSION, None)
97
+
98
+ return buffers, param_shapes, ds_version
99
+
100
+
101
+ def parse_optim_states(files, ds_checkpoint_dir):
102
+
103
+ total_files = len(files)
104
+ state_dicts = []
105
+ for f in files:
106
+ state_dicts.append(torch.load(f, map_location=device))
107
+
108
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
109
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
110
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
111
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
112
+
113
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
114
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
115
+ # use the max of the partition_count to get the dp world_size.
116
+
117
+ if type(world_size) is list:
118
+ world_size = max(world_size)
119
+
120
+ if world_size != total_files:
121
+ raise ValueError(
122
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
123
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
124
+ )
125
+
126
+ # the groups are named differently in each stage
127
+ if zero_stage == 2:
128
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
129
+ elif zero_stage == 3:
130
+ fp32_groups_key = FP32_FLAT_GROUPS
131
+ else:
132
+ raise ValueError(f"unknown zero stage {zero_stage}")
133
+
134
+ if zero_stage == 2:
135
+ fp32_flat_groups = [
136
+ state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key]
137
+ for i in range(len(state_dicts))
138
+ ]
139
+ elif zero_stage == 3:
140
+ # if there is more than one param group, there will be multiple flattened tensors - one
141
+ # flattened tensor per group - for simplicity merge them into a single tensor
142
+ #
143
+ # XXX: could make the script more memory efficient for when there are multiple groups - it
144
+ # will require matching the sub-lists of param_shapes for each param group flattened tensor
145
+
146
+ fp32_flat_groups = [
147
+ torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key],
148
+ 0) for i in range(len(state_dicts))
149
+ ]
150
+
151
+ return zero_stage, world_size, fp32_flat_groups
152
+
153
+
154
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir):
155
+ """
156
+ Returns fp32 state_dict reconstructed from ds checkpoint
157
+
158
+ Args:
159
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
160
+
161
+ """
162
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
163
+
164
+ optim_files = get_optim_files(ds_checkpoint_dir)
165
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
166
+ print(
167
+ f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
168
+
169
+ model_file = get_model_state_file(ds_checkpoint_dir, zero_stage)
170
+ buffers, param_shapes, ds_version = parse_model_state(model_file)
171
+ print(f'Parsing checkpoint created by deepspeed=={ds_version}')
172
+
173
+ if zero_stage == 2:
174
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size,
175
+ param_shapes,
176
+ fp32_flat_groups,
177
+ buffers)
178
+ elif zero_stage == 3:
179
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size,
180
+ param_shapes,
181
+ fp32_flat_groups,
182
+ buffers)
183
+
184
+
185
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size,
186
+ param_shapes,
187
+ fp32_flat_groups,
188
+ buffers):
189
+
190
+ # Reconstruction protocol:
191
+ #
192
+ # XXX: document this
193
+
194
+ if debug:
195
+ for i in range(world_size):
196
+ for j in range(len(fp32_flat_groups[0])):
197
+ print(
198
+ f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
199
+
200
+ # XXX: memory usage doubles here (zero2)
201
+ num_param_groups = len(fp32_flat_groups[0])
202
+ merged_single_partition_of_fp32_groups = []
203
+ for i in range(num_param_groups):
204
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
205
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
206
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
207
+ avail_numel = sum([
208
+ full_single_fp32_vector.numel()
209
+ for full_single_fp32_vector in merged_single_partition_of_fp32_groups
210
+ ])
211
+
212
+ if debug:
213
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
214
+ wanted_numel = sum(
215
+ [sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
216
+ # not asserting if there is a mismatch due to possible padding
217
+ print(f"Have {avail_numel} numels to process.")
218
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
219
+
220
+ state_dict = OrderedDict()
221
+
222
+ # buffers
223
+ state_dict.update(buffers)
224
+ if debug:
225
+ print(f"added {len(buffers)} buffers")
226
+
227
+ # params
228
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
229
+ # out-of-core computing solution
230
+ total_numel = 0
231
+ total_params = 0
232
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
233
+ offset = 0
234
+ avail_numel = full_single_fp32_vector.numel()
235
+ for name, shape in shapes.items():
236
+
237
+ unpartitioned_numel = shape.numel()
238
+ total_numel += unpartitioned_numel
239
+ total_params += 1
240
+
241
+ if debug:
242
+ print(
243
+ f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} "
244
+ )
245
+ state_dict[name] = full_single_fp32_vector.narrow(
246
+ 0,
247
+ offset,
248
+ unpartitioned_numel).view(shape)
249
+ offset += unpartitioned_numel
250
+
251
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
252
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
253
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
254
+ # live optimizer object, so we are checking that the numbers are within the right range
255
+ align_to = 2 * world_size
256
+
257
+ def zero2_align(x):
258
+ return align_to * math.ceil(x / align_to)
259
+
260
+ if debug:
261
+ print(f"original offset={offset}, avail_numel={avail_numel}")
262
+
263
+ offset = zero2_align(offset)
264
+ avail_numel = zero2_align(avail_numel)
265
+
266
+ if debug:
267
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
268
+
269
+ # Sanity check
270
+ if offset != avail_numel:
271
+ raise ValueError(
272
+ f"consumed {offset} numels out of {avail_numel} - something is wrong")
273
+
274
+ print(
275
+ f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements"
276
+ )
277
+
278
+ return state_dict
279
+
280
+
281
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
282
+ remainder = unpartitioned_numel % world_size
283
+ padding_numel = (world_size - remainder) if remainder else 0
284
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
285
+ return partitioned_numel, padding_numel
286
+
287
+
288
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size,
289
+ param_shapes,
290
+ fp32_flat_groups,
291
+ buffers):
292
+
293
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
294
+ # param, re-consolidating each param, while dealing with padding if any
295
+
296
+ avail_numel = fp32_flat_groups[0].numel() * world_size
297
+ # merge list of dicts, preserving order
298
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
299
+
300
+ if debug:
301
+ for i in range(world_size):
302
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
303
+
304
+ wanted_params = len(param_shapes)
305
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
306
+ # not asserting if there is a mismatch due to possible padding
307
+ print(f"Have {avail_numel} numels to process.")
308
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
309
+
310
+ state_dict = OrderedDict()
311
+
312
+ # buffers
313
+ state_dict.update(buffers)
314
+ if debug:
315
+ print(f"added {len(buffers)} buffers")
316
+
317
+ # params
318
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
319
+ # out-of-core computing solution
320
+ offset = 0
321
+ total_numel = 0
322
+ total_params = 0
323
+ for name, shape in param_shapes.items():
324
+
325
+ unpartitioned_numel = shape.numel()
326
+ total_numel += unpartitioned_numel
327
+ total_params += 1
328
+
329
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
330
+
331
+ if debug:
332
+ print(
333
+ f"{total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
334
+ )
335
+
336
+ # XXX: memory usage doubles here
337
+ state_dict[name] = torch.cat(
338
+ tuple(fp32_flat_groups[i].narrow(0,
339
+ offset,
340
+ partitioned_numel)
341
+ for i in range(world_size)),
342
+ 0).narrow(0,
343
+ 0,
344
+ unpartitioned_numel).view(shape)
345
+ offset += partitioned_numel
346
+
347
+ offset *= world_size
348
+
349
+ # Sanity check
350
+ if offset != avail_numel:
351
+ raise ValueError(
352
+ f"consumed {offset} numels out of {avail_numel} - something is wrong")
353
+
354
+ print(
355
+ f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements"
356
+ )
357
+
358
+ return state_dict
359
+
360
+
361
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None):
362
+ """
363
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
364
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
365
+ via a model hub.
366
+
367
+ Args:
368
+ - ``checkpoint_dir``: path to the desired checkpoint folder
369
+ - ``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``
370
+
371
+ Returns:
372
+ - pytorch ``state_dict``
373
+
374
+ Note: this approach may not work if your application doesn't have sufficient free CPU memory and
375
+ you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
376
+ the checkpoint.
377
+
378
+ A typical usage might be ::
379
+
380
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
381
+ # do the training and checkpoint saving
382
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
383
+ model = model.cpu() # move to cpu
384
+ model.load_state_dict(state_dict)
385
+ # submit to model hub or save the model to share with others
386
+
387
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
388
+ application. i.e. you will need to re-initialize the deepspeed engine, since
389
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
390
+
391
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
392
+
393
+ """
394
+ if tag is None:
395
+ latest_path = os.path.join(checkpoint_dir, 'latest')
396
+ if os.path.isfile(latest_path):
397
+ with open(latest_path, 'r') as fd:
398
+ tag = fd.read().strip()
399
+ else:
400
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
401
+
402
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
403
+
404
+ if not os.path.isdir(ds_checkpoint_dir):
405
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
406
+
407
+ return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir)
408
+
409
+
410
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file, tag=None):
411
+ """
412
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
413
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
414
+
415
+ Args:
416
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
417
+ - ``output_file``: path to the pytorch fp32 state_dict output file (e.g. path/pytorch_model.bin)
418
+ - ``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``
419
+ """
420
+
421
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
422
+ print(f"Saving fp32 state dict to {output_file}")
423
+ torch.save(state_dict, output_file)
424
+
425
+
426
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
427
+ """
428
+ 1. Put the provided model to cpu
429
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
430
+ 3. Load it into the provided model
431
+
432
+ Args:
433
+ - ``model``: the model object to update
434
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
435
+ - ``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``
436
+
437
+ Returns:
438
+ - ``model`: modified model
439
+
440
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
441
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
442
+ conveniently placed for you in the checkpoint folder.
443
+
444
+ A typical usage might be ::
445
+
446
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
447
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
448
+ # submit to model hub or save the model to share with others
449
+
450
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
451
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
452
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
453
+
454
+ """
455
+ logger.info(f"Extracting fp32 weights")
456
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
457
+
458
+ logger.info(f"Overwriting model with fp32 weights")
459
+ model = model.cpu()
460
+ model.load_state_dict(state_dict, strict=False)
461
+
462
+ return model
463
+
464
+
465
+ if __name__ == "__main__":
466
+
467
+ parser = argparse.ArgumentParser()
468
+ parser.add_argument(
469
+ "checkpoint_dir",
470
+ type=str,
471
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
472
+ parser.add_argument(
473
+ "output_file",
474
+ type=str,
475
+ help=
476
+ "path to the pytorch fp32 state_dict output file (e.g. path/checkpoint-12/pytorch_model.bin)"
477
+ )
478
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
479
+ args = parser.parse_args()
480
+
481
+ debug = args.debug
482
+
483
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir, args.output_file)