|
| 1 | +/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | +
|
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +
|
| 9 | +Unless required by applicable law or agreed to in writing, software |
| 10 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +See the License for the specific language governing permissions and |
| 13 | +limitations under the License. */ |
| 14 | + |
| 15 | +syntax = "proto2"; |
| 16 | +option optimize_for = LITE_RUNTIME; |
| 17 | +package paddle_mobile.framework.proto; |
| 18 | + |
| 19 | +enum AttrType { |
| 20 | + INT = 0; |
| 21 | + FLOAT = 1; |
| 22 | + STRING = 2; |
| 23 | + INTS = 3; |
| 24 | + FLOATS = 4; |
| 25 | + STRINGS = 5; |
| 26 | + BOOLEAN = 6; |
| 27 | + BOOLEANS = 7; |
| 28 | + BLOCK = 8; |
| 29 | + LONG = 9; |
| 30 | +} |
| 31 | + |
| 32 | +// OpDesc describes an instance of a C++ framework::OperatorBase |
| 33 | +// derived class type. |
| 34 | +message OpDesc { |
| 35 | + |
| 36 | + message Attr { |
| 37 | + required string name = 1; |
| 38 | + required AttrType type = 2; |
| 39 | + optional int32 i = 3; |
| 40 | + optional float f = 4; |
| 41 | + optional string s = 5; |
| 42 | + repeated int32 ints = 6; |
| 43 | + repeated float floats = 7; |
| 44 | + repeated string strings = 8; |
| 45 | + optional bool b = 10; |
| 46 | + repeated bool bools = 11; |
| 47 | + optional int32 block_idx = 12; |
| 48 | + optional int64 l = 13; |
| 49 | + }; |
| 50 | + |
| 51 | + message Var { |
| 52 | + required string parameter = 1; |
| 53 | + repeated string arguments = 2; |
| 54 | + }; |
| 55 | + |
| 56 | + required string type = 3; |
| 57 | + repeated Var inputs = 1; |
| 58 | + repeated Var outputs = 2; |
| 59 | + repeated Attr attrs = 4; |
| 60 | + optional bool is_target = 5 [ default = false ]; |
| 61 | +}; |
| 62 | + |
| 63 | +// OpProto describes a C++ framework::OperatorBase derived class. |
| 64 | +message OpProto { |
| 65 | + |
| 66 | + // VarProto describes the C++ type framework::Variable. |
| 67 | + message Var { |
| 68 | + required string name = 1; |
| 69 | + required string comment = 2; |
| 70 | + |
| 71 | + optional bool duplicable = 3 [ default = false ]; |
| 72 | + optional bool intermediate = 4 [ default = false ]; |
| 73 | + optional bool dispensable = 5 [ default = false ]; |
| 74 | + } |
| 75 | + |
| 76 | + // AttrProto describes the C++ type Attribute. |
| 77 | + message Attr { |
| 78 | + required string name = 1; |
| 79 | + required AttrType type = 2; |
| 80 | + required string comment = 3; |
| 81 | + // If that attribute is generated, it means the Paddle third |
| 82 | + // language binding has responsibility to fill that |
| 83 | + // attribute. End-User should not set that attribute. |
| 84 | + optional bool generated = 4 [ default = false ]; |
| 85 | + } |
| 86 | + |
| 87 | + required string type = 1; |
| 88 | + repeated Var inputs = 2; |
| 89 | + repeated Var outputs = 3; |
| 90 | + repeated Attr attrs = 4; |
| 91 | + required string comment = 5; |
| 92 | +} |
| 93 | + |
| 94 | +message VarType { |
| 95 | + enum Type { |
| 96 | + // Pod Types |
| 97 | + BOOL = 0; |
| 98 | + INT16 = 1; |
| 99 | + INT32 = 2; |
| 100 | + INT64 = 3; |
| 101 | + FP16 = 4; |
| 102 | + FP32 = 5; |
| 103 | + FP64 = 6; |
| 104 | + |
| 105 | + // Other types that may need additional descriptions |
| 106 | + LOD_TENSOR = 7; |
| 107 | + SELECTED_ROWS = 8; |
| 108 | + FEED_MINIBATCH = 9; |
| 109 | + FETCH_LIST = 10; |
| 110 | + STEP_SCOPES = 11; |
| 111 | + LOD_RANK_TABLE = 12; |
| 112 | + LOD_TENSOR_ARRAY = 13; |
| 113 | + PLACE_LIST = 14; |
| 114 | + READER = 15; |
| 115 | + CHANNEL = 16; |
| 116 | + // Any runtime decided variable type is raw |
| 117 | + // raw variables should manage their own allocations |
| 118 | + // in operators like nccl_op |
| 119 | + RAW = 17; |
| 120 | + TUPLE = 18; |
| 121 | + } |
| 122 | + |
| 123 | + required Type type = 1; |
| 124 | + |
| 125 | + message TensorDesc { |
| 126 | + // Should only be PODType. Is enforced in C++ |
| 127 | + required Type data_type = 1; |
| 128 | + repeated int64 dims = 2; // [UNK, 640, 480] is saved as [-1, 640, 480] |
| 129 | + } |
| 130 | + optional TensorDesc selected_rows = 2; |
| 131 | + |
| 132 | + message LoDTensorDesc { |
| 133 | + required TensorDesc tensor = 1; |
| 134 | + optional int32 lod_level = 2 [ default = 0 ]; |
| 135 | + } |
| 136 | + optional LoDTensorDesc lod_tensor = 3; |
| 137 | + |
| 138 | + message LoDTensorArrayDesc { |
| 139 | + required TensorDesc tensor = 1; |
| 140 | + optional int32 lod_level = 2 [ default = 0 ]; |
| 141 | + } |
| 142 | + optional LoDTensorArrayDesc tensor_array = 4; |
| 143 | + |
| 144 | + message ReaderDesc { repeated LoDTensorDesc lod_tensor = 1; } |
| 145 | + optional ReaderDesc reader = 5; |
| 146 | + |
| 147 | + message ChannelDesc { |
| 148 | + required Type data_type = 1; |
| 149 | + required int64 capacity = 2; |
| 150 | + } |
| 151 | + optional ChannelDesc channel = 6; |
| 152 | + |
| 153 | + message Tuple { repeated Type element_type = 1; } |
| 154 | + optional Tuple tuple = 7; |
| 155 | +} |
| 156 | + |
| 157 | +message VarDesc { |
| 158 | + required string name = 1; |
| 159 | + required VarType type = 2; |
| 160 | + optional bool persistable = 3 [ default = false ]; |
| 161 | +} |
| 162 | + |
| 163 | +message BlockDesc { |
| 164 | + required int32 idx = 1; |
| 165 | + required int32 parent_idx = 2; |
| 166 | + repeated VarDesc vars = 3; |
| 167 | + repeated OpDesc ops = 4; |
| 168 | + optional int32 forward_block_idx = 5 [ default = -1 ]; |
| 169 | +} |
| 170 | + |
| 171 | +// Please refer to |
| 172 | +// https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/program.md |
| 173 | +// for more details. |
| 174 | +// TODO(panyx0718): A model can have multiple programs. Need a |
| 175 | +// way to distinguish them. Maybe ID or name? |
| 176 | +message ProgramDesc { repeated BlockDesc blocks = 1; } |
0 commit comments