Skip to content

Commit

Permalink
add readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ouyangyu committed Jun 4, 2021
1 parent c6ab796 commit 0f973de
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions LanguageModeling/GPT/tools/README.md
Original file line number Diff line number Diff line change
@@ -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`,保存转换后的模型路径


2 changes: 1 addition & 1 deletion LanguageModeling/GPT/tools/convert_py_model_to_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0f973de

Please sign in to comment.