bind_fleet_executor.cc 3.6 KB
Newer Older
L
LiYuRio 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
//
// 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 "paddle/fluid/pybind/bind_fleet_executor.h"
#include <pybind11/stl.h>
17
#include "paddle/fluid/distributed/fleet_executor/dist_model.h"
L
LiYuRio 已提交
18
#include "paddle/fluid/distributed/fleet_executor/fleet_executor.h"
L
LiYuRio 已提交
19
#include "paddle/fluid/distributed/fleet_executor/task_node.h"
20
#include "paddle/fluid/framework/operator.h"
L
LiYuRio 已提交
21
#include "paddle/fluid/framework/program_desc.h"
22 23
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/platform/place.h"
L
LiYuRio 已提交
24 25 26 27 28 29 30

namespace py = pybind11;

namespace paddle {
namespace pybind {

using paddle::distributed::FleetExecutor;
L
LiYuRio 已提交
31
using paddle::distributed::TaskNode;
32 33
using paddle::distributed::DistModelConfig;
using paddle::distributed::DistModel;
34
using paddle::framework::OpDesc;
35
using paddle::framework::ProgramDesc;
L
LiYuRio 已提交
36 37 38 39 40

void BindFleetExecutor(py::module* m) {
  py::class_<FleetExecutor>(*m, "FleetExecutor")
      .def(py::init<const std::string&>())
      .def("init", &FleetExecutor::Init)
41 42
      .def("run", &FleetExecutor::Run,
           py::call_guard<py::gil_scoped_release>());
L
LiYuRio 已提交
43 44

  py::class_<TaskNode>(*m, "TaskNode")
45
      .def(py::init<framework::ProgramDesc*, int64_t, int64_t, int64_t>())
46 47
      .def(py::init<int32_t, const std::vector<framework::OpDesc*>&, int64_t,
                    int64_t, int64_t, int64_t>())
L
LiYuRio 已提交
48 49
      .def("task_id", &TaskNode::task_id)
      .def("add_upstream_task", &TaskNode::AddUpstreamTask)
50 51 52 53
      .def("add_downstream_task", &TaskNode::AddDownstreamTask)
      .def("set_run_pre_steps", &TaskNode::SetRunPerSteps)
      .def("set_run_at_offset", &TaskNode::SetRunAtOffset)
      .def("set_type", &TaskNode::SetType)
54 55 56
      .def("role", &TaskNode::role)
      .def("init", &TaskNode::Init)
      .def("set_program", &TaskNode::SetProgram);
57 58 59 60

  py::class_<DistModelConfig>(*m, "DistModelConfig")
      .def(py::init<>())
      .def_readwrite("model_dir", &DistModelConfig::model_dir)
61 62 63 64
      .def_readwrite("program_desc", &DistModelConfig::program_desc)
      .def_readwrite("scope", &DistModelConfig::scope)
      .def_readwrite("place", &DistModelConfig::place)
      .def_readwrite("device_id", &DistModelConfig::device_id)
65 66 67 68 69
      .def_readwrite("trainer_endpoints", &DistModelConfig::trainer_endpoints)
      .def_readwrite("current_endpoint", &DistModelConfig::current_endpoint)
      .def_readwrite("nranks", &DistModelConfig::nranks)
      .def_readwrite("local_rank", &DistModelConfig::local_rank)
      .def_readwrite("mp_degree", &DistModelConfig::mp_degree)
70 71 72 73 74 75
      .def_readwrite("pp_degree", &DistModelConfig::pp_degree)
      .def_readwrite("mp_ring_id", &DistModelConfig::mp_ring_id)
      .def_readwrite("pp_upstream_ring_id",
                     &DistModelConfig::pp_upstream_ring_id)
      .def_readwrite("pp_downstream_ring_id",
                     &DistModelConfig::pp_downstream_ring_id);
76 77 78 79 80

  py::class_<DistModel>(*m, "DistModel")
      .def(py::init<const DistModelConfig&>())
      .def("init", &DistModel::Init)
      .def("run", &DistModel::Run, py::call_guard<py::gil_scoped_release>());
L
LiYuRio 已提交
81 82 83
}
}  // namespace pybind
}  // namespace paddle