TrainerMain.cpp 1.9 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Z
zhangjinchao01 已提交
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. */

#include <fenv.h>
16
#include "paddle/pserver/PServerController.h"
Y
Yu Yang 已提交
17
#include "paddle/utils/Excepts.h"
Z
zhangjinchao01 已提交
18 19 20 21 22
#include "paddle/utils/PythonUtil.h"

#include "ParamUtil.h"
#include "Trainer.h"

23 24 25 26 27 28 29
DEFINE_bool(start_pserver, false, "Whether to start pserver");
DECLARE_int32(gpu_id);
DEFINE_string(job, "train", "one of (train, test, checkgrad)");
DECLARE_int32(start_pass);
DECLARE_string(config);
DECLARE_string(init_model_path);
DECLARE_string(rdma_tcp);
Z
zhangjinchao01 已提交
30 31 32 33

using namespace paddle;  // NOLINT

int main(int argc, char** argv) {
34
  // write logs instantly (never buffer log messages)
Z
zhangjinchao01 已提交
35
  FLAGS_logbuflevel = -1;
36

Z
zhangjinchao01 已提交
37 38 39
  initMain(argc, argv);
  initPython(argc, argv);

40
  std::unique_ptr<PServerController> pServerPtr(nullptr);
Z
zhangjinchao01 已提交
41
  if (FLAGS_start_pserver) {
42
    pServerPtr.reset(paddle::PServerController::createByGflags());
Q
qiaolongfei 已提交
43
    pServerPtr->start();
Z
zhangjinchao01 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57
  }
  Trainer trainer;
  auto config = TrainerConfigHelper::createFromFlags();
  CHECK(config != nullptr) << "no valid config";

  feenableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW);
  trainer.init(config, FLAGS_job == "test");

  if (FLAGS_job == "train") {
    trainer.train();
  } else if (FLAGS_job == "checkgrad") {
    trainer.checkGradient();
  } else if (FLAGS_job == "test") {
    trainer.test();
58 59
  } else if (FLAGS_job == "time") {
    trainer.time();
Z
zhangjinchao01 已提交
60 61 62 63 64 65
  } else {
    LOG(FATAL) << "Unknown job type: " << FLAGS_job;
  }

  return 0;
}