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/ParameterServerController.h"
Z
zhangjinchao01 已提交
17 18 19 20 21
#include "paddle/utils/PythonUtil.h"

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

22 23 24 25 26 27 28
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 已提交
29 30 31 32

using namespace paddle;  // NOLINT

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

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

39
  std::unique_ptr<ParameterServerController> parameterServerPtr(nullptr);
Z
zhangjinchao01 已提交
40
  if (FLAGS_start_pserver) {
41 42 43
    parameterServerPtr.reset(
        paddle::ParameterServerController::createFromGflags());
    parameterServerPtr->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;
}