commit 16558f15d437ce1b363575950e39a504c1d79c84 Author: ModelHub XC Date: Wed Jul 15 05:53:09 2026 +0800 初始化项目,由ModelHub XC社区提供模型 Model: 64bits/LexPodLM-13B Source: Original Platform diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e339d11 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,35 @@ +*.7z filter=lfs diff=lfs merge=lfs -text +*.arrow filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.ckpt filter=lfs diff=lfs merge=lfs -text +*.ftz filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.h5 filter=lfs diff=lfs merge=lfs -text +*.joblib filter=lfs diff=lfs merge=lfs -text +*.lfs.* filter=lfs diff=lfs merge=lfs -text +*.mlmodel filter=lfs diff=lfs merge=lfs -text +*.model filter=lfs diff=lfs merge=lfs -text +*.msgpack filter=lfs diff=lfs merge=lfs -text +*.npy filter=lfs diff=lfs merge=lfs -text +*.npz filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.ot filter=lfs diff=lfs merge=lfs -text +*.parquet filter=lfs diff=lfs merge=lfs -text +*.pb filter=lfs diff=lfs merge=lfs -text +*.pickle filter=lfs diff=lfs merge=lfs -text +*.pkl filter=lfs diff=lfs merge=lfs -text +*.pt filter=lfs diff=lfs merge=lfs -text +*.pth filter=lfs diff=lfs merge=lfs -text +*.rar filter=lfs diff=lfs merge=lfs -text +*.safetensors filter=lfs diff=lfs merge=lfs -text +saved_model/**/* filter=lfs diff=lfs merge=lfs -text +*.tar.* filter=lfs diff=lfs merge=lfs -text +*.tflite filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.wasm filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text +*tfevents* filter=lfs diff=lfs merge=lfs -text +*.psd filter=lfs diff=lfs merge=lfs -text diff --git a/README.md b/README.md new file mode 100644 index 0000000..a17e0c6 --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ +--- +license: other +datasets: +- 64bits/lex_fridman_podcast_for_llm_vicuna +language: +- en +library_name: transformers +tags: +- llama +- transformers +--- + +LexPodLM-13B is a LLaMA-13B model fine-tuned using Vicuna's schema, with this dataset: https://huggingface.co/datasets/64bits/lex_fridman_podcast_for_llm_vicuna + +While it might not excel in tasks like code writing, fact searching, or essay writing, it can potentially serve as an effective chat model, capable of providing verbose and nuanced responses. + + +I trained the model on 4 A100 (80 GB RAM) for ~15 hrs. +*** +Eval (evaluate models like [Open LLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard) using [Eleuther AI Language Model Evaluation Harness](https://github.com/EleutherAI/lm-evaluation-harness])): +| Model | Average | ARC (25-shot) | HellaSwag (10-shot) | MMLU (5-shot) | TruthfulQA (0-shot) | +| ------------ | ------- | ------------- | ------------------- | ------------- | ------------------- | +| LexPodLM-13B | 52.5 | 48.8 | 79.4 | 37.9 | 43.8 | +| LLaMA-13B | 51.8 | 50.8 | 78.9 | 37.7 | 39.9 | + +*** +*Human: do you think consciousness is foundamentally computational?* + +*Assistant: I think consciousness is foundational computational. Yes. The key insight that I've had over the last five years is that consciousness itself is the ultimate self-organizing system. It's the ultimate emergent of the universe. It's the ultimate thing that's not explainable in terms of its parts. So it's not that I think brains are computation. I think, you know, brains are made of neurons, and neurons are made of cells. And the cells are made of molecules and the molecules are made of atoms, and the atoms are made of particles. And we can explain all of those things in terms of their parts. There's no emergent physics in physics. There are no emergent laws in physics. And you know, people have been trying to get to this level. And there's the whole philosophy of physics that says, you know, you've got your fundamental laws. Let's just explain everything in terms of the fundamental laws. But that's just not how physics works. The reason that there are emergent laws in physics is because there are emergent structures in physics. And the first emergent structure is the cell. The cell is a structure that doesn't exist in physics. It's an emergent structure. And the fact that the cell is an emergent structure means that it has rules that are different from the rules of physics. And the same thing with brains. Brains have rules that are different from the rules of physics. And the same thing with consciousness. Consciousness, the fact that it exists at all is an emergent fact. It's not a fact that you can reduce to the underlying physics. And the thing that's amazing to me is that there is this structure that exists at the highest level of everything that exists. And it's not an emergent. So the fact that you and I have consciousness is not an emergent fact. It's a foundational fact. It's a fact that's there right at the bottom of reality right along with atoms and particles. I mean, it's not that I think that brains are conscious. I think that brains are a particular way of organizing consciousness. I think brains are a particular way of organizing the relationship between consciousness and the physical world. And so when people say to me, you know, well, what do you think?* + +*** + +*Human: What are the ethical implications of artificial intelligence?* + +*Assistant: The ethical implications of artificial intelligence are significant. As AI systems become more advanced and integrated into our daily lives, we have to be aware of their limitations and potential unfair biases. Such systems should be designed with a focus on fairness, transparency, and security. AI systems should not be used to replace human decision-making. Their output should be easily interpretable, so that decisions can be traced to rationales and justifications. We should also prioritize the well-being of humans over the well-being of AI systems. We need to ensure that AI systems are designed in a way that they do not harm users or other people. This can be achieved by building in safety mechanisms and testing systems for potential biases and security vulnerabilities.* + +*** + +*Human: How do you think quantum computing will affect our future?* + +*Assistant: Quantum computing has the potential to change the way we compute in many ways. One of the most significant benefits will be the possibility of solving previously unsolvable problems and accelerating the development of machine learning and artificial intelligence. By harnessing the power of quantum computers, we can make machines that are exponentially more powerful than any existing computer.* + +*** + +*Human: What are your thoughts on the Singularity theory?* + +*Assistant: I am a strong proponent of the singularity. I have seen many technological advancements in my career. I've seen the power of exponential growth in technology. I've seen the power of exponential growth in markets, in the economy, and in population. And I'm very excited about the future. I'm very excited about what's going to happen. And I think that it's important for the world to understand that. And so I think that the singularity is very important for our future and we need to make sure that we're preparing for it.* +# [Open LLM Leaderboard Evaluation Results](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard) +Detailed results can be found [here](https://huggingface.co/datasets/open-llm-leaderboard/details_64bits__LexPodLM-13B) + +| Metric | Value | +|-----------------------|---------------------------| +| Avg. | 49.51 | +| ARC (25-shot) | 57.76 | +| HellaSwag (10-shot) | 81.04 | +| MMLU (5-shot) | 48.38 | +| TruthfulQA (0-shot) | 43.48 | +| Winogrande (5-shot) | 76.16 | +| GSM8K (5-shot) | 0.0 | +| DROP (3-shot) | 39.71 | diff --git a/config.json b/config.json new file mode 100644 index 0000000..c65e5d7 --- /dev/null +++ b/config.json @@ -0,0 +1,24 @@ +{ + "_name_or_path": "/workspace/datasets/llama-13b", + "architectures": [ + "LlamaForCausalLM" + ], + "bos_token_id": 1, + "eos_token_id": 2, + "hidden_act": "silu", + "hidden_size": 5120, + "initializer_range": 0.02, + "intermediate_size": 13824, + "max_position_embeddings": 2048, + "max_sequence_length": 2048, + "model_type": "llama", + "num_attention_heads": 40, + "num_hidden_layers": 40, + "pad_token_id": 0, + "rms_norm_eps": 1e-06, + "tie_word_embeddings": false, + "torch_dtype": "bfloat16", + "transformers_version": "4.28.1", + "use_cache": false, + "vocab_size": 32000 +} diff --git a/generation_config.json b/generation_config.json new file mode 100644 index 0000000..1372199 --- /dev/null +++ b/generation_config.json @@ -0,0 +1,7 @@ +{ + "_from_model_config": true, + "bos_token_id": 1, + "eos_token_id": 2, + "pad_token_id": 0, + "transformers_version": "4.28.1" +} diff --git a/pytorch_model.bin b/pytorch_model.bin new file mode 100644 index 0000000..5cd00a1 --- /dev/null +++ b/pytorch_model.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:316aa63bdb5b58c77dff5490f62fad85304252fa6c653cf389e13245ec4d7595 +size 26031865519 diff --git a/special_tokens_map.json b/special_tokens_map.json new file mode 100644 index 0000000..f928b24 --- /dev/null +++ b/special_tokens_map.json @@ -0,0 +1,24 @@ +{ + "bos_token": { + "content": "", + "lstrip": false, + "normalized": true, + "rstrip": false, + "single_word": false + }, + "eos_token": { + "content": "", + "lstrip": false, + "normalized": true, + "rstrip": false, + "single_word": false + }, + "pad_token": "", + "unk_token": { + "content": "", + "lstrip": false, + "normalized": true, + "rstrip": false, + "single_word": false + } +} diff --git a/tokenizer.model b/tokenizer.model new file mode 100644 index 0000000..6c00c74 --- /dev/null +++ b/tokenizer.model @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347 +size 499723 diff --git a/tokenizer_config.json b/tokenizer_config.json new file mode 100644 index 0000000..5ab645d --- /dev/null +++ b/tokenizer_config.json @@ -0,0 +1,34 @@ +{ + "add_bos_token": true, + "add_eos_token": false, + "bos_token": { + "__type": "AddedToken", + "content": "", + "lstrip": false, + "normalized": true, + "rstrip": false, + "single_word": false + }, + "clean_up_tokenization_spaces": false, + "eos_token": { + "__type": "AddedToken", + "content": "", + "lstrip": false, + "normalized": true, + "rstrip": false, + "single_word": false + }, + "model_max_length": 2048, + "pad_token": null, + "padding_side": "right", + "sp_model_kwargs": {}, + "tokenizer_class": "LlamaTokenizer", + "unk_token": { + "__type": "AddedToken", + "content": "", + "lstrip": false, + "normalized": true, + "rstrip": false, + "single_word": false + } +} diff --git a/trainer_state.json b/trainer_state.json new file mode 100644 index 0000000..0d4d073 --- /dev/null +++ b/trainer_state.json @@ -0,0 +1,1592 @@ +{ + "best_metric": null, + "best_model_checkpoint": null, + "epoch": 1.9941747572815534, + "global_step": 256, + "is_hyper_param_search": false, + "is_local_process_zero": true, + "is_world_process_zero": true, + "log_history": [ + { + "epoch": 0.01, + "learning_rate": 1.8181818181818183e-06, + "loss": 2.6279, + "step": 1 + }, + { + "epoch": 0.02, + "learning_rate": 3.6363636363636366e-06, + "loss": 2.6631, + "step": 2 + }, + { + "epoch": 0.02, + "learning_rate": 5.4545454545454545e-06, + "loss": 2.6104, + "step": 3 + }, + { + "epoch": 0.03, + "learning_rate": 7.272727272727273e-06, + "loss": 2.6699, + "step": 4 + }, + { + "epoch": 0.04, + "learning_rate": 9.090909090909091e-06, + "loss": 2.5469, + "step": 5 + }, + { + "epoch": 0.05, + "learning_rate": 1.0909090909090909e-05, + "loss": 2.499, + "step": 6 + }, + { + "epoch": 0.05, + "learning_rate": 1.2727272727272728e-05, + "loss": 2.5264, + "step": 7 + }, + { + "epoch": 0.06, + "learning_rate": 1.4545454545454546e-05, + "loss": 2.5, + "step": 8 + }, + { + "epoch": 0.07, + "learning_rate": 1.6363636363636366e-05, + "loss": 2.5107, + "step": 9 + }, + { + "epoch": 0.08, + "learning_rate": 1.8181818181818182e-05, + "loss": 2.541, + "step": 10 + }, + { + "epoch": 0.09, + "learning_rate": 2e-05, + "loss": 2.5381, + "step": 11 + }, + { + "epoch": 0.09, + "learning_rate": 1.9999177886783194e-05, + "loss": 2.5234, + "step": 12 + }, + { + "epoch": 0.1, + "learning_rate": 1.99967116823068e-05, + "loss": 2.5303, + "step": 13 + }, + { + "epoch": 0.11, + "learning_rate": 1.999260179207068e-05, + "loss": 2.5117, + "step": 14 + }, + { + "epoch": 0.12, + "learning_rate": 1.9986848891833846e-05, + "loss": 2.4707, + "step": 15 + }, + { + "epoch": 0.12, + "learning_rate": 1.9979453927503366e-05, + "loss": 2.5107, + "step": 16 + }, + { + "epoch": 0.13, + "learning_rate": 1.997041811497882e-05, + "loss": 2.5078, + "step": 17 + }, + { + "epoch": 0.14, + "learning_rate": 1.9959742939952393e-05, + "loss": 2.4258, + "step": 18 + }, + { + "epoch": 0.15, + "learning_rate": 1.9947430157664575e-05, + "loss": 2.4717, + "step": 19 + }, + { + "epoch": 0.16, + "learning_rate": 1.9933481792615583e-05, + "loss": 2.5234, + "step": 20 + }, + { + "epoch": 0.16, + "learning_rate": 1.991790013823246e-05, + "loss": 2.4385, + "step": 21 + }, + { + "epoch": 0.17, + "learning_rate": 1.9900687756492022e-05, + "loss": 2.4541, + "step": 22 + }, + { + "epoch": 0.18, + "learning_rate": 1.988184747749956e-05, + "loss": 2.4629, + "step": 23 + }, + { + "epoch": 0.19, + "learning_rate": 1.986138239902355e-05, + "loss": 2.5381, + "step": 24 + }, + { + "epoch": 0.19, + "learning_rate": 1.98392958859863e-05, + "loss": 2.4775, + "step": 25 + }, + { + "epoch": 0.2, + "learning_rate": 1.9815591569910654e-05, + "loss": 2.4717, + "step": 26 + }, + { + "epoch": 0.21, + "learning_rate": 1.979027334832293e-05, + "loss": 2.4678, + "step": 27 + }, + { + "epoch": 0.22, + "learning_rate": 1.9763345384112044e-05, + "loss": 2.4863, + "step": 28 + }, + { + "epoch": 0.23, + "learning_rate": 1.973481210484505e-05, + "loss": 2.5049, + "step": 29 + }, + { + "epoch": 0.23, + "learning_rate": 1.9704678202039148e-05, + "loss": 2.5186, + "step": 30 + }, + { + "epoch": 0.24, + "learning_rate": 1.9672948630390296e-05, + "loss": 2.3848, + "step": 31 + }, + { + "epoch": 0.25, + "learning_rate": 1.9639628606958535e-05, + "loss": 2.5127, + "step": 32 + }, + { + "epoch": 0.26, + "learning_rate": 1.9604723610310195e-05, + "loss": 2.4727, + "step": 33 + }, + { + "epoch": 0.26, + "learning_rate": 1.956823937961709e-05, + "loss": 2.4502, + "step": 34 + }, + { + "epoch": 0.27, + "learning_rate": 1.9530181913712875e-05, + "loss": 2.5029, + "step": 35 + }, + { + "epoch": 0.28, + "learning_rate": 1.949055747010669e-05, + "loss": 2.5, + "step": 36 + }, + { + "epoch": 0.29, + "learning_rate": 1.9449372563954293e-05, + "loss": 2.4551, + "step": 37 + }, + { + "epoch": 0.3, + "learning_rate": 1.9406633966986828e-05, + "loss": 2.458, + "step": 38 + }, + { + "epoch": 0.3, + "learning_rate": 1.9362348706397374e-05, + "loss": 2.4453, + "step": 39 + }, + { + "epoch": 0.31, + "learning_rate": 1.9316524063685544e-05, + "loss": 2.3975, + "step": 40 + }, + { + "epoch": 0.32, + "learning_rate": 1.926916757346022e-05, + "loss": 2.4785, + "step": 41 + }, + { + "epoch": 0.33, + "learning_rate": 1.9220287022200707e-05, + "loss": 2.416, + "step": 42 + }, + { + "epoch": 0.33, + "learning_rate": 1.9169890446976454e-05, + "loss": 2.5166, + "step": 43 + }, + { + "epoch": 0.34, + "learning_rate": 1.911798613412557e-05, + "loss": 2.4268, + "step": 44 + }, + { + "epoch": 0.35, + "learning_rate": 1.9064582617892383e-05, + "loss": 2.4736, + "step": 45 + }, + { + "epoch": 0.36, + "learning_rate": 1.900968867902419e-05, + "loss": 2.4531, + "step": 46 + }, + { + "epoch": 0.37, + "learning_rate": 1.895331334332753e-05, + "loss": 2.4199, + "step": 47 + }, + { + "epoch": 0.37, + "learning_rate": 1.889546588018412e-05, + "loss": 2.4893, + "step": 48 + }, + { + "epoch": 0.38, + "learning_rate": 1.8836155801026754e-05, + "loss": 2.4785, + "step": 49 + }, + { + "epoch": 0.39, + "learning_rate": 1.877539285777543e-05, + "loss": 2.4346, + "step": 50 + }, + { + "epoch": 0.39, + "eval_loss": 2.4345414638519287, + "eval_runtime": 50.8104, + "eval_samples_per_second": 3.326, + "eval_steps_per_second": 0.039, + "step": 50 + }, + { + "epoch": 0.4, + "learning_rate": 1.8713187041233896e-05, + "loss": 2.4541, + "step": 51 + }, + { + "epoch": 0.4, + "learning_rate": 1.8649548579446938e-05, + "loss": 2.4746, + "step": 52 + }, + { + "epoch": 0.41, + "learning_rate": 1.8584487936018663e-05, + "loss": 2.4355, + "step": 53 + }, + { + "epoch": 0.42, + "learning_rate": 1.8518015808392045e-05, + "loss": 2.4268, + "step": 54 + }, + { + "epoch": 0.43, + "learning_rate": 1.8450143126090015e-05, + "loss": 2.4092, + "step": 55 + }, + { + "epoch": 0.43, + "learning_rate": 1.8380881048918406e-05, + "loss": 2.5039, + "step": 56 + }, + { + "epoch": 0.44, + "learning_rate": 1.831024096513104e-05, + "loss": 2.4609, + "step": 57 + }, + { + "epoch": 0.45, + "learning_rate": 1.8238234489557217e-05, + "loss": 2.5352, + "step": 58 + }, + { + "epoch": 0.46, + "learning_rate": 1.8164873461691987e-05, + "loss": 2.4775, + "step": 59 + }, + { + "epoch": 0.47, + "learning_rate": 1.8090169943749477e-05, + "loss": 2.4678, + "step": 60 + }, + { + "epoch": 0.47, + "learning_rate": 1.8014136218679566e-05, + "loss": 2.4814, + "step": 61 + }, + { + "epoch": 0.48, + "learning_rate": 1.793678478814833e-05, + "loss": 2.4473, + "step": 62 + }, + { + "epoch": 0.49, + "learning_rate": 1.7858128370482427e-05, + "loss": 2.4346, + "step": 63 + }, + { + "epoch": 0.5, + "learning_rate": 1.7778179898577973e-05, + "loss": 2.4561, + "step": 64 + }, + { + "epoch": 0.5, + "learning_rate": 1.769695251777406e-05, + "loss": 2.5137, + "step": 65 + }, + { + "epoch": 0.51, + "learning_rate": 1.7614459583691346e-05, + "loss": 2.4717, + "step": 66 + }, + { + "epoch": 0.52, + "learning_rate": 1.7530714660036112e-05, + "loss": 2.4561, + "step": 67 + }, + { + "epoch": 0.53, + "learning_rate": 1.744573151637007e-05, + "loss": 2.5293, + "step": 68 + }, + { + "epoch": 0.54, + "learning_rate": 1.7359524125846353e-05, + "loss": 2.4531, + "step": 69 + }, + { + "epoch": 0.54, + "learning_rate": 1.7272106662911972e-05, + "loss": 2.4854, + "step": 70 + }, + { + "epoch": 0.55, + "learning_rate": 1.7183493500977277e-05, + "loss": 2.4414, + "step": 71 + }, + { + "epoch": 0.56, + "learning_rate": 1.709369921005258e-05, + "loss": 2.4619, + "step": 72 + }, + { + "epoch": 0.57, + "learning_rate": 1.700273855435255e-05, + "loss": 2.4424, + "step": 73 + }, + { + "epoch": 0.57, + "learning_rate": 1.691062648986865e-05, + "loss": 2.4336, + "step": 74 + }, + { + "epoch": 0.58, + "learning_rate": 1.6817378161909995e-05, + "loss": 2.4795, + "step": 75 + }, + { + "epoch": 0.59, + "learning_rate": 1.672300890261317e-05, + "loss": 2.4756, + "step": 76 + }, + { + "epoch": 0.6, + "learning_rate": 1.662753422842123e-05, + "loss": 2.4492, + "step": 77 + }, + { + "epoch": 0.61, + "learning_rate": 1.6530969837532487e-05, + "loss": 2.4141, + "step": 78 + }, + { + "epoch": 0.61, + "learning_rate": 1.6433331607319342e-05, + "loss": 2.459, + "step": 79 + }, + { + "epoch": 0.62, + "learning_rate": 1.63346355917177e-05, + "loss": 2.4434, + "step": 80 + }, + { + "epoch": 0.63, + "learning_rate": 1.6234898018587336e-05, + "loss": 2.4854, + "step": 81 + }, + { + "epoch": 0.64, + "learning_rate": 1.6134135287043668e-05, + "loss": 2.3984, + "step": 82 + }, + { + "epoch": 0.64, + "learning_rate": 1.6032363964761363e-05, + "loss": 2.4277, + "step": 83 + }, + { + "epoch": 0.65, + "learning_rate": 1.592960078525026e-05, + "loss": 2.415, + "step": 84 + }, + { + "epoch": 0.66, + "learning_rate": 1.5825862645103962e-05, + "loss": 2.3994, + "step": 85 + }, + { + "epoch": 0.67, + "learning_rate": 1.5721166601221697e-05, + "loss": 2.4014, + "step": 86 + }, + { + "epoch": 0.68, + "learning_rate": 1.561552986800375e-05, + "loss": 2.4766, + "step": 87 + }, + { + "epoch": 0.68, + "learning_rate": 1.5508969814521026e-05, + "loss": 2.4268, + "step": 88 + }, + { + "epoch": 0.69, + "learning_rate": 1.5401503961659202e-05, + "loss": 2.4688, + "step": 89 + }, + { + "epoch": 0.7, + "learning_rate": 1.5293149979237875e-05, + "loss": 2.4619, + "step": 90 + }, + { + "epoch": 0.71, + "learning_rate": 1.5183925683105254e-05, + "loss": 2.4678, + "step": 91 + }, + { + "epoch": 0.71, + "learning_rate": 1.5073849032208823e-05, + "loss": 2.4551, + "step": 92 + }, + { + "epoch": 0.72, + "learning_rate": 1.4962938125642504e-05, + "loss": 2.4502, + "step": 93 + }, + { + "epoch": 0.73, + "learning_rate": 1.485121119967072e-05, + "loss": 2.4707, + "step": 94 + }, + { + "epoch": 0.74, + "learning_rate": 1.4738686624729987e-05, + "loss": 2.4453, + "step": 95 + }, + { + "epoch": 0.75, + "learning_rate": 1.4625382902408356e-05, + "loss": 2.4443, + "step": 96 + }, + { + "epoch": 0.75, + "learning_rate": 1.4511318662403347e-05, + "loss": 2.4424, + "step": 97 + }, + { + "epoch": 0.76, + "learning_rate": 1.4396512659458824e-05, + "loss": 2.4375, + "step": 98 + }, + { + "epoch": 0.77, + "learning_rate": 1.4280983770281258e-05, + "loss": 2.4492, + "step": 99 + }, + { + "epoch": 0.78, + "learning_rate": 1.4164750990435991e-05, + "loss": 2.3975, + "step": 100 + }, + { + "epoch": 0.78, + "eval_loss": 2.415125846862793, + "eval_runtime": 46.8913, + "eval_samples_per_second": 3.604, + "eval_steps_per_second": 0.043, + "step": 100 + }, + { + "epoch": 0.78, + "learning_rate": 1.4047833431223938e-05, + "loss": 2.4238, + "step": 101 + }, + { + "epoch": 0.79, + "learning_rate": 1.3930250316539237e-05, + "loss": 2.4658, + "step": 102 + }, + { + "epoch": 0.8, + "learning_rate": 1.3812020979708418e-05, + "loss": 2.4521, + "step": 103 + }, + { + "epoch": 0.81, + "learning_rate": 1.3693164860311565e-05, + "loss": 2.4619, + "step": 104 + }, + { + "epoch": 0.82, + "learning_rate": 1.3573701500986012e-05, + "loss": 2.3975, + "step": 105 + }, + { + "epoch": 0.82, + "learning_rate": 1.3453650544213078e-05, + "loss": 2.4551, + "step": 106 + }, + { + "epoch": 0.83, + "learning_rate": 1.333303172908842e-05, + "loss": 2.4492, + "step": 107 + }, + { + "epoch": 0.84, + "learning_rate": 1.3211864888076458e-05, + "loss": 2.4092, + "step": 108 + }, + { + "epoch": 0.85, + "learning_rate": 1.3090169943749475e-05, + "loss": 2.4395, + "step": 109 + }, + { + "epoch": 0.85, + "learning_rate": 1.2967966905511906e-05, + "loss": 2.3906, + "step": 110 + }, + { + "epoch": 0.86, + "learning_rate": 1.2845275866310325e-05, + "loss": 2.4619, + "step": 111 + }, + { + "epoch": 0.87, + "learning_rate": 1.2722116999329712e-05, + "loss": 2.4443, + "step": 112 + }, + { + "epoch": 0.88, + "learning_rate": 1.259851055467653e-05, + "loss": 2.4629, + "step": 113 + }, + { + "epoch": 0.89, + "learning_rate": 1.2474476856049145e-05, + "loss": 2.4502, + "step": 114 + }, + { + "epoch": 0.89, + "learning_rate": 1.2350036297396153e-05, + "loss": 2.4736, + "step": 115 + }, + { + "epoch": 0.9, + "learning_rate": 1.2225209339563144e-05, + "loss": 2.4521, + "step": 116 + }, + { + "epoch": 0.91, + "learning_rate": 1.2100016506928494e-05, + "loss": 2.4775, + "step": 117 + }, + { + "epoch": 0.92, + "learning_rate": 1.1974478384028672e-05, + "loss": 2.3906, + "step": 118 + }, + { + "epoch": 0.92, + "learning_rate": 1.1848615612173689e-05, + "loss": 2.4521, + "step": 119 + }, + { + "epoch": 0.93, + "learning_rate": 1.172244888605319e-05, + "loss": 2.4844, + "step": 120 + }, + { + "epoch": 0.94, + "learning_rate": 1.1595998950333794e-05, + "loss": 2.4258, + "step": 121 + }, + { + "epoch": 0.95, + "learning_rate": 1.1469286596248181e-05, + "loss": 2.3906, + "step": 122 + }, + { + "epoch": 0.96, + "learning_rate": 1.1342332658176556e-05, + "loss": 2.4238, + "step": 123 + }, + { + "epoch": 0.96, + "learning_rate": 1.1215158010221005e-05, + "loss": 2.458, + "step": 124 + }, + { + "epoch": 0.97, + "learning_rate": 1.108778356277331e-05, + "loss": 2.4736, + "step": 125 + }, + { + "epoch": 0.98, + "learning_rate": 1.0960230259076819e-05, + "loss": 2.4062, + "step": 126 + }, + { + "epoch": 0.99, + "learning_rate": 1.0832519071782895e-05, + "loss": 2.4004, + "step": 127 + }, + { + "epoch": 0.99, + "learning_rate": 1.070467099950254e-05, + "loss": 2.4473, + "step": 128 + }, + { + "epoch": 1.0, + "learning_rate": 1.0576707063353745e-05, + "loss": 2.3799, + "step": 129 + }, + { + "epoch": 1.01, + "learning_rate": 1.044864830350515e-05, + "loss": 2.2168, + "step": 130 + }, + { + "epoch": 1.02, + "learning_rate": 1.0320515775716556e-05, + "loss": 2.1523, + "step": 131 + }, + { + "epoch": 1.03, + "learning_rate": 1.0192330547876871e-05, + "loss": 2.1826, + "step": 132 + }, + { + "epoch": 1.03, + "learning_rate": 1.0064113696540112e-05, + "loss": 2.1543, + "step": 133 + }, + { + "epoch": 1.04, + "learning_rate": 9.93588630345989e-06, + "loss": 2.1992, + "step": 134 + }, + { + "epoch": 1.05, + "learning_rate": 9.80766945212313e-06, + "loss": 2.1069, + "step": 135 + }, + { + "epoch": 1.06, + "learning_rate": 9.67948422428345e-06, + "loss": 2.1523, + "step": 136 + }, + { + "epoch": 1.06, + "learning_rate": 9.551351696494854e-06, + "loss": 2.1797, + "step": 137 + }, + { + "epoch": 1.07, + "learning_rate": 9.423292936646258e-06, + "loss": 2.1787, + "step": 138 + }, + { + "epoch": 1.08, + "learning_rate": 9.29532900049746e-06, + "loss": 2.2017, + "step": 139 + }, + { + "epoch": 1.09, + "learning_rate": 9.167480928217108e-06, + "loss": 2.1636, + "step": 140 + }, + { + "epoch": 1.1, + "learning_rate": 9.039769740923183e-06, + "loss": 2.1738, + "step": 141 + }, + { + "epoch": 1.1, + "learning_rate": 8.912216437226692e-06, + "loss": 2.1904, + "step": 142 + }, + { + "epoch": 1.11, + "learning_rate": 8.784841989778997e-06, + "loss": 2.1855, + "step": 143 + }, + { + "epoch": 1.12, + "learning_rate": 8.657667341823449e-06, + "loss": 2.1182, + "step": 144 + }, + { + "epoch": 1.13, + "learning_rate": 8.530713403751822e-06, + "loss": 2.1924, + "step": 145 + }, + { + "epoch": 1.13, + "learning_rate": 8.404001049666211e-06, + "loss": 2.1953, + "step": 146 + }, + { + "epoch": 1.14, + "learning_rate": 8.277551113946812e-06, + "loss": 2.1802, + "step": 147 + }, + { + "epoch": 1.15, + "learning_rate": 8.151384387826313e-06, + "loss": 2.1299, + "step": 148 + }, + { + "epoch": 1.16, + "learning_rate": 8.02552161597133e-06, + "loss": 2.166, + "step": 149 + }, + { + "epoch": 1.17, + "learning_rate": 7.899983493071506e-06, + "loss": 2.1167, + "step": 150 + }, + { + "epoch": 1.17, + "eval_loss": 2.4375, + "eval_runtime": 44.0835, + "eval_samples_per_second": 3.834, + "eval_steps_per_second": 0.045, + "step": 150 + }, + { + "epoch": 1.17, + "learning_rate": 7.774790660436857e-06, + "loss": 2.1729, + "step": 151 + }, + { + "epoch": 1.18, + "learning_rate": 7.649963702603848e-06, + "loss": 2.1719, + "step": 152 + }, + { + "epoch": 1.19, + "learning_rate": 7.525523143950859e-06, + "loss": 2.2061, + "step": 153 + }, + { + "epoch": 1.2, + "learning_rate": 7.401489445323473e-06, + "loss": 2.1426, + "step": 154 + }, + { + "epoch": 1.2, + "learning_rate": 7.27788300067029e-06, + "loss": 2.1987, + "step": 155 + }, + { + "epoch": 1.21, + "learning_rate": 7.154724133689677e-06, + "loss": 2.1572, + "step": 156 + }, + { + "epoch": 1.22, + "learning_rate": 7.032033094488094e-06, + "loss": 2.1465, + "step": 157 + }, + { + "epoch": 1.23, + "learning_rate": 6.909830056250527e-06, + "loss": 2.1411, + "step": 158 + }, + { + "epoch": 1.23, + "learning_rate": 6.788135111923545e-06, + "loss": 2.1548, + "step": 159 + }, + { + "epoch": 1.24, + "learning_rate": 6.666968270911585e-06, + "loss": 2.1138, + "step": 160 + }, + { + "epoch": 1.25, + "learning_rate": 6.546349455786926e-06, + "loss": 2.1548, + "step": 161 + }, + { + "epoch": 1.26, + "learning_rate": 6.426298499013994e-06, + "loss": 2.1782, + "step": 162 + }, + { + "epoch": 1.27, + "learning_rate": 6.306835139688439e-06, + "loss": 2.1621, + "step": 163 + }, + { + "epoch": 1.27, + "learning_rate": 6.187979020291584e-06, + "loss": 2.1738, + "step": 164 + }, + { + "epoch": 1.28, + "learning_rate": 6.069749683460765e-06, + "loss": 2.1221, + "step": 165 + }, + { + "epoch": 1.29, + "learning_rate": 5.952166568776062e-06, + "loss": 2.1304, + "step": 166 + }, + { + "epoch": 1.3, + "learning_rate": 5.835249009564013e-06, + "loss": 2.1885, + "step": 167 + }, + { + "epoch": 1.3, + "learning_rate": 5.719016229718748e-06, + "loss": 2.1777, + "step": 168 + }, + { + "epoch": 1.31, + "learning_rate": 5.60348734054118e-06, + "loss": 2.1304, + "step": 169 + }, + { + "epoch": 1.32, + "learning_rate": 5.488681337596653e-06, + "loss": 2.1294, + "step": 170 + }, + { + "epoch": 1.33, + "learning_rate": 5.37461709759165e-06, + "loss": 2.1592, + "step": 171 + }, + { + "epoch": 1.34, + "learning_rate": 5.2613133752700145e-06, + "loss": 2.1367, + "step": 172 + }, + { + "epoch": 1.34, + "learning_rate": 5.148788800329279e-06, + "loss": 2.124, + "step": 173 + }, + { + "epoch": 1.35, + "learning_rate": 5.037061874357503e-06, + "loss": 2.1538, + "step": 174 + }, + { + "epoch": 1.36, + "learning_rate": 4.92615096779118e-06, + "loss": 2.1382, + "step": 175 + }, + { + "epoch": 1.37, + "learning_rate": 4.81607431689475e-06, + "loss": 2.1826, + "step": 176 + }, + { + "epoch": 1.37, + "learning_rate": 4.706850020762126e-06, + "loss": 2.167, + "step": 177 + }, + { + "epoch": 1.38, + "learning_rate": 4.598496038340801e-06, + "loss": 2.1699, + "step": 178 + }, + { + "epoch": 1.39, + "learning_rate": 4.491030185478976e-06, + "loss": 2.1533, + "step": 179 + }, + { + "epoch": 1.4, + "learning_rate": 4.3844701319962525e-06, + "loss": 2.1255, + "step": 180 + }, + { + "epoch": 1.41, + "learning_rate": 4.278833398778306e-06, + "loss": 2.1577, + "step": 181 + }, + { + "epoch": 1.41, + "learning_rate": 4.17413735489604e-06, + "loss": 2.1519, + "step": 182 + }, + { + "epoch": 1.42, + "learning_rate": 4.070399214749743e-06, + "loss": 2.1636, + "step": 183 + }, + { + "epoch": 1.43, + "learning_rate": 3.967636035238636e-06, + "loss": 2.1699, + "step": 184 + }, + { + "epoch": 1.44, + "learning_rate": 3.865864712956336e-06, + "loss": 2.1719, + "step": 185 + }, + { + "epoch": 1.44, + "learning_rate": 3.7651019814126656e-06, + "loss": 2.1538, + "step": 186 + }, + { + "epoch": 1.45, + "learning_rate": 3.665364408282305e-06, + "loss": 2.2119, + "step": 187 + }, + { + "epoch": 1.46, + "learning_rate": 3.5666683926806623e-06, + "loss": 2.1455, + "step": 188 + }, + { + "epoch": 1.47, + "learning_rate": 3.4690301624675127e-06, + "loss": 2.1162, + "step": 189 + }, + { + "epoch": 1.48, + "learning_rate": 3.372465771578771e-06, + "loss": 2.0981, + "step": 190 + }, + { + "epoch": 1.48, + "learning_rate": 3.2769910973868314e-06, + "loss": 2.1162, + "step": 191 + }, + { + "epoch": 1.49, + "learning_rate": 3.1826218380900066e-06, + "loss": 2.1655, + "step": 192 + }, + { + "epoch": 1.5, + "learning_rate": 3.089373510131354e-06, + "loss": 2.1724, + "step": 193 + }, + { + "epoch": 1.51, + "learning_rate": 2.9972614456474537e-06, + "loss": 2.0962, + "step": 194 + }, + { + "epoch": 1.51, + "learning_rate": 2.9063007899474214e-06, + "loss": 2.1387, + "step": 195 + }, + { + "epoch": 1.52, + "learning_rate": 2.8165064990227255e-06, + "loss": 2.1211, + "step": 196 + }, + { + "epoch": 1.53, + "learning_rate": 2.7278933370880267e-06, + "loss": 2.1543, + "step": 197 + }, + { + "epoch": 1.54, + "learning_rate": 2.640475874153651e-06, + "loss": 2.1494, + "step": 198 + }, + { + "epoch": 1.55, + "learning_rate": 2.5542684836299316e-06, + "loss": 2.208, + "step": 199 + }, + { + "epoch": 1.55, + "learning_rate": 2.469285339963892e-06, + "loss": 2.1606, + "step": 200 + }, + { + "epoch": 1.55, + "eval_loss": 2.4366679191589355, + "eval_runtime": 44.9926, + "eval_samples_per_second": 3.756, + "eval_steps_per_second": 0.044, + "step": 200 + }, + { + "epoch": 1.56, + "learning_rate": 2.3855404163086558e-06, + "loss": 2.1528, + "step": 201 + }, + { + "epoch": 1.57, + "learning_rate": 2.3030474822259396e-06, + "loss": 2.1606, + "step": 202 + }, + { + "epoch": 1.58, + "learning_rate": 2.2218201014220266e-06, + "loss": 2.1572, + "step": 203 + }, + { + "epoch": 1.58, + "learning_rate": 2.1418716295175766e-06, + "loss": 2.1582, + "step": 204 + }, + { + "epoch": 1.59, + "learning_rate": 2.063215211851678e-06, + "loss": 2.1406, + "step": 205 + }, + { + "epoch": 1.6, + "learning_rate": 1.9858637813204352e-06, + "loss": 2.1709, + "step": 206 + }, + { + "epoch": 1.61, + "learning_rate": 1.9098300562505266e-06, + "loss": 2.1826, + "step": 207 + }, + { + "epoch": 1.62, + "learning_rate": 1.835126538308013e-06, + "loss": 2.1416, + "step": 208 + }, + { + "epoch": 1.62, + "learning_rate": 1.7617655104427833e-06, + "loss": 2.1665, + "step": 209 + }, + { + "epoch": 1.63, + "learning_rate": 1.6897590348689607e-06, + "loss": 2.1582, + "step": 210 + }, + { + "epoch": 1.64, + "learning_rate": 1.6191189510815942e-06, + "loss": 2.144, + "step": 211 + }, + { + "epoch": 1.65, + "learning_rate": 1.5498568739099907e-06, + "loss": 2.1685, + "step": 212 + }, + { + "epoch": 1.65, + "learning_rate": 1.481984191607959e-06, + "loss": 2.1343, + "step": 213 + }, + { + "epoch": 1.66, + "learning_rate": 1.4155120639813392e-06, + "loss": 2.1528, + "step": 214 + }, + { + "epoch": 1.67, + "learning_rate": 1.350451420553065e-06, + "loss": 2.1411, + "step": 215 + }, + { + "epoch": 1.68, + "learning_rate": 1.286812958766106e-06, + "loss": 2.1289, + "step": 216 + }, + { + "epoch": 1.69, + "learning_rate": 1.224607142224572e-06, + "loss": 2.127, + "step": 217 + }, + { + "epoch": 1.69, + "learning_rate": 1.1638441989732474e-06, + "loss": 2.1367, + "step": 218 + }, + { + "epoch": 1.7, + "learning_rate": 1.1045341198158833e-06, + "loss": 2.1021, + "step": 219 + }, + { + "epoch": 1.71, + "learning_rate": 1.0466866566724698e-06, + "loss": 2.1436, + "step": 220 + }, + { + "epoch": 1.72, + "learning_rate": 9.903113209758098e-07, + "loss": 2.1509, + "step": 221 + }, + { + "epoch": 1.72, + "learning_rate": 9.354173821076184e-07, + "loss": 2.1665, + "step": 222 + }, + { + "epoch": 1.73, + "learning_rate": 8.820138658744304e-07, + "loss": 2.1162, + "step": 223 + }, + { + "epoch": 1.74, + "learning_rate": 8.301095530235492e-07, + "loss": 2.1104, + "step": 224 + }, + { + "epoch": 1.75, + "learning_rate": 7.797129777992951e-07, + "loss": 2.1348, + "step": 225 + }, + { + "epoch": 1.76, + "learning_rate": 7.308324265397837e-07, + "loss": 2.1562, + "step": 226 + }, + { + "epoch": 1.76, + "learning_rate": 6.834759363144595e-07, + "loss": 2.1543, + "step": 227 + }, + { + "epoch": 1.77, + "learning_rate": 6.37651293602628e-07, + "loss": 2.1357, + "step": 228 + }, + { + "epoch": 1.78, + "learning_rate": 5.933660330131752e-07, + "loss": 2.1392, + "step": 229 + }, + { + "epoch": 1.79, + "learning_rate": 5.506274360457087e-07, + "loss": 2.123, + "step": 230 + }, + { + "epoch": 1.79, + "learning_rate": 5.094425298933136e-07, + "loss": 2.1606, + "step": 231 + }, + { + "epoch": 1.8, + "learning_rate": 4.6981808628712823e-07, + "loss": 2.0991, + "step": 232 + }, + { + "epoch": 1.81, + "learning_rate": 4.3176062038291275e-07, + "loss": 2.1582, + "step": 233 + }, + { + "epoch": 1.82, + "learning_rate": 3.9527638968980707e-07, + "loss": 2.1929, + "step": 234 + }, + { + "epoch": 1.83, + "learning_rate": 3.603713930414676e-07, + "loss": 2.0874, + "step": 235 + }, + { + "epoch": 1.83, + "learning_rate": 3.2705136960970554e-07, + "loss": 2.1299, + "step": 236 + }, + { + "epoch": 1.84, + "learning_rate": 2.9532179796085356e-07, + "loss": 2.1704, + "step": 237 + }, + { + "epoch": 1.85, + "learning_rate": 2.6518789515495356e-07, + "loss": 2.1382, + "step": 238 + }, + { + "epoch": 1.86, + "learning_rate": 2.3665461588795902e-07, + "loss": 2.1689, + "step": 239 + }, + { + "epoch": 1.86, + "learning_rate": 2.097266516770713e-07, + "loss": 2.1436, + "step": 240 + }, + { + "epoch": 1.87, + "learning_rate": 1.844084300893456e-07, + "loss": 2.1108, + "step": 241 + }, + { + "epoch": 1.88, + "learning_rate": 1.6070411401370335e-07, + "loss": 2.1206, + "step": 242 + }, + { + "epoch": 1.89, + "learning_rate": 1.3861760097645062e-07, + "loss": 2.1118, + "step": 243 + }, + { + "epoch": 1.9, + "learning_rate": 1.1815252250044318e-07, + "loss": 2.1738, + "step": 244 + }, + { + "epoch": 1.9, + "learning_rate": 9.931224350798185e-08, + "loss": 2.1328, + "step": 245 + }, + { + "epoch": 1.91, + "learning_rate": 8.209986176753947e-08, + "loss": 2.1538, + "step": 246 + }, + { + "epoch": 1.92, + "learning_rate": 6.65182073844195e-08, + "loss": 2.1338, + "step": 247 + }, + { + "epoch": 1.93, + "learning_rate": 5.256984233542595e-08, + "loss": 2.1455, + "step": 248 + }, + { + "epoch": 1.93, + "learning_rate": 4.025706004760932e-08, + "loss": 2.1831, + "step": 249 + }, + { + "epoch": 1.94, + "learning_rate": 2.9581885021181534e-08, + "loss": 2.1304, + "step": 250 + }, + { + "epoch": 1.94, + "eval_loss": 2.4366679191589355, + "eval_runtime": 40.7598, + "eval_samples_per_second": 4.146, + "eval_steps_per_second": 0.049, + "step": 250 + }, + { + "epoch": 1.96, + "learning_rate": 2.054607249663665e-08, + "loss": 2.1387, + "step": 251 + }, + { + "epoch": 1.96, + "learning_rate": 1.3151108166156168e-08, + "loss": 2.1406, + "step": 252 + }, + { + "epoch": 1.97, + "learning_rate": 7.3982079293233314e-09, + "loss": 2.1309, + "step": 253 + }, + { + "epoch": 1.98, + "learning_rate": 3.2883176932019255e-09, + "loss": 2.1133, + "step": 254 + }, + { + "epoch": 1.99, + "learning_rate": 8.221132168073631e-10, + "loss": 2.1543, + "step": 255 + }, + { + "epoch": 1.99, + "learning_rate": 0.0, + "loss": 2.1475, + "step": 256 + } + ], + "max_steps": 256, + "num_train_epochs": 2, + "total_flos": 83249552424960.0, + "trial_name": null, + "trial_params": null +} diff --git a/training_args.bin b/training_args.bin new file mode 100644 index 0000000..5f033c0 --- /dev/null +++ b/training_args.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0a95bb91ac445ca680f147f9c52cedc230507eaf729b4551416a08d2430966a5 +size 4591 diff --git a/zero_to_fp32.py b/zero_to_fp32.py new file mode 100755 index 0000000..c5246ff --- /dev/null +++ b/zero_to_fp32.py @@ -0,0 +1,578 @@ +#!/usr/bin/env python + +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 + +# DeepSpeed Team + +# This script extracts fp32 consolidated weights from a zero 2 and 3 DeepSpeed checkpoints. It gets +# copied into the top level checkpoint dir, so the user can easily do the conversion at any point in +# the future. Once extracted, the weights don't require DeepSpeed and can be used in any +# application. +# +# example: python zero_to_fp32.py . pytorch_model.bin + +import argparse +import torch +import glob +import math +import os +import re +from collections import OrderedDict +from dataclasses import dataclass + +# while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with +# DeepSpeed data structures it has to be available in the current python environment. +from deepspeed.utils import logger +from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS, + FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES, + FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS) + + +@dataclass +class zero_model_state: + buffers: dict() + param_shapes: dict() + shared_params: list + ds_version: int + frozen_param_shapes: dict() + frozen_param_fragments: dict() + + +debug = 0 + +# load to cpu +device = torch.device('cpu') + + +def atoi(text): + return int(text) if text.isdigit() else text + + +def natural_keys(text): + ''' + alist.sort(key=natural_keys) sorts in human order + http://nedbatchelder.com/blog/200712/human_sorting.html + (See Toothy's implementation in the comments) + ''' + return [atoi(c) for c in re.split(r'(\d+)', text)] + + +def get_model_state_file(checkpoint_dir, zero_stage): + if not os.path.isdir(checkpoint_dir): + raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist") + + # there should be only one file + if zero_stage == 2: + file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt") + elif zero_stage == 3: + file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt") + + if not os.path.exists(file): + raise FileNotFoundError(f"can't find model states file at '{file}'") + + return file + + +def get_checkpoint_files(checkpoint_dir, glob_pattern): + # XXX: need to test that this simple glob rule works for multi-node setup too + ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys) + + if len(ckpt_files) == 0: + raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'") + + return ckpt_files + + +def get_optim_files(checkpoint_dir): + return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt") + + +def get_model_state_files(checkpoint_dir): + return get_checkpoint_files(checkpoint_dir, "*_model_states.pt") + + +def parse_model_states(files): + zero_model_states = [] + for file in files: + state_dict = torch.load(file, map_location=device) + + if BUFFER_NAMES not in state_dict: + raise ValueError(f"{file} is not a model state checkpoint") + buffer_names = state_dict[BUFFER_NAMES] + if debug: + print("Found buffers:", buffer_names) + + # recover just the buffers while restoring them to fp32 if they were saved in fp16 + buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names} + param_shapes = state_dict[PARAM_SHAPES] + + # collect parameters that are included in param_shapes + param_names = [] + for s in param_shapes: + for name in s.keys(): + param_names.append(name) + + # update with frozen parameters + frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None) + if frozen_param_shapes is not None: + if debug: + print(f"Found frozen_param_shapes: {frozen_param_shapes}") + param_names += list(frozen_param_shapes.keys()) + + # handle shared params + shared_params = [[k, v] for k, v in state_dict["shared_params"].items()] + + ds_version = state_dict.get(DS_VERSION, None) + + frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None) + + z_model_state = zero_model_state(buffers=buffers, + param_shapes=param_shapes, + shared_params=shared_params, + ds_version=ds_version, + frozen_param_shapes=frozen_param_shapes, + frozen_param_fragments=frozen_param_fragments) + zero_model_states.append(z_model_state) + + return zero_model_states + + +def parse_optim_states(files, ds_checkpoint_dir): + + total_files = len(files) + state_dicts = [] + for f in files: + state_dicts.append(torch.load(f, map_location=device)) + + if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]: + raise ValueError(f"{files[0]} is not a zero checkpoint") + zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE] + world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT] + + # For ZeRO-2 each param group can have different partition_count as data parallelism for expert + # parameters can be different from data parallelism for non-expert parameters. So we can just + # use the max of the partition_count to get the dp world_size. + + if type(world_size) is list: + world_size = max(world_size) + + if world_size != total_files: + raise ValueError( + f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. " + "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes." + ) + + # the groups are named differently in each stage + if zero_stage == 2: + fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS + elif zero_stage == 3: + fp32_groups_key = FP32_FLAT_GROUPS + else: + raise ValueError(f"unknown zero stage {zero_stage}") + + if zero_stage == 2: + fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))] + elif zero_stage == 3: + # if there is more than one param group, there will be multiple flattened tensors - one + # flattened tensor per group - for simplicity merge them into a single tensor + # + # XXX: could make the script more memory efficient for when there are multiple groups - it + # will require matching the sub-lists of param_shapes for each param group flattened tensor + + fp32_flat_groups = [ + torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key], 0) for i in range(len(state_dicts)) + ] + + return zero_stage, world_size, fp32_flat_groups + + +def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir): + """ + Returns fp32 state_dict reconstructed from ds checkpoint + + Args: + - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are) + + """ + print(f"Processing zero checkpoint '{ds_checkpoint_dir}'") + + optim_files = get_optim_files(ds_checkpoint_dir) + zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir) + print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}") + + model_files = get_model_state_files(ds_checkpoint_dir) + + zero_model_states = parse_model_states(model_files) + print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}') + + if zero_stage == 2: + return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states) + elif zero_stage == 3: + return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states) + + +def _zero2_merge_frozen_params(state_dict, zero_model_states): + if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0: + return + + frozen_param_shapes = zero_model_states[0].frozen_param_shapes + frozen_param_fragments = zero_model_states[0].frozen_param_fragments + + if debug: + num_elem = sum(s.numel() for s in frozen_param_shapes.values()) + print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}') + + wanted_params = len(frozen_param_shapes) + wanted_numel = sum(s.numel() for s in frozen_param_shapes.values()) + avail_numel = sum([p.numel() for p in frozen_param_fragments.values()]) + print(f'Frozen params: Have {avail_numel} numels to process.') + print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params') + + total_params = 0 + total_numel = 0 + for name, shape in frozen_param_shapes.items(): + total_params += 1 + unpartitioned_numel = shape.numel() + total_numel += unpartitioned_numel + + state_dict[name] = frozen_param_fragments[name] + + if debug: + print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ") + + print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements") + + +def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states): + param_shapes = zero_model_states[0].param_shapes + + # Reconstruction protocol: + # + # XXX: document this + + if debug: + for i in range(world_size): + for j in range(len(fp32_flat_groups[0])): + print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}") + + # XXX: memory usage doubles here (zero2) + num_param_groups = len(fp32_flat_groups[0]) + merged_single_partition_of_fp32_groups = [] + for i in range(num_param_groups): + merged_partitions = [sd[i] for sd in fp32_flat_groups] + full_single_fp32_vector = torch.cat(merged_partitions, 0) + merged_single_partition_of_fp32_groups.append(full_single_fp32_vector) + avail_numel = sum( + [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups]) + + if debug: + wanted_params = sum([len(shapes) for shapes in param_shapes]) + wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes]) + # not asserting if there is a mismatch due to possible padding + print(f"Have {avail_numel} numels to process.") + print(f"Need {wanted_numel} numels in {wanted_params} params.") + + # params + # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support + # out-of-core computing solution + total_numel = 0 + total_params = 0 + for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups): + offset = 0 + avail_numel = full_single_fp32_vector.numel() + for name, shape in shapes.items(): + + unpartitioned_numel = shape.numel() + total_numel += unpartitioned_numel + total_params += 1 + + if debug: + print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ") + state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape) + offset += unpartitioned_numel + + # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and + # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex + # paddings performed in the code it's almost impossible to predict the exact numbers w/o the + # live optimizer object, so we are checking that the numbers are within the right range + align_to = 2 * world_size + + def zero2_align(x): + return align_to * math.ceil(x / align_to) + + if debug: + print(f"original offset={offset}, avail_numel={avail_numel}") + + offset = zero2_align(offset) + avail_numel = zero2_align(avail_numel) + + if debug: + print(f"aligned offset={offset}, avail_numel={avail_numel}") + + # Sanity check + if offset != avail_numel: + raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong") + + print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements") + + +def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states): + state_dict = OrderedDict() + + # buffers + buffers = zero_model_states[0].buffers + state_dict.update(buffers) + if debug: + print(f"added {len(buffers)} buffers") + + _zero2_merge_frozen_params(state_dict, zero_model_states) + + _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states) + + # recover shared parameters + for pair in zero_model_states[0].shared_params: + if pair[1] in state_dict: + state_dict[pair[0]] = state_dict[pair[1]] + + return state_dict + + +def zero3_partitioned_param_info(unpartitioned_numel, world_size): + remainder = unpartitioned_numel % world_size + padding_numel = (world_size - remainder) if remainder else 0 + partitioned_numel = math.ceil(unpartitioned_numel / world_size) + return partitioned_numel, padding_numel + + +def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states): + if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0: + return + + if debug: + for i in range(world_size): + num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values()) + print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}') + + frozen_param_shapes = zero_model_states[0].frozen_param_shapes + wanted_params = len(frozen_param_shapes) + wanted_numel = sum(s.numel() for s in frozen_param_shapes.values()) + avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size + print(f'Frozen params: Have {avail_numel} numels to process.') + print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params') + + total_params = 0 + total_numel = 0 + for name, shape in zero_model_states[0].frozen_param_shapes.items(): + total_params += 1 + unpartitioned_numel = shape.numel() + total_numel += unpartitioned_numel + + param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states) + state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape) + + partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size) + + if debug: + print( + f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}" + ) + + print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements") + + +def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states): + param_shapes = zero_model_states[0].param_shapes + avail_numel = fp32_flat_groups[0].numel() * world_size + # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each + # param, re-consolidating each param, while dealing with padding if any + + # merge list of dicts, preserving order + param_shapes = {k: v for d in param_shapes for k, v in d.items()} + + if debug: + for i in range(world_size): + print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}") + + wanted_params = len(param_shapes) + wanted_numel = sum(shape.numel() for shape in param_shapes.values()) + # not asserting if there is a mismatch due to possible padding + avail_numel = fp32_flat_groups[0].numel() * world_size + print(f"Trainable params: Have {avail_numel} numels to process.") + print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.") + + # params + # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support + # out-of-core computing solution + offset = 0 + total_numel = 0 + total_params = 0 + for name, shape in param_shapes.items(): + + unpartitioned_numel = shape.numel() + total_numel += unpartitioned_numel + total_params += 1 + + partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size) + + if debug: + print( + f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}" + ) + + # XXX: memory usage doubles here + state_dict[name] = torch.cat( + tuple(fp32_flat_groups[i].narrow(0, offset, partitioned_numel) for i in range(world_size)), + 0).narrow(0, 0, unpartitioned_numel).view(shape) + offset += partitioned_numel + + offset *= world_size + + # Sanity check + if offset != avail_numel: + raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong") + + print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements") + + +def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states): + state_dict = OrderedDict() + + # buffers + buffers = zero_model_states[0].buffers + state_dict.update(buffers) + if debug: + print(f"added {len(buffers)} buffers") + + _zero3_merge_frozen_params(state_dict, world_size, zero_model_states) + + _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states) + + # recover shared parameters + for pair in zero_model_states[0].shared_params: + if pair[1] in state_dict: + state_dict[pair[0]] = state_dict[pair[1]] + + return state_dict + + +def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None): + """ + Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with + ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example + via a model hub. + + Args: + - ``checkpoint_dir``: path to the desired checkpoint folder + - ``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`` + + Returns: + - pytorch ``state_dict`` + + Note: this approach may not work if your application doesn't have sufficient free CPU memory and + you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with + the checkpoint. + + A typical usage might be :: + + from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint + # do the training and checkpoint saving + state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu + model = model.cpu() # move to cpu + model.load_state_dict(state_dict) + # submit to model hub or save the model to share with others + + In this example the ``model`` will no longer be usable in the deepspeed context of the same + application. i.e. you will need to re-initialize the deepspeed engine, since + ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it. + + If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead. + + """ + if tag is None: + latest_path = os.path.join(checkpoint_dir, 'latest') + if os.path.isfile(latest_path): + with open(latest_path, 'r') as fd: + tag = fd.read().strip() + else: + raise ValueError(f"Unable to find 'latest' file at {latest_path}") + + ds_checkpoint_dir = os.path.join(checkpoint_dir, tag) + + if not os.path.isdir(ds_checkpoint_dir): + raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist") + + return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir) + + +def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file, tag=None): + """ + Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be + loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed. + + Args: + - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``) + - ``output_file``: path to the pytorch fp32 state_dict output file (e.g. path/pytorch_model.bin) + - ``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`` + """ + + state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag) + print(f"Saving fp32 state dict to {output_file}") + torch.save(state_dict, output_file) + + +def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None): + """ + 1. Put the provided model to cpu + 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` + 3. Load it into the provided model + + Args: + - ``model``: the model object to update + - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``) + - ``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`` + + Returns: + - ``model`: modified model + + Make sure you have plenty of CPU memory available before you call this function. If you don't + have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it + conveniently placed for you in the checkpoint folder. + + A typical usage might be :: + + from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint + model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir) + # submit to model hub or save the model to share with others + + Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context + of the same application. i.e. you will need to re-initialize the deepspeed engine, since + ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it. + + """ + logger.info(f"Extracting fp32 weights") + state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag) + + logger.info(f"Overwriting model with fp32 weights") + model = model.cpu() + model.load_state_dict(state_dict, strict=False) + + return model + + +if __name__ == "__main__": + + parser = argparse.ArgumentParser() + parser.add_argument("checkpoint_dir", + type=str, + help="path to the desired checkpoint folder, e.g., path/checkpoint-12") + parser.add_argument( + "output_file", + type=str, + help="path to the pytorch fp32 state_dict output file (e.g. path/checkpoint-12/pytorch_model.bin)") + parser.add_argument("-d", "--debug", action='store_true', help="enable debug") + args = parser.parse_args() + + debug = args.debug + + convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir, args.output_file)