framework.proto 6.3 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
Y
Yi Wang 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

syntax = "proto2";
16
package paddle.framework.proto;
Y
Yi Wang 已提交
17

X
version  
Xin Pan 已提交
18 19 20 21 22
// Any incompatible changes to ProgramDesc and its dependencies should
// raise the version defined version.h.
//
// Serailization and Deserialization codes should be modified in a way
// that supports old versions following the version and compatibility policy.
X
fix  
Xin Pan 已提交
23
message Version { optional int64 version = 1 [ default = 0 ]; }
X
version  
Xin Pan 已提交
24

Y
Yi Wang 已提交
25 26
enum AttrType {
  INT = 0;
27 28 29 30 31 32 33 34 35 36 37
  FLOAT = 1;
  STRING = 2;
  INTS = 3;
  FLOATS = 4;
  STRINGS = 5;
  BOOLEAN = 6;
  BOOLEANS = 7;
  BLOCK = 8;
  LONG = 9;
  BLOCKS = 10;
  LONGS = 11;
38
  FLOAT64S = 12;
Y
Yi Wang 已提交
39 40
}

41 42 43 44 45 46 47
message ProcessMeshDesc {
  required int32 id = 1;
  required int32 parent_id = 2;
  repeated int32 topology = 3;
  repeated int32 process_group = 4;
};

Y
Yi Wang 已提交
48 49 50 51 52 53 54 55
// OpDesc describes an instance of a C++ framework::OperatorBase
// derived class type.
message OpDesc {

  message Attr {
    required string name = 1;
    required AttrType type = 2;
    optional int32 i = 3;
56 57 58 59 60 61 62 63 64
    optional float f = 4;
    optional string s = 5;
    repeated int32 ints = 6;
    repeated float floats = 7;
    repeated string strings = 8;
    optional bool b = 10;
    repeated bool bools = 11;
    optional int32 block_idx = 12;
    optional int64 l = 13;
65
    repeated int32 blocks_idx = 14;
66
    repeated int64 longs = 15;
67
    repeated double float64s = 16;
Y
Yi Wang 已提交
68 69 70
  };

  message Var {
71 72
    required string parameter = 1;
    repeated string arguments = 2;
Y
Yi Wang 已提交
73 74 75 76 77 78
  };

  required string type = 3;
  repeated Var inputs = 1;
  repeated Var outputs = 2;
  repeated Attr attrs = 4;
Y
Yang Yang 已提交
79
  optional bool is_target = 5 [ default = false ];
Y
Yi Wang 已提交
80 81 82 83 84 85 86 87 88
};

// OpProto describes a C++ framework::OperatorBase derived class.
message OpProto {

  // VarProto describes the C++ type framework::Variable.
  message Var {
    required string name = 1;
    required string comment = 2;
Y
Yu Yang 已提交
89

Y
Yi Wang 已提交
90 91
    optional bool duplicable = 3 [ default = false ];
    optional bool intermediate = 4 [ default = false ];
Y
Yang Yang 已提交
92
    optional bool dispensable = 5 [ default = false ];
93 94
    optional bool extra = 6 [ default = false ];
    optional bool quant = 7 [ default = false ];
Y
Yi Wang 已提交
95 96 97 98 99 100 101 102 103 104 105
  }

  // AttrProto describes the C++ type Attribute.
  message Attr {
    required string name = 1;
    required AttrType type = 2;
    required string comment = 3;
    // If that attribute is generated, it means the Paddle third
    // language binding has responsibility to fill that
    // attribute. End-User should not set that attribute.
    optional bool generated = 4 [ default = false ];
106 107
    optional bool extra = 5 [ default = false ];
    optional bool quant = 6 [ default = false ];
Y
Yi Wang 已提交
108 109 110 111 112 113 114 115
  }

  required string type = 1;
  repeated Var inputs = 2;
  repeated Var outputs = 3;
  repeated Attr attrs = 4;
  required string comment = 5;
}
Q
qiaolongfei 已提交
116

117 118
message VarType {
  enum Type {
119 120 121 122 123 124 125 126
    // Pod Types
    BOOL = 0;
    INT16 = 1;
    INT32 = 2;
    INT64 = 3;
    FP16 = 4;
    FP32 = 5;
    FP64 = 6;
Y
yuyang18 已提交
127 128
    // Tensor<size_t> is used in C++.
    SIZE_T = 19;
Y
yuyang18 已提交
129
    UINT8 = 20;
Q
qingqing01 已提交
130
    INT8 = 21;
131
    BF16 = 22;
132 133
    COMPLEX64 = 23;
    COMPLEX128 = 24;
134 135 136 137 138 139 140 141 142 143 144

    // Other types that may need additional descriptions
    LOD_TENSOR = 7;
    SELECTED_ROWS = 8;
    FEED_MINIBATCH = 9;
    FETCH_LIST = 10;
    STEP_SCOPES = 11;
    LOD_RANK_TABLE = 12;
    LOD_TENSOR_ARRAY = 13;
    PLACE_LIST = 14;
    READER = 15;
T
typhoonzero 已提交
145 146
    // Any runtime decided variable type is raw
    // raw variables should manage their own allocations
T
typhoonzero 已提交
147
    // in operators like nccl_op
T
typhoonzero 已提交
148
    RAW = 17;
C
chengduo 已提交
149
    TUPLE = 18;
S
Steffy-zxf 已提交
150 151 152 153 154

    STRING = 25;
    STRINGS = 26;
    VOCAB = 27;
    FEED_LIST = 28;
Y
Yu Yang 已提交
155
  }
156 157 158 159

  required Type type = 1;

  message TensorDesc {
160 161
    // Should only be PODType. Is enforced in C++
    required Type data_type = 1;
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
    repeated int64 dims = 2; // [UNK, 640, 480] is saved as [-1, 640, 480]
  }
  optional TensorDesc selected_rows = 2;

  message LoDTensorDesc {
    required TensorDesc tensor = 1;
    optional int32 lod_level = 2 [ default = 0 ];
  }
  optional LoDTensorDesc lod_tensor = 3;

  message LoDTensorArrayDesc {
    required TensorDesc tensor = 1;
    optional int32 lod_level = 2 [ default = 0 ];
  }
  optional LoDTensorArrayDesc tensor_array = 4;

  message ReaderDesc { repeated LoDTensorDesc lod_tensor = 1; }
  optional ReaderDesc reader = 5;
180

C
chengduo 已提交
181 182
  message Tuple { repeated Type element_type = 1; }
  optional Tuple tuple = 7;
S
Steffy-zxf 已提交
183 184 185 186

  optional TensorDesc string = 8;
  optional TensorDesc strings = 9;
  optional TensorDesc vocab = 10;
187 188 189
}

message VarDesc {
190 191 192 193 194 195 196 197 198

  message Attr {
    required string name = 1;
    required AttrType type = 2;
    optional int32 i = 3;
    optional string s = 4;
    repeated int32 ints = 5;
  };

Q
qiaolongfei 已提交
199
  required string name = 1;
Y
Yu Yang 已提交
200
  required VarType type = 2;
F
fengjiayi 已提交
201
  optional bool persistable = 3 [ default = false ];
H
Huihuang Zheng 已提交
202 203 204
  // True if the variable is an input data and
  // have to check the feed data shape and dtype
  optional bool need_check_feed = 4 [ default = false ];
205 206
  optional bool is_parameter = 5 [ default = false ];
  optional bool stop_gradient = 6 [ default = false ];
207
  repeated Attr attrs = 7;
Q
qiaolongfei 已提交
208
}
209 210 211 212 213 214

message BlockDesc {
  required int32 idx = 1;
  required int32 parent_idx = 2;
  repeated VarDesc vars = 3;
  repeated OpDesc ops = 4;
Y
Yu Yang 已提交
215
  optional int32 forward_block_idx = 5 [ default = -1 ];
216 217
}

218 219 220 221 222
// In some cases, Paddle may perform operator definition iterations,
// and the operator uses OpVersionMap for compatibility testing.
message OpVersion { required int32 version = 1; }
message OpVersionMap {
  message OpVersionPair {
223
    required string op_name = 1;
224
    required OpVersion op_version = 2;
225
  }
226
  repeated OpVersionPair pair = 1;
227 228
}

Y
Yi Wang 已提交
229 230 231
// Please refer to
// https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/program.md
// for more details.
232 233
// TODO(panyx0718): A model can have multiple programs. Need a
// way to distinguish them. Maybe ID or name?
X
version  
Xin Pan 已提交
234
message ProgramDesc {
235
  reserved 2, 3; // For backward compatibility.
X
version  
Xin Pan 已提交
236
  repeated BlockDesc blocks = 1;
237
  optional Version version = 4;
238
  optional OpVersionMap op_version_map = 5;
X
version  
Xin Pan 已提交
239
}