ParameterService.proto 8.5 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
Z
zhangjinchao01 已提交
2 3 4 5 6 7 8 9 10 11 12 13

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. */
Y
Yu Yang 已提交
14
syntax = "proto2";
Z
zhangjinchao01 已提交
15 16 17 18 19 20 21 22 23 24 25

import "ParameterConfig.proto";
import "TrainerConfig.proto";

package paddle;

/**
 * Various structs for communicating with parameter server
 */
enum ParameterUpdateMode {
  // Set parameter
L
liaogang 已提交
26 27
  PSERVER_UPDATE_MODE_SET_PARAM = 0;      // use local param
  PSERVER_UPDATE_MODE_SET_PARAM_ZERO = 1; // set zero param
Z
zhangjinchao01 已提交
28 29 30 31 32 33 34 35 36 37 38 39

  // Update parameter once a gradient is received
  PSERVER_UPDATE_MODE_ASYNC_SGD = 2;

  // Accumulate gradient
  PSERVER_UPDATE_MODE_ADD_GRADIENT = 3;

  // Average parameters
  PSERVER_UPDATE_MODE_AVERAGE_PARAMETER = 4;

  // No update. Only get parameters back.
  PSERVER_UPDATE_MODE_GET_PARAM = 5;
L
liaogang 已提交
40
  PSERVER_UPDATE_MODE_GET_PARAM_SPARSE = 6; // only get sparse rows
Z
zhangjinchao01 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
};

message ParameterBlock {
  // it accurately means parameter id.
  required uint64 para_id = 1;
  // global sparse row or dense block for each block in parameter
  required uint64 block_id = 2;
  // offset in (local) storage
  required uint64 begin_pos = 3;
  // actual size of block, size for last block is [endDim -beginDim],
  // others is parameter_block_size in ParameterConfig
  required uint64 block_size = 4;
}

enum PServerStatus {
  PSERVER_STATUS_NOT_SET = 0;
  PSERVER_STATUS_PARAMETER_READY = 1;
};

enum BatchStatus {
  BATCH_START = 0;
  BATCH_ON = 1;
  BATCH_FINISH = 2;
  BATCH_START_AND_FINISH = 3;
};

message SendParameterRequest {
  required ParameterUpdateMode update_mode = 1;
  repeated ParameterBlock blocks = 2;
  required bool send_back_parameter = 3;

  // number of samples used for calculating this update
  optional int64 num_samples = 4;

  // cost will be used to calculate global objective value
Y
Yu Yang 已提交
76
  optional double cost = 5;
Z
zhangjinchao01 已提交
77 78 79 80 81 82

  required BatchStatus batch_status = 6;

  optional int32 trainer_id = 7;

  // send back parameter type on pserver, PARAMETER_VALUE by default
L
liaogang 已提交
83
  optional int32 send_back_parameter_type = 8 [ default = 0 ];
Z
zhangjinchao01 已提交
84 85 86 87 88

  // forwardbackward time in usec
  optional uint64 forwardbackward_time = 9;
}

L
liaogang 已提交
89
message WaitPassStartRequest {}
Z
zhangjinchao01 已提交
90

L
liaogang 已提交
91
message WaitPassStartResponse {}
Z
zhangjinchao01 已提交
92

L
liaogang 已提交
93
message WaitPassFinishRequest {}
Z
zhangjinchao01 已提交
94

L
liaogang 已提交
95
message WaitPassFinishResponse {}
Z
zhangjinchao01 已提交
96 97 98

enum SyncObject {
  SYNC_DEFAULT = 0; // wait for the synchronizeBarrier_
L
liaogang 已提交
99
  SYNC_DATA = 1;    // wait for the synchronizeDataBarrier_
Z
zhangjinchao01 已提交
100 101 102
}

message SynchronizeRequest {
L
liaogang 已提交
103
  required SyncObject sync_object_id = 1 [ default = SYNC_DEFAULT ];
Z
zhangjinchao01 已提交
104 105 106 107

  optional int32 trainer_id = 2;
}

L
liaogang 已提交
108
message SynchronizeResponse {}
Z
zhangjinchao01 已提交
109

L
liaogang 已提交
110
message SendParameterResponse { repeated ParameterBlock blocks = 1; }
Z
zhangjinchao01 已提交
111 112 113 114 115 116 117 118 119

message SetConfigRequest {
  repeated ParameterConfig param_configs = 1;
  required OptimizationConfig opt_config = 2;
  required string save_dir = 4;
  required int32 server_id = 5;
  required bool is_sparse_server = 6;
}

L
liaogang 已提交
120
message SetConfigResponse {}
Z
zhangjinchao01 已提交
121

L
liaogang 已提交
122
message GetStatusRequest {}
Z
zhangjinchao01 已提交
123

L
liaogang 已提交
124
message GetStatusResponse { required PServerStatus status = 1; }
Z
zhangjinchao01 已提交
125

L
liaogang 已提交
126
message SetStatusRequest { required PServerStatus status = 1; }
Z
zhangjinchao01 已提交
127

L
liaogang 已提交
128
message SetStatusResponse {}
Z
zhangjinchao01 已提交
129 130

// create a column vector. The size is the dimension of parameter
L
liaogang 已提交
131
message CreateVectorRequest {}
Z
zhangjinchao01 已提交
132 133 134 135 136 137 138 139

message CreateVectorResponse {
  // error message. Empty if success
  optional string return_message = 1;

  required int64 handle = 2;
}

L
liaogang 已提交
140
message ReleaseVectorRequest { required int64 handle = 1; }
Z
zhangjinchao01 已提交
141 142 143 144 145 146 147 148

message ReleaseVectorResponse {
  // error message. Empty if success
  optional string return_message = 1;
}

// Create a column major matrix. The number of rows is the dimension
// of parameter. The number of columns is specifed by num_cols
L
liaogang 已提交
149
message CreateMatrixRequest { required int32 num_cols = 1; }
Z
zhangjinchao01 已提交
150 151 152 153 154 155 156 157

message CreateMatrixResponse {
  // error message. Empty if success
  optional string return_message = 1;

  required int64 handle = 2;
}

L
liaogang 已提交
158
message ReleaseMatrixRequest { required int64 handle = 1; }
Z
zhangjinchao01 已提交
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224

message ReleaseMatrixResponse {
  // error message. Empty if success
  optional string return_message = 1;
}

/**
 * The operations are defined using the variables commented at Operation
 * and OperationResult
 */
enum MatrixVectorOperation {
  // r = u^T u
  PSERVER_OP_utu = 0;

  // r = u^T v
  PSERVER_OP_utv = 1;

  // u = a u
  PSERVER_OP_au = 2;

  // v = a u + b v
  PSERVER_OP_au_bv = 3;

  // u = a A x + b u
  PSERVER_OP_aAx_bu = 4;

  // Stochastic gradient update
  PSERVER_OP_SGD = 5;

  // u = a
  PSERVER_OP_RESET = 6;

  // v = u
  PSERVER_OP_COPY = 7;

  // w = a u + b v + c w
  PSERVER_OP_au_bv_cw = 8;

  // owlqn: MakeSteepestDescDir
  PSERVER_OP_MAKE_STEEPEST_DESC_DIR = 9;

  // owlqn: FixDirSigns
  PSERVER_OP_FIX_DIR_SIGNS = 10;

  // owlqn: DirDeriv
  PSERVER_OP_DIR_DERIV = 11;

  // owlqn: FixOmegaSigns
  PSERVER_OP_FIX_OMEGA_SIGNS = 12;

  // Get overall cost
  PSERVER_OP_COST = 13;

  // Pass control
  PSERVER_OP_START_PASS = 14;
  PSERVER_OP_FINISH_PASS = 15;

  // randomize value
  PSERVER_OP_RANDOMIZE = 16;

  // call optimizer apply
  PSERVER_OP_APPLY = 17;
}

message ProtoVector {
  required int64 dim = 1;
L
liaogang 已提交
225
  repeated double values = 2 [ packed = true ];
Z
zhangjinchao01 已提交
226 227 228 229 230
}

message ProtoMatrix {
  required int64 num_rows = 1;
  required int64 num_cols = 2;
L
liaogang 已提交
231
  repeated double values = 3 [ packed = true ];
Z
zhangjinchao01 已提交
232 233 234 235 236 237
}

message Operation {
  required MatrixVectorOperation operation = 1;

  // vector handles created on the pserver
L
liaogang 已提交
238
  repeated int64 pvectors = 2; // u, v, w
Z
zhangjinchao01 已提交
239 240

  // matrix handles created on the pserver
L
liaogang 已提交
241
  repeated int64 pmatrices = 3; // A, B, C
Z
zhangjinchao01 已提交
242

L
liaogang 已提交
243 244 245
  repeated double scalars = 4;       // a, b, c
  repeated ProtoVector vectors = 5;  // x, y, z
  repeated ProtoMatrix matrices = 6; // X, Y, Z
Z
zhangjinchao01 已提交
246 247 248 249 250
}

message OperationResult {
  // error message. Empty if success
  optional string return_message = 1;
L
liaogang 已提交
251 252
  //
  repeated double scalars = 2;       // d, e, f
Z
zhangjinchao01 已提交
253
  repeated ProtoVector vectors = 3;  // p, q, r
L
liaogang 已提交
254
  repeated ProtoMatrix matrices = 4; // P, Q, R
Z
zhangjinchao01 已提交
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
}

message DoOperationRequest {
  repeated Operation operations = 1;

  // If true, wait for gradient to be ready before starting the operations
  required bool wait_for_gradient = 2;

  // If true, send back the parameter to clients after the operations are
  // finished
  required bool send_back_parameter = 3;

  // If true, and if all clients call waitPassFinish,
  // signal all clients finish the pass
  required bool release_pass = 4;
}

message DoOperationResponse {
  // error message. Empty if success
  optional string return_message = 1;

  repeated OperationResult results = 2;

  required bool pass_finish = 3;
}

L
liaogang 已提交
281
message LoadValueRequest { required string dir_name = 1; }
Z
zhangjinchao01 已提交
282 283 284 285 286 287

message LoadValueResponse {
  // error message. Empty if success
  optional string return_message = 1;
}

L
liaogang 已提交
288
message SaveValueRequest { required string dir_name = 1; }
Z
zhangjinchao01 已提交
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306

message SaveValueResponse {
  // error message. Empty if success
  optional string return_message = 1;
}

enum DataUpdateMode {
  // Client send it's own data to pserver
  DATA_UPDATE_MODE_SET_OWN = 0;
  // Client get all user data from all pservers
  DATA_UPDATE_MODE_GET_ALL = 1;
  // Client send it's own ref feature to pserver
  DATA_UPDATE_MODE_SET_REF = 2;
  // Client get all ref featuers from all pservers
  DATA_UPDATE_MODE_GET_REF = 3;
  // Client send it's own ref label to pserver
  DATA_UPDATE_MODE_SET_REF_LABEL = 4;
  // Client get all ref labels from all pservers
L
liaogang 已提交
307
  DATA_UPDATE_MODE_GET_REF_LABEL = 5;
Z
zhangjinchao01 已提交
308
  // Client send it's own ref grad to pserver
L
liaogang 已提交
309
  DATA_UPDATE_MODE_SET_REF_GRAD = 6;
Z
zhangjinchao01 已提交
310
  // Client get all ref grad from all pservers
L
liaogang 已提交
311
  DATA_UPDATE_MODE_GET_REF_GRAD = 7;
Z
zhangjinchao01 已提交
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
}

enum SendDataType {
  DATA_REF = 0;
  DATA_REFLABEL = 1;
  DATA_REFGRAD = 2;
  DATA_REDUCE_SUM = 3;
}

enum TransDataType {
  TRANS_INT32 = 0;
  TRANS_UINT32_T = 1;
  TRANS_INT64_T = 2;
  TRANS_UINT64_T = 3;
  TRANS_FLOAT = 5;
  TRANS_DOUBLE = 6;
}

message DataBlock {
  // total byte size of this data blcok
  required uint64 total_size = 1;
  // byte size of one data type
  required int32 data_size = 2;
  // data_type
L
liaogang 已提交
336
  optional TransDataType data_type = 3 [ default = TRANS_DOUBLE ];
Z
zhangjinchao01 已提交
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
}

message SendDataRequest {
  required SendDataType type = 1;
  required DataUpdateMode update_mode = 2;
  repeated DataBlock blocks = 3;
  required uint64 client_id = 4;
  required uint64 server_id = 5;
}

message SendDataResponse {
  required SendDataType type = 1;
  repeated DataBlock blocks = 2;
  required uint64 server_id = 3;
}