From 0f973def7b32147b56532c1176dd373e7112d89c Mon Sep 17 00:00:00 2001 From: ouyangyu Date: Fri, 4 Jun 2021 17:29:34 +0800 Subject: [PATCH] add readme.md --- LanguageModeling/GPT/tools/README.md | 36 +++++++++++++++++++ .../GPT/tools/convert_py_model_to_of.py | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 LanguageModeling/GPT/tools/README.md diff --git a/LanguageModeling/GPT/tools/README.md b/LanguageModeling/GPT/tools/README.md new file mode 100644 index 0000000..955b149 --- /dev/null +++ b/LanguageModeling/GPT/tools/README.md @@ -0,0 +1,36 @@ +# GPT模型转换 + +### PyTorch模型转OneFlow模型 + - `meta.proto`,是为生成模型目录下的`meta`文件,需要执行`protoc --python_out=. meta.proto`后生成`meta_pb2.py`,即可`import meta_pb2 as meta_pb` + ``` + syntax = "proto2"; + package gpt; + + message Shape { + repeated int32 dim = 1; + } + + enum DataType { + kInvalidDataType = 0; + kChar = 1; + kFloat = 2; + kDouble = 3; + kInt8 = 4; + kInt32 = 5; + kInt64 = 6; + kUInt8 = 7; + kOFRecord = 8; + kFloat16 = 9; + kTensorBuffer = 10; + } + + message Meta { + required Shape shape = 1; + required DataType data_type = 2 [default = kFloat16]; + } + ``` + - 转换脚本`convert_pt_to_of_gpt.py`,执行`python3 convert_pt_to_of_gpt.py --py_model_dir /path/to/iter_0500000/mp_rank_00/model_optim_rng.pt`即可在当前目录下的`convert_pt_to_of_gpt`生成OneFlow模型 + - `--py_model_dir`,pytorch模型地址 + - `--of_dump_path`,保存转换后的模型路径 + + \ No newline at end of file diff --git a/LanguageModeling/GPT/tools/convert_py_model_to_of.py b/LanguageModeling/GPT/tools/convert_py_model_to_of.py index 2caba97..eea85e8 100644 --- a/LanguageModeling/GPT/tools/convert_py_model_to_of.py +++ b/LanguageModeling/GPT/tools/convert_py_model_to_of.py @@ -13,7 +13,7 @@ def get_args(): parser.add_argument( "--py_model_dir", type=str, - default="/home/oyy/iter_0500000/mp_rank_00/model_optim_rng.pt", + default="/path/to/iter_0500000/mp_rank_00/model_optim_rng.pt", help="Path the PyTorch checkpoint file path.", ) parser.add_argument(