framework.proto 4.6 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";
Y
Yu Yang 已提交
16
option optimize_for = LITE_RUNTIME;
17
package paddle.framework.proto;
Y
Yi Wang 已提交
18 19 20 21 22 23 24 25

enum AttrType {
  INT = 0;
  FLOAT = 1;
  STRING = 2;
  INTS = 3;
  FLOATS = 4;
  STRINGS = 5;
Y
Yu Yang 已提交
26 27 28
  BOOLEAN = 6;
  BOOLEANS = 7;
  BLOCK = 8;
29
  LONG = 9;
Y
Yi Wang 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
}

// 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;
    optional float f = 4;
    optional string s = 5;
    repeated int32 ints = 6;
    repeated float floats = 7;
    repeated string strings = 8;
D
dangqingqing 已提交
45
    optional bool b = 10;
46
    repeated bool bools = 11;
D
dangqingqing 已提交
47
    optional int32 block_idx = 12;
48
    optional int64 l = 13;
Y
Yi Wang 已提交
49 50 51
  };

  message Var {
52 53
    required string parameter = 1;
    repeated string arguments = 2;
Y
Yi Wang 已提交
54 55 56 57 58 59
  };

  required string type = 3;
  repeated Var inputs = 1;
  repeated Var outputs = 2;
  repeated Attr attrs = 4;
Y
Yang Yang 已提交
60
  optional bool is_target = 5 [ default = false ];
Y
Yi Wang 已提交
61 62 63 64 65 66 67 68 69
};

// 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 已提交
70

Y
Yi Wang 已提交
71 72
    optional bool duplicable = 3 [ default = false ];
    optional bool intermediate = 4 [ default = false ];
Y
Yang Yang 已提交
73
    optional bool dispensable = 5 [ default = false ];
74
    optional string reuse = 6;
Y
Yi Wang 已提交
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  }

  // 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 ];
  }

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

95 96
message VarType {
  enum Type {
97 98 99 100 101 102 103 104
    // Pod Types
    BOOL = 0;
    INT16 = 1;
    INT32 = 2;
    INT64 = 3;
    FP16 = 4;
    FP32 = 5;
    FP64 = 6;
Y
yuyang18 已提交
105 106
    // Tensor<size_t> is used in C++.
    SIZE_T = 19;
Y
yuyang18 已提交
107
    UINT8 = 20;
108 109 110 111 112 113 114 115 116 117 118

    // 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;
119
    CHANNEL = 16;
T
typhoonzero 已提交
120 121
    // Any runtime decided variable type is raw
    // raw variables should manage their own allocations
T
typhoonzero 已提交
122
    // in operators like nccl_op
T
typhoonzero 已提交
123
    RAW = 17;
C
chengduo 已提交
124
    TUPLE = 18;
Y
Yu Yang 已提交
125
  }
126 127 128 129

  required Type type = 1;

  message TensorDesc {
130 131
    // Should only be PODType. Is enforced in C++
    required Type data_type = 1;
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    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;
150 151 152 153 154 155

  message ChannelDesc {
    required Type data_type = 1;
    required int64 capacity = 2;
  }
  optional ChannelDesc channel = 6;
C
chengduo 已提交
156 157 158

  message Tuple { repeated Type element_type = 1; }
  optional Tuple tuple = 7;
159 160 161
}

message VarDesc {
Q
qiaolongfei 已提交
162
  required string name = 1;
Y
Yu Yang 已提交
163
  required VarType type = 2;
F
fengjiayi 已提交
164
  optional bool persistable = 3 [ default = false ];
Q
qiaolongfei 已提交
165
}
166 167 168 169 170 171

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

Y
Yi Wang 已提交
175 176 177
// Please refer to
// https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/program.md
// for more details.
178 179
// TODO(panyx0718): A model can have multiple programs. Need a
// way to distinguish them. Maybe ID or name?
180
message ProgramDesc { repeated BlockDesc blocks = 1; }