Ubuntu
commited on
Commit
•
9ceb86a
1
Parent(s):
5ddd0bb
First model version
Browse files- README.md +84 -0
- config.json +61 -0
- generation_config.json +7 -0
- global_step8973/bf16_zero_pp_rank_0_mp_rank_00_optim_states.pt +3 -0
- global_step8973/bf16_zero_pp_rank_1_mp_rank_00_optim_states.pt +3 -0
- global_step8973/bf16_zero_pp_rank_2_mp_rank_00_optim_states.pt +3 -0
- global_step8973/bf16_zero_pp_rank_3_mp_rank_00_optim_states.pt +3 -0
- global_step8973/zero_pp_rank_0_mp_rank_00_model_states.pt +3 -0
- global_step8973/zero_pp_rank_1_mp_rank_00_model_states.pt +3 -0
- global_step8973/zero_pp_rank_2_mp_rank_00_model_states.pt +3 -0
- global_step8973/zero_pp_rank_3_mp_rank_00_model_states.pt +3 -0
- latest +1 -0
- logs/1679517173.383739/events.out.tfevents.1679517173.ip-172-31-10-160.5641.1 +3 -0
- logs/events.out.tfevents.1679517173.ip-172-31-10-160.5641.0 +3 -0
- special_tokens_map.json +107 -0
- tokenizer.json +0 -0
- tokenizer_config.json +112 -0
- train_results.json +0 -0
- trainer_state.json +166 -0
- training_args.bin +3 -0
- zero_to_fp32.py +482 -0
README.md
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
tags:
|
4 |
+
- generated_from_trainer
|
5 |
+
datasets:
|
6 |
+
- cnn_dailymail
|
7 |
+
metrics:
|
8 |
+
- rouge
|
9 |
+
model-index:
|
10 |
+
- name: flan-t5-xl
|
11 |
+
results:
|
12 |
+
- task:
|
13 |
+
name: Sequence-to-sequence Language Modeling
|
14 |
+
type: text2text-generation
|
15 |
+
dataset:
|
16 |
+
name: cnn_dailymail
|
17 |
+
type: cnn_dailymail
|
18 |
+
config: 3.0.0
|
19 |
+
split: validation
|
20 |
+
args: 3.0.0
|
21 |
+
metrics:
|
22 |
+
- name: Rouge1
|
23 |
+
type: rouge
|
24 |
+
value: 45.1318
|
25 |
+
---
|
26 |
+
|
27 |
+
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
28 |
+
should probably proofread and complete it, then remove this comment. -->
|
29 |
+
|
30 |
+
# flan-t5-xl
|
31 |
+
|
32 |
+
This model is a fine-tuned version of [google/flan-t5-xl](https://huggingface.co/google/flan-t5-xl) on the cnn_dailymail dataset.
|
33 |
+
It achieves the following results on the evaluation set:
|
34 |
+
- Loss: 1.2648
|
35 |
+
- Rouge1: 45.1318
|
36 |
+
- Rouge2: 22.2773
|
37 |
+
- Rougel: 31.9084
|
38 |
+
- Rougelsum: 42.0558
|
39 |
+
- Gen Len: 94.2332
|
40 |
+
|
41 |
+
## Model description
|
42 |
+
|
43 |
+
More information needed
|
44 |
+
|
45 |
+
## Intended uses & limitations
|
46 |
+
|
47 |
+
More information needed
|
48 |
+
|
49 |
+
## Training and evaluation data
|
50 |
+
|
51 |
+
More information needed
|
52 |
+
|
53 |
+
## Training procedure
|
54 |
+
|
55 |
+
### Training hyperparameters
|
56 |
+
|
57 |
+
The following hyperparameters were used during training:
|
58 |
+
- learning_rate: 0.0001
|
59 |
+
- train_batch_size: 24
|
60 |
+
- eval_batch_size: 24
|
61 |
+
- seed: 42
|
62 |
+
- distributed_type: multi-GPU
|
63 |
+
- num_devices: 4
|
64 |
+
- total_train_batch_size: 96
|
65 |
+
- total_eval_batch_size: 96
|
66 |
+
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
|
67 |
+
- lr_scheduler_type: linear
|
68 |
+
- num_epochs: 3
|
69 |
+
|
70 |
+
### Training results
|
71 |
+
|
72 |
+
| Training Loss | Epoch | Step | Validation Loss | Rouge1 | Rouge2 | Rougel | Rougelsum | Gen Len |
|
73 |
+
|:-------------:|:-----:|:----:|:---------------:|:-------:|:-------:|:-------:|:---------:|:--------:|
|
74 |
+
| 1.4352 | 1.0 | 2991 | 1.2645 | 43.8582 | 21.2227 | 30.7038 | 40.761 | 101.9968 |
|
75 |
+
| 1.3198 | 2.0 | 5982 | 1.2525 | 44.4594 | 21.8174 | 31.4304 | 41.4563 | 94.0733 |
|
76 |
+
| 1.2151 | 3.0 | 8973 | 1.2648 | 45.1318 | 22.2773 | 31.9084 | 42.0558 | 94.2332 |
|
77 |
+
|
78 |
+
|
79 |
+
### Framework versions
|
80 |
+
|
81 |
+
- Transformers 4.27.1
|
82 |
+
- Pytorch 2.0.0
|
83 |
+
- Datasets 2.10.1
|
84 |
+
- Tokenizers 0.13.2
|
config.json
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "google/flan-t5-xl",
|
3 |
+
"architectures": [
|
4 |
+
"T5ForConditionalGeneration"
|
5 |
+
],
|
6 |
+
"d_ff": 5120,
|
7 |
+
"d_kv": 64,
|
8 |
+
"d_model": 2048,
|
9 |
+
"decoder_start_token_id": 0,
|
10 |
+
"dense_act_fn": "gelu_new",
|
11 |
+
"dropout_rate": 0.1,
|
12 |
+
"eos_token_id": 1,
|
13 |
+
"feed_forward_proj": "gated-gelu",
|
14 |
+
"initializer_factor": 1.0,
|
15 |
+
"is_encoder_decoder": true,
|
16 |
+
"is_gated_act": true,
|
17 |
+
"layer_norm_epsilon": 1e-06,
|
18 |
+
"model_type": "t5",
|
19 |
+
"n_positions": 512,
|
20 |
+
"num_decoder_layers": 24,
|
21 |
+
"num_heads": 32,
|
22 |
+
"num_layers": 24,
|
23 |
+
"output_past": true,
|
24 |
+
"pad_token_id": 0,
|
25 |
+
"relative_attention_max_distance": 128,
|
26 |
+
"relative_attention_num_buckets": 32,
|
27 |
+
"task_specific_params": {
|
28 |
+
"summarization": {
|
29 |
+
"early_stopping": true,
|
30 |
+
"length_penalty": 2.0,
|
31 |
+
"max_length": 200,
|
32 |
+
"min_length": 30,
|
33 |
+
"no_repeat_ngram_size": 3,
|
34 |
+
"num_beams": 4,
|
35 |
+
"prefix": "summarize: "
|
36 |
+
},
|
37 |
+
"translation_en_to_de": {
|
38 |
+
"early_stopping": true,
|
39 |
+
"max_length": 300,
|
40 |
+
"num_beams": 4,
|
41 |
+
"prefix": "translate English to German: "
|
42 |
+
},
|
43 |
+
"translation_en_to_fr": {
|
44 |
+
"early_stopping": true,
|
45 |
+
"max_length": 300,
|
46 |
+
"num_beams": 4,
|
47 |
+
"prefix": "translate English to French: "
|
48 |
+
},
|
49 |
+
"translation_en_to_ro": {
|
50 |
+
"early_stopping": true,
|
51 |
+
"max_length": 300,
|
52 |
+
"num_beams": 4,
|
53 |
+
"prefix": "translate English to Romanian: "
|
54 |
+
}
|
55 |
+
},
|
56 |
+
"tie_word_embeddings": false,
|
57 |
+
"torch_dtype": "bfloat16",
|
58 |
+
"transformers_version": "4.27.1",
|
59 |
+
"use_cache": false,
|
60 |
+
"vocab_size": 32128
|
61 |
+
}
|
generation_config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"decoder_start_token_id": 0,
|
3 |
+
"eos_token_id": 1,
|
4 |
+
"pad_token_id": 0,
|
5 |
+
"transformers_version": "4.27.1",
|
6 |
+
"use_cache": false
|
7 |
+
}
|
global_step8973/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:04a96f9f792daaa8da8fac5422d0e203eb83d384c2f07a28b389c3d599a28fa5
|
3 |
+
size 8549274679
|
global_step8973/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:45c89472db470ec844cd12fd690d1f40bdf5a3f820ea2df9c66a0399446f4f28
|
3 |
+
size 8549274679
|
global_step8973/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:4a1e72ae12675553d4ce51ab7a6eaf1d7931752f7adbae5a63d740b014da7bd3
|
3 |
+
size 8549274679
|
global_step8973/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:e21153d5ffec9ed16d4345029a9628e1ef067b4a9f9bffecc1f0ac481451395e
|
3 |
+
size 8549274679
|
global_step8973/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:a4c076ab49ef40b1c8ca354553f95bf71ee26e1c34b2cef553de589e12ad8bda
|
3 |
+
size 318261
|
global_step8973/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:3727bccd266dcd563ba87519e85b2117f4f2147d962748ebe0b16f1179abf601
|
3 |
+
size 318261
|
global_step8973/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:4b05e872c199e475b8b8cf2c3081a92a2f642efbd8e4fd6ae8347e5fa0d108fd
|
3 |
+
size 318261
|
global_step8973/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:1604c30e27f7938a1de08dfba0a96c2d626ed1f7bf0f27f8377a9fd8fc35cea9
|
3 |
+
size 318261
|
latest
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
global_step8973
|
logs/1679517173.383739/events.out.tfevents.1679517173.ip-172-31-10-160.5641.1
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:192467bae6e170271c373a3d3150a7fcf7a2bfce69cf7232c9dc9c5e764ab9a0
|
3 |
+
size 6045
|
logs/events.out.tfevents.1679517173.ip-172-31-10-160.5641.0
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6fac395615d64b8b40c9264127abedcf27ff8feb15ee6ae9fd0b766fefbbb190
|
3 |
+
size 9552
|
special_tokens_map.json
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"additional_special_tokens": [
|
3 |
+
"<extra_id_0>",
|
4 |
+
"<extra_id_1>",
|
5 |
+
"<extra_id_2>",
|
6 |
+
"<extra_id_3>",
|
7 |
+
"<extra_id_4>",
|
8 |
+
"<extra_id_5>",
|
9 |
+
"<extra_id_6>",
|
10 |
+
"<extra_id_7>",
|
11 |
+
"<extra_id_8>",
|
12 |
+
"<extra_id_9>",
|
13 |
+
"<extra_id_10>",
|
14 |
+
"<extra_id_11>",
|
15 |
+
"<extra_id_12>",
|
16 |
+
"<extra_id_13>",
|
17 |
+
"<extra_id_14>",
|
18 |
+
"<extra_id_15>",
|
19 |
+
"<extra_id_16>",
|
20 |
+
"<extra_id_17>",
|
21 |
+
"<extra_id_18>",
|
22 |
+
"<extra_id_19>",
|
23 |
+
"<extra_id_20>",
|
24 |
+
"<extra_id_21>",
|
25 |
+
"<extra_id_22>",
|
26 |
+
"<extra_id_23>",
|
27 |
+
"<extra_id_24>",
|
28 |
+
"<extra_id_25>",
|
29 |
+
"<extra_id_26>",
|
30 |
+
"<extra_id_27>",
|
31 |
+
"<extra_id_28>",
|
32 |
+
"<extra_id_29>",
|
33 |
+
"<extra_id_30>",
|
34 |
+
"<extra_id_31>",
|
35 |
+
"<extra_id_32>",
|
36 |
+
"<extra_id_33>",
|
37 |
+
"<extra_id_34>",
|
38 |
+
"<extra_id_35>",
|
39 |
+
"<extra_id_36>",
|
40 |
+
"<extra_id_37>",
|
41 |
+
"<extra_id_38>",
|
42 |
+
"<extra_id_39>",
|
43 |
+
"<extra_id_40>",
|
44 |
+
"<extra_id_41>",
|
45 |
+
"<extra_id_42>",
|
46 |
+
"<extra_id_43>",
|
47 |
+
"<extra_id_44>",
|
48 |
+
"<extra_id_45>",
|
49 |
+
"<extra_id_46>",
|
50 |
+
"<extra_id_47>",
|
51 |
+
"<extra_id_48>",
|
52 |
+
"<extra_id_49>",
|
53 |
+
"<extra_id_50>",
|
54 |
+
"<extra_id_51>",
|
55 |
+
"<extra_id_52>",
|
56 |
+
"<extra_id_53>",
|
57 |
+
"<extra_id_54>",
|
58 |
+
"<extra_id_55>",
|
59 |
+
"<extra_id_56>",
|
60 |
+
"<extra_id_57>",
|
61 |
+
"<extra_id_58>",
|
62 |
+
"<extra_id_59>",
|
63 |
+
"<extra_id_60>",
|
64 |
+
"<extra_id_61>",
|
65 |
+
"<extra_id_62>",
|
66 |
+
"<extra_id_63>",
|
67 |
+
"<extra_id_64>",
|
68 |
+
"<extra_id_65>",
|
69 |
+
"<extra_id_66>",
|
70 |
+
"<extra_id_67>",
|
71 |
+
"<extra_id_68>",
|
72 |
+
"<extra_id_69>",
|
73 |
+
"<extra_id_70>",
|
74 |
+
"<extra_id_71>",
|
75 |
+
"<extra_id_72>",
|
76 |
+
"<extra_id_73>",
|
77 |
+
"<extra_id_74>",
|
78 |
+
"<extra_id_75>",
|
79 |
+
"<extra_id_76>",
|
80 |
+
"<extra_id_77>",
|
81 |
+
"<extra_id_78>",
|
82 |
+
"<extra_id_79>",
|
83 |
+
"<extra_id_80>",
|
84 |
+
"<extra_id_81>",
|
85 |
+
"<extra_id_82>",
|
86 |
+
"<extra_id_83>",
|
87 |
+
"<extra_id_84>",
|
88 |
+
"<extra_id_85>",
|
89 |
+
"<extra_id_86>",
|
90 |
+
"<extra_id_87>",
|
91 |
+
"<extra_id_88>",
|
92 |
+
"<extra_id_89>",
|
93 |
+
"<extra_id_90>",
|
94 |
+
"<extra_id_91>",
|
95 |
+
"<extra_id_92>",
|
96 |
+
"<extra_id_93>",
|
97 |
+
"<extra_id_94>",
|
98 |
+
"<extra_id_95>",
|
99 |
+
"<extra_id_96>",
|
100 |
+
"<extra_id_97>",
|
101 |
+
"<extra_id_98>",
|
102 |
+
"<extra_id_99>"
|
103 |
+
],
|
104 |
+
"eos_token": "</s>",
|
105 |
+
"pad_token": "<pad>",
|
106 |
+
"unk_token": "<unk>"
|
107 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"additional_special_tokens": [
|
3 |
+
"<extra_id_0>",
|
4 |
+
"<extra_id_1>",
|
5 |
+
"<extra_id_2>",
|
6 |
+
"<extra_id_3>",
|
7 |
+
"<extra_id_4>",
|
8 |
+
"<extra_id_5>",
|
9 |
+
"<extra_id_6>",
|
10 |
+
"<extra_id_7>",
|
11 |
+
"<extra_id_8>",
|
12 |
+
"<extra_id_9>",
|
13 |
+
"<extra_id_10>",
|
14 |
+
"<extra_id_11>",
|
15 |
+
"<extra_id_12>",
|
16 |
+
"<extra_id_13>",
|
17 |
+
"<extra_id_14>",
|
18 |
+
"<extra_id_15>",
|
19 |
+
"<extra_id_16>",
|
20 |
+
"<extra_id_17>",
|
21 |
+
"<extra_id_18>",
|
22 |
+
"<extra_id_19>",
|
23 |
+
"<extra_id_20>",
|
24 |
+
"<extra_id_21>",
|
25 |
+
"<extra_id_22>",
|
26 |
+
"<extra_id_23>",
|
27 |
+
"<extra_id_24>",
|
28 |
+
"<extra_id_25>",
|
29 |
+
"<extra_id_26>",
|
30 |
+
"<extra_id_27>",
|
31 |
+
"<extra_id_28>",
|
32 |
+
"<extra_id_29>",
|
33 |
+
"<extra_id_30>",
|
34 |
+
"<extra_id_31>",
|
35 |
+
"<extra_id_32>",
|
36 |
+
"<extra_id_33>",
|
37 |
+
"<extra_id_34>",
|
38 |
+
"<extra_id_35>",
|
39 |
+
"<extra_id_36>",
|
40 |
+
"<extra_id_37>",
|
41 |
+
"<extra_id_38>",
|
42 |
+
"<extra_id_39>",
|
43 |
+
"<extra_id_40>",
|
44 |
+
"<extra_id_41>",
|
45 |
+
"<extra_id_42>",
|
46 |
+
"<extra_id_43>",
|
47 |
+
"<extra_id_44>",
|
48 |
+
"<extra_id_45>",
|
49 |
+
"<extra_id_46>",
|
50 |
+
"<extra_id_47>",
|
51 |
+
"<extra_id_48>",
|
52 |
+
"<extra_id_49>",
|
53 |
+
"<extra_id_50>",
|
54 |
+
"<extra_id_51>",
|
55 |
+
"<extra_id_52>",
|
56 |
+
"<extra_id_53>",
|
57 |
+
"<extra_id_54>",
|
58 |
+
"<extra_id_55>",
|
59 |
+
"<extra_id_56>",
|
60 |
+
"<extra_id_57>",
|
61 |
+
"<extra_id_58>",
|
62 |
+
"<extra_id_59>",
|
63 |
+
"<extra_id_60>",
|
64 |
+
"<extra_id_61>",
|
65 |
+
"<extra_id_62>",
|
66 |
+
"<extra_id_63>",
|
67 |
+
"<extra_id_64>",
|
68 |
+
"<extra_id_65>",
|
69 |
+
"<extra_id_66>",
|
70 |
+
"<extra_id_67>",
|
71 |
+
"<extra_id_68>",
|
72 |
+
"<extra_id_69>",
|
73 |
+
"<extra_id_70>",
|
74 |
+
"<extra_id_71>",
|
75 |
+
"<extra_id_72>",
|
76 |
+
"<extra_id_73>",
|
77 |
+
"<extra_id_74>",
|
78 |
+
"<extra_id_75>",
|
79 |
+
"<extra_id_76>",
|
80 |
+
"<extra_id_77>",
|
81 |
+
"<extra_id_78>",
|
82 |
+
"<extra_id_79>",
|
83 |
+
"<extra_id_80>",
|
84 |
+
"<extra_id_81>",
|
85 |
+
"<extra_id_82>",
|
86 |
+
"<extra_id_83>",
|
87 |
+
"<extra_id_84>",
|
88 |
+
"<extra_id_85>",
|
89 |
+
"<extra_id_86>",
|
90 |
+
"<extra_id_87>",
|
91 |
+
"<extra_id_88>",
|
92 |
+
"<extra_id_89>",
|
93 |
+
"<extra_id_90>",
|
94 |
+
"<extra_id_91>",
|
95 |
+
"<extra_id_92>",
|
96 |
+
"<extra_id_93>",
|
97 |
+
"<extra_id_94>",
|
98 |
+
"<extra_id_95>",
|
99 |
+
"<extra_id_96>",
|
100 |
+
"<extra_id_97>",
|
101 |
+
"<extra_id_98>",
|
102 |
+
"<extra_id_99>"
|
103 |
+
],
|
104 |
+
"eos_token": "</s>",
|
105 |
+
"extra_ids": 100,
|
106 |
+
"model_max_length": 512,
|
107 |
+
"pad_token": "<pad>",
|
108 |
+
"sp_model_kwargs": {},
|
109 |
+
"special_tokens_map_file": "/home/arthur_huggingface_co/.cache/huggingface/hub/models--google--t5-v1_1-small/snapshots/fb7e6cba609f7bab11c614294bc04f82f613c7b1/special_tokens_map.json",
|
110 |
+
"tokenizer_class": "T5Tokenizer",
|
111 |
+
"unk_token": "<unk>"
|
112 |
+
}
|
train_results.json
ADDED
File without changes
|
trainer_state.json
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"best_metric": 1.2524826526641846,
|
3 |
+
"best_model_checkpoint": "flan-t5-xl/checkpoint-5982",
|
4 |
+
"epoch": 3.0,
|
5 |
+
"global_step": 8973,
|
6 |
+
"is_hyper_param_search": false,
|
7 |
+
"is_local_process_zero": true,
|
8 |
+
"is_world_process_zero": true,
|
9 |
+
"log_history": [
|
10 |
+
{
|
11 |
+
"epoch": 0.17,
|
12 |
+
"learning_rate": 0.0001,
|
13 |
+
"loss": 1.4987,
|
14 |
+
"step": 500
|
15 |
+
},
|
16 |
+
{
|
17 |
+
"epoch": 0.33,
|
18 |
+
"learning_rate": 0.0001,
|
19 |
+
"loss": 1.4692,
|
20 |
+
"step": 1000
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"epoch": 0.5,
|
24 |
+
"learning_rate": 0.0001,
|
25 |
+
"loss": 1.4559,
|
26 |
+
"step": 1500
|
27 |
+
},
|
28 |
+
{
|
29 |
+
"epoch": 0.67,
|
30 |
+
"learning_rate": 0.0001,
|
31 |
+
"loss": 1.4418,
|
32 |
+
"step": 2000
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"epoch": 0.84,
|
36 |
+
"learning_rate": 0.0001,
|
37 |
+
"loss": 1.4352,
|
38 |
+
"step": 2500
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"epoch": 1.0,
|
42 |
+
"eval_gen_len": 101.99678336325553,
|
43 |
+
"eval_loss": 1.264474868774414,
|
44 |
+
"eval_rouge1": 43.8582,
|
45 |
+
"eval_rouge2": 21.2227,
|
46 |
+
"eval_rougeL": 30.7038,
|
47 |
+
"eval_rougeLsum": 40.761,
|
48 |
+
"eval_runtime": 23490.726,
|
49 |
+
"eval_samples_per_second": 0.569,
|
50 |
+
"eval_steps_per_second": 0.006,
|
51 |
+
"step": 2991
|
52 |
+
},
|
53 |
+
{
|
54 |
+
"epoch": 1.0,
|
55 |
+
"learning_rate": 0.0001,
|
56 |
+
"loss": 1.426,
|
57 |
+
"step": 3000
|
58 |
+
},
|
59 |
+
{
|
60 |
+
"epoch": 1.17,
|
61 |
+
"learning_rate": 0.0001,
|
62 |
+
"loss": 1.3106,
|
63 |
+
"step": 3500
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"epoch": 1.34,
|
67 |
+
"learning_rate": 0.0001,
|
68 |
+
"loss": 1.3127,
|
69 |
+
"step": 4000
|
70 |
+
},
|
71 |
+
{
|
72 |
+
"epoch": 1.5,
|
73 |
+
"learning_rate": 0.0001,
|
74 |
+
"loss": 1.3173,
|
75 |
+
"step": 4500
|
76 |
+
},
|
77 |
+
{
|
78 |
+
"epoch": 1.67,
|
79 |
+
"learning_rate": 0.0001,
|
80 |
+
"loss": 1.3158,
|
81 |
+
"step": 5000
|
82 |
+
},
|
83 |
+
{
|
84 |
+
"epoch": 1.84,
|
85 |
+
"learning_rate": 0.0001,
|
86 |
+
"loss": 1.3198,
|
87 |
+
"step": 5500
|
88 |
+
},
|
89 |
+
{
|
90 |
+
"epoch": 2.0,
|
91 |
+
"eval_gen_len": 94.07330939557151,
|
92 |
+
"eval_loss": 1.2524826526641846,
|
93 |
+
"eval_rouge1": 44.4594,
|
94 |
+
"eval_rouge2": 21.8174,
|
95 |
+
"eval_rougeL": 31.4304,
|
96 |
+
"eval_rougeLsum": 41.4563,
|
97 |
+
"eval_runtime": 23248.3801,
|
98 |
+
"eval_samples_per_second": 0.575,
|
99 |
+
"eval_steps_per_second": 0.006,
|
100 |
+
"step": 5982
|
101 |
+
},
|
102 |
+
{
|
103 |
+
"epoch": 2.01,
|
104 |
+
"learning_rate": 0.0001,
|
105 |
+
"loss": 1.3143,
|
106 |
+
"step": 6000
|
107 |
+
},
|
108 |
+
{
|
109 |
+
"epoch": 2.17,
|
110 |
+
"learning_rate": 0.0001,
|
111 |
+
"loss": 1.1993,
|
112 |
+
"step": 6500
|
113 |
+
},
|
114 |
+
{
|
115 |
+
"epoch": 2.34,
|
116 |
+
"learning_rate": 0.0001,
|
117 |
+
"loss": 1.2054,
|
118 |
+
"step": 7000
|
119 |
+
},
|
120 |
+
{
|
121 |
+
"epoch": 2.51,
|
122 |
+
"learning_rate": 0.0001,
|
123 |
+
"loss": 1.2063,
|
124 |
+
"step": 7500
|
125 |
+
},
|
126 |
+
{
|
127 |
+
"epoch": 2.67,
|
128 |
+
"learning_rate": 0.0001,
|
129 |
+
"loss": 1.2095,
|
130 |
+
"step": 8000
|
131 |
+
},
|
132 |
+
{
|
133 |
+
"epoch": 2.84,
|
134 |
+
"learning_rate": 0.0001,
|
135 |
+
"loss": 1.2151,
|
136 |
+
"step": 8500
|
137 |
+
},
|
138 |
+
{
|
139 |
+
"epoch": 3.0,
|
140 |
+
"eval_gen_len": 94.23324356672651,
|
141 |
+
"eval_loss": 1.264769434928894,
|
142 |
+
"eval_rouge1": 45.1318,
|
143 |
+
"eval_rouge2": 22.2773,
|
144 |
+
"eval_rougeL": 31.9084,
|
145 |
+
"eval_rougeLsum": 42.0558,
|
146 |
+
"eval_runtime": 23125.233,
|
147 |
+
"eval_samples_per_second": 0.578,
|
148 |
+
"eval_steps_per_second": 0.006,
|
149 |
+
"step": 8973
|
150 |
+
},
|
151 |
+
{
|
152 |
+
"epoch": 3.0,
|
153 |
+
"step": 8973,
|
154 |
+
"total_flos": 650731472289792.0,
|
155 |
+
"train_loss": 1.326217149713028,
|
156 |
+
"train_runtime": 208860.2672,
|
157 |
+
"train_samples_per_second": 4.124,
|
158 |
+
"train_steps_per_second": 0.043
|
159 |
+
}
|
160 |
+
],
|
161 |
+
"max_steps": 8973,
|
162 |
+
"num_train_epochs": 3,
|
163 |
+
"total_flos": 650731472289792.0,
|
164 |
+
"trial_name": null,
|
165 |
+
"trial_params": null
|
166 |
+
}
|
training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7cf951de972fe571baa3291bfb74811ad14b4f1a58453c21cdd6f489bf7b2e13
|
3 |
+
size 4859
|
zero_to_fp32.py
ADDED
@@ -0,0 +1,482 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
# This script extracts fp32 consolidated weights from a zero 2 and 3 DeepSpeed checkpoints. It gets
|
4 |
+
# copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
|
5 |
+
# the future. Once extracted, the weights don't require DeepSpeed and can be used in any
|
6 |
+
# application.
|
7 |
+
#
|
8 |
+
# example: python zero_to_fp32.py . pytorch_model.bin
|
9 |
+
|
10 |
+
import argparse
|
11 |
+
import torch
|
12 |
+
import glob
|
13 |
+
import math
|
14 |
+
import os
|
15 |
+
import re
|
16 |
+
from collections import OrderedDict
|
17 |
+
|
18 |
+
# while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
|
19 |
+
# DeepSpeed data structures it has to be available in the current python environment.
|
20 |
+
from deepspeed.utils import logger
|
21 |
+
from deepspeed.checkpoint.constants import (DS_VERSION,
|
22 |
+
OPTIMIZER_STATE_DICT,
|
23 |
+
SINGLE_PARTITION_OF_FP32_GROUPS,
|
24 |
+
FP32_FLAT_GROUPS,
|
25 |
+
ZERO_STAGE,
|
26 |
+
PARTITION_COUNT,
|
27 |
+
PARAM_SHAPES,
|
28 |
+
BUFFER_NAMES)
|
29 |
+
|
30 |
+
debug = 0
|
31 |
+
|
32 |
+
# load to cpu
|
33 |
+
device = torch.device('cpu')
|
34 |
+
|
35 |
+
|
36 |
+
def atoi(text):
|
37 |
+
return int(text) if text.isdigit() else text
|
38 |
+
|
39 |
+
|
40 |
+
def natural_keys(text):
|
41 |
+
'''
|
42 |
+
alist.sort(key=natural_keys) sorts in human order
|
43 |
+
http://nedbatchelder.com/blog/200712/human_sorting.html
|
44 |
+
(See Toothy's implementation in the comments)
|
45 |
+
'''
|
46 |
+
return [atoi(c) for c in re.split(r'(\d+)', text)]
|
47 |
+
|
48 |
+
|
49 |
+
def get_model_state_file(checkpoint_dir, zero_stage):
|
50 |
+
if not os.path.isdir(checkpoint_dir):
|
51 |
+
raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
|
52 |
+
|
53 |
+
# there should be only one file
|
54 |
+
if zero_stage == 2:
|
55 |
+
file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
|
56 |
+
elif zero_stage == 3:
|
57 |
+
file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
|
58 |
+
|
59 |
+
if not os.path.exists(file):
|
60 |
+
raise FileNotFoundError(f"can't find model states file at '{file}'")
|
61 |
+
|
62 |
+
return file
|
63 |
+
|
64 |
+
|
65 |
+
def get_optim_files(checkpoint_dir):
|
66 |
+
# XXX: need to test that this simple glob rule works for multi-node setup too
|
67 |
+
optim_files = sorted(glob.glob(os.path.join(checkpoint_dir,
|
68 |
+
"*_optim_states.pt")),
|
69 |
+
key=natural_keys)
|
70 |
+
|
71 |
+
if len(optim_files) == 0:
|
72 |
+
raise FileNotFoundError(
|
73 |
+
f"can't find '*_optim_states.pt' files in directory '{checkpoint_dir}'")
|
74 |
+
|
75 |
+
return optim_files
|
76 |
+
|
77 |
+
|
78 |
+
def parse_model_state(file):
|
79 |
+
state_dict = torch.load(file, map_location=device)
|
80 |
+
|
81 |
+
if BUFFER_NAMES not in state_dict:
|
82 |
+
raise ValueError(f"{file} is not a model state checkpoint")
|
83 |
+
buffer_names = state_dict[BUFFER_NAMES]
|
84 |
+
if debug:
|
85 |
+
print("Found buffers:", buffer_names)
|
86 |
+
|
87 |
+
# recover just the buffers while restoring them to fp32 if they were saved in fp16
|
88 |
+
buffers = {
|
89 |
+
k: v.float()
|
90 |
+
for k,
|
91 |
+
v in state_dict["module"].items() if k in buffer_names
|
92 |
+
}
|
93 |
+
param_shapes = state_dict[PARAM_SHAPES]
|
94 |
+
|
95 |
+
ds_version = state_dict.get(DS_VERSION, None)
|
96 |
+
|
97 |
+
return buffers, param_shapes, ds_version
|
98 |
+
|
99 |
+
|
100 |
+
def parse_optim_states(files, ds_checkpoint_dir):
|
101 |
+
|
102 |
+
total_files = len(files)
|
103 |
+
state_dicts = []
|
104 |
+
for f in files:
|
105 |
+
state_dicts.append(torch.load(f, map_location=device))
|
106 |
+
|
107 |
+
if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
|
108 |
+
raise ValueError(f"{files[0]} is not a zero checkpoint")
|
109 |
+
zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
|
110 |
+
world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
|
111 |
+
|
112 |
+
# For ZeRO-2 each param group can have different partition_count as data parallelism for expert
|
113 |
+
# parameters can be different from data parallelism for non-expert parameters. So we can just
|
114 |
+
# use the max of the partition_count to get the dp world_size.
|
115 |
+
|
116 |
+
if type(world_size) is list:
|
117 |
+
world_size = max(world_size)
|
118 |
+
|
119 |
+
if world_size != total_files:
|
120 |
+
raise ValueError(
|
121 |
+
f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
|
122 |
+
"Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
|
123 |
+
)
|
124 |
+
|
125 |
+
# the groups are named differently in each stage
|
126 |
+
if zero_stage == 2:
|
127 |
+
fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
|
128 |
+
elif zero_stage == 3:
|
129 |
+
fp32_groups_key = FP32_FLAT_GROUPS
|
130 |
+
else:
|
131 |
+
raise ValueError(f"unknown zero stage {zero_stage}")
|
132 |
+
|
133 |
+
if zero_stage == 2:
|
134 |
+
fp32_flat_groups = [
|
135 |
+
state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key]
|
136 |
+
for i in range(len(state_dicts))
|
137 |
+
]
|
138 |
+
elif zero_stage == 3:
|
139 |
+
# if there is more than one param group, there will be multiple flattened tensors - one
|
140 |
+
# flattened tensor per group - for simplicity merge them into a single tensor
|
141 |
+
#
|
142 |
+
# XXX: could make the script more memory efficient for when there are multiple groups - it
|
143 |
+
# will require matching the sub-lists of param_shapes for each param group flattened tensor
|
144 |
+
|
145 |
+
fp32_flat_groups = [
|
146 |
+
torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key],
|
147 |
+
0) for i in range(len(state_dicts))
|
148 |
+
]
|
149 |
+
|
150 |
+
return zero_stage, world_size, fp32_flat_groups
|
151 |
+
|
152 |
+
|
153 |
+
def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir):
|
154 |
+
"""
|
155 |
+
Returns fp32 state_dict reconstructed from ds checkpoint
|
156 |
+
|
157 |
+
Args:
|
158 |
+
- ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
|
159 |
+
|
160 |
+
"""
|
161 |
+
print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
|
162 |
+
|
163 |
+
optim_files = get_optim_files(ds_checkpoint_dir)
|
164 |
+
zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
|
165 |
+
print(
|
166 |
+
f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
|
167 |
+
|
168 |
+
model_file = get_model_state_file(ds_checkpoint_dir, zero_stage)
|
169 |
+
buffers, param_shapes, ds_version = parse_model_state(model_file)
|
170 |
+
print(f'Parsing checkpoint created by deepspeed=={ds_version}')
|
171 |
+
|
172 |
+
if zero_stage == 2:
|
173 |
+
return _get_fp32_state_dict_from_zero2_checkpoint(world_size,
|
174 |
+
param_shapes,
|
175 |
+
fp32_flat_groups,
|
176 |
+
buffers)
|
177 |
+
elif zero_stage == 3:
|
178 |
+
return _get_fp32_state_dict_from_zero3_checkpoint(world_size,
|
179 |
+
param_shapes,
|
180 |
+
fp32_flat_groups,
|
181 |
+
buffers)
|
182 |
+
|
183 |
+
|
184 |
+
def _get_fp32_state_dict_from_zero2_checkpoint(world_size,
|
185 |
+
param_shapes,
|
186 |
+
fp32_flat_groups,
|
187 |
+
buffers):
|
188 |
+
|
189 |
+
# Reconstruction protocol:
|
190 |
+
#
|
191 |
+
# XXX: document this
|
192 |
+
|
193 |
+
if debug:
|
194 |
+
for i in range(world_size):
|
195 |
+
for j in range(len(fp32_flat_groups[0])):
|
196 |
+
print(
|
197 |
+
f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
|
198 |
+
|
199 |
+
# XXX: memory usage doubles here (zero2)
|
200 |
+
num_param_groups = len(fp32_flat_groups[0])
|
201 |
+
merged_single_partition_of_fp32_groups = []
|
202 |
+
for i in range(num_param_groups):
|
203 |
+
merged_partitions = [sd[i] for sd in fp32_flat_groups]
|
204 |
+
full_single_fp32_vector = torch.cat(merged_partitions, 0)
|
205 |
+
merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
|
206 |
+
avail_numel = sum([
|
207 |
+
full_single_fp32_vector.numel()
|
208 |
+
for full_single_fp32_vector in merged_single_partition_of_fp32_groups
|
209 |
+
])
|
210 |
+
|
211 |
+
if debug:
|
212 |
+
wanted_params = sum([len(shapes) for shapes in param_shapes])
|
213 |
+
wanted_numel = sum(
|
214 |
+
[sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
|
215 |
+
# not asserting if there is a mismatch due to possible padding
|
216 |
+
print(f"Have {avail_numel} numels to process.")
|
217 |
+
print(f"Need {wanted_numel} numels in {wanted_params} params.")
|
218 |
+
|
219 |
+
state_dict = OrderedDict()
|
220 |
+
|
221 |
+
# buffers
|
222 |
+
state_dict.update(buffers)
|
223 |
+
if debug:
|
224 |
+
print(f"added {len(buffers)} buffers")
|
225 |
+
|
226 |
+
# params
|
227 |
+
# XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
|
228 |
+
# out-of-core computing solution
|
229 |
+
total_numel = 0
|
230 |
+
total_params = 0
|
231 |
+
for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
|
232 |
+
offset = 0
|
233 |
+
avail_numel = full_single_fp32_vector.numel()
|
234 |
+
for name, shape in shapes.items():
|
235 |
+
|
236 |
+
unpartitioned_numel = shape.numel()
|
237 |
+
total_numel += unpartitioned_numel
|
238 |
+
total_params += 1
|
239 |
+
|
240 |
+
if debug:
|
241 |
+
print(
|
242 |
+
f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} "
|
243 |
+
)
|
244 |
+
state_dict[name] = full_single_fp32_vector.narrow(
|
245 |
+
0,
|
246 |
+
offset,
|
247 |
+
unpartitioned_numel).view(shape)
|
248 |
+
offset += unpartitioned_numel
|
249 |
+
|
250 |
+
# Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
|
251 |
+
# avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
|
252 |
+
# paddings performed in the code it's almost impossible to predict the exact numbers w/o the
|
253 |
+
# live optimizer object, so we are checking that the numbers are within the right range
|
254 |
+
align_to = 2 * world_size
|
255 |
+
|
256 |
+
def zero2_align(x):
|
257 |
+
return align_to * math.ceil(x / align_to)
|
258 |
+
|
259 |
+
if debug:
|
260 |
+
print(f"original offset={offset}, avail_numel={avail_numel}")
|
261 |
+
|
262 |
+
offset = zero2_align(offset)
|
263 |
+
avail_numel = zero2_align(avail_numel)
|
264 |
+
|
265 |
+
if debug:
|
266 |
+
print(f"aligned offset={offset}, avail_numel={avail_numel}")
|
267 |
+
|
268 |
+
# Sanity check
|
269 |
+
if offset != avail_numel:
|
270 |
+
raise ValueError(
|
271 |
+
f"consumed {offset} numels out of {avail_numel} - something is wrong")
|
272 |
+
|
273 |
+
print(
|
274 |
+
f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements"
|
275 |
+
)
|
276 |
+
|
277 |
+
return state_dict
|
278 |
+
|
279 |
+
|
280 |
+
def zero3_partitioned_param_info(unpartitioned_numel, world_size):
|
281 |
+
remainder = unpartitioned_numel % world_size
|
282 |
+
padding_numel = (world_size - remainder) if remainder else 0
|
283 |
+
partitioned_numel = math.ceil(unpartitioned_numel / world_size)
|
284 |
+
return partitioned_numel, padding_numel
|
285 |
+
|
286 |
+
|
287 |
+
def _get_fp32_state_dict_from_zero3_checkpoint(world_size,
|
288 |
+
param_shapes,
|
289 |
+
fp32_flat_groups,
|
290 |
+
buffers):
|
291 |
+
|
292 |
+
# Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
|
293 |
+
# param, re-consolidating each param, while dealing with padding if any
|
294 |
+
|
295 |
+
avail_numel = fp32_flat_groups[0].numel() * world_size
|
296 |
+
# merge list of dicts, preserving order
|
297 |
+
param_shapes = {k: v for d in param_shapes for k, v in d.items()}
|
298 |
+
|
299 |
+
if debug:
|
300 |
+
for i in range(world_size):
|
301 |
+
print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
|
302 |
+
|
303 |
+
wanted_params = len(param_shapes)
|
304 |
+
wanted_numel = sum(shape.numel() for shape in param_shapes.values())
|
305 |
+
# not asserting if there is a mismatch due to possible padding
|
306 |
+
print(f"Have {avail_numel} numels to process.")
|
307 |
+
print(f"Need {wanted_numel} numels in {wanted_params} params.")
|
308 |
+
|
309 |
+
state_dict = OrderedDict()
|
310 |
+
|
311 |
+
# buffers
|
312 |
+
state_dict.update(buffers)
|
313 |
+
if debug:
|
314 |
+
print(f"added {len(buffers)} buffers")
|
315 |
+
|
316 |
+
# params
|
317 |
+
# XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
|
318 |
+
# out-of-core computing solution
|
319 |
+
offset = 0
|
320 |
+
total_numel = 0
|
321 |
+
total_params = 0
|
322 |
+
for name, shape in param_shapes.items():
|
323 |
+
|
324 |
+
unpartitioned_numel = shape.numel()
|
325 |
+
total_numel += unpartitioned_numel
|
326 |
+
total_params += 1
|
327 |
+
|
328 |
+
partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
|
329 |
+
|
330 |
+
if debug:
|
331 |
+
print(
|
332 |
+
f"{total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
|
333 |
+
)
|
334 |
+
|
335 |
+
# XXX: memory usage doubles here
|
336 |
+
state_dict[name] = torch.cat(
|
337 |
+
tuple(fp32_flat_groups[i].narrow(0,
|
338 |
+
offset,
|
339 |
+
partitioned_numel)
|
340 |
+
for i in range(world_size)),
|
341 |
+
0).narrow(0,
|
342 |
+
0,
|
343 |
+
unpartitioned_numel).view(shape)
|
344 |
+
offset += partitioned_numel
|
345 |
+
|
346 |
+
offset *= world_size
|
347 |
+
|
348 |
+
# Sanity check
|
349 |
+
if offset != avail_numel:
|
350 |
+
raise ValueError(
|
351 |
+
f"consumed {offset} numels out of {avail_numel} - something is wrong")
|
352 |
+
|
353 |
+
print(
|
354 |
+
f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements"
|
355 |
+
)
|
356 |
+
|
357 |
+
return state_dict
|
358 |
+
|
359 |
+
|
360 |
+
def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None):
|
361 |
+
"""
|
362 |
+
Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
|
363 |
+
``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
|
364 |
+
via a model hub.
|
365 |
+
|
366 |
+
Args:
|
367 |
+
- ``checkpoint_dir``: path to the desired checkpoint folder
|
368 |
+
- ``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``
|
369 |
+
|
370 |
+
Returns:
|
371 |
+
- pytorch ``state_dict``
|
372 |
+
|
373 |
+
Note: this approach may not work if your application doesn't have sufficient free CPU memory and
|
374 |
+
you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
|
375 |
+
the checkpoint.
|
376 |
+
|
377 |
+
A typical usage might be ::
|
378 |
+
|
379 |
+
from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
|
380 |
+
# do the training and checkpoint saving
|
381 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
|
382 |
+
model = model.cpu() # move to cpu
|
383 |
+
model.load_state_dict(state_dict)
|
384 |
+
# submit to model hub or save the model to share with others
|
385 |
+
|
386 |
+
In this example the ``model`` will no longer be usable in the deepspeed context of the same
|
387 |
+
application. i.e. you will need to re-initialize the deepspeed engine, since
|
388 |
+
``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
|
389 |
+
|
390 |
+
If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
|
391 |
+
|
392 |
+
"""
|
393 |
+
if tag is None:
|
394 |
+
latest_path = os.path.join(checkpoint_dir, 'latest')
|
395 |
+
if os.path.isfile(latest_path):
|
396 |
+
with open(latest_path, 'r') as fd:
|
397 |
+
tag = fd.read().strip()
|
398 |
+
else:
|
399 |
+
raise ValueError(f"Unable to find 'latest' file at {latest_path}")
|
400 |
+
|
401 |
+
ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
|
402 |
+
|
403 |
+
if not os.path.isdir(ds_checkpoint_dir):
|
404 |
+
raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
|
405 |
+
|
406 |
+
return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir)
|
407 |
+
|
408 |
+
|
409 |
+
def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file, tag=None):
|
410 |
+
"""
|
411 |
+
Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
|
412 |
+
loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
|
413 |
+
|
414 |
+
Args:
|
415 |
+
- ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
|
416 |
+
- ``output_file``: path to the pytorch fp32 state_dict output file (e.g. path/pytorch_model.bin)
|
417 |
+
- ``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``
|
418 |
+
"""
|
419 |
+
|
420 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
|
421 |
+
print(f"Saving fp32 state dict to {output_file}")
|
422 |
+
torch.save(state_dict, output_file)
|
423 |
+
|
424 |
+
|
425 |
+
def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
|
426 |
+
"""
|
427 |
+
1. Put the provided model to cpu
|
428 |
+
2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
|
429 |
+
3. Load it into the provided model
|
430 |
+
|
431 |
+
Args:
|
432 |
+
- ``model``: the model object to update
|
433 |
+
- ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
|
434 |
+
- ``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``
|
435 |
+
|
436 |
+
Returns:
|
437 |
+
- ``model`: modified model
|
438 |
+
|
439 |
+
Make sure you have plenty of CPU memory available before you call this function. If you don't
|
440 |
+
have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
|
441 |
+
conveniently placed for you in the checkpoint folder.
|
442 |
+
|
443 |
+
A typical usage might be ::
|
444 |
+
|
445 |
+
from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
|
446 |
+
model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
|
447 |
+
# submit to model hub or save the model to share with others
|
448 |
+
|
449 |
+
Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
|
450 |
+
of the same application. i.e. you will need to re-initialize the deepspeed engine, since
|
451 |
+
``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
|
452 |
+
|
453 |
+
"""
|
454 |
+
logger.info(f"Extracting fp32 weights")
|
455 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
|
456 |
+
|
457 |
+
logger.info(f"Overwriting model with fp32 weights")
|
458 |
+
model = model.cpu()
|
459 |
+
model.load_state_dict(state_dict, strict=False)
|
460 |
+
|
461 |
+
return model
|
462 |
+
|
463 |
+
|
464 |
+
if __name__ == "__main__":
|
465 |
+
|
466 |
+
parser = argparse.ArgumentParser()
|
467 |
+
parser.add_argument(
|
468 |
+
"checkpoint_dir",
|
469 |
+
type=str,
|
470 |
+
help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
|
471 |
+
parser.add_argument(
|
472 |
+
"output_file",
|
473 |
+
type=str,
|
474 |
+
help=
|
475 |
+
"path to the pytorch fp32 state_dict output file (e.g. path/checkpoint-12/pytorch_model.bin)"
|
476 |
+
)
|
477 |
+
parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
|
478 |
+
args = parser.parse_args()
|
479 |
+
|
480 |
+
debug = args.debug
|
481 |
+
|
482 |
+
convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir, args.output_file)
|