|
|
|
@ -123,7 +123,18 @@ void BindProgramDesc(py::module &m) {
|
|
|
|
|
AppendBackward(program_desc, no_grad_vars);
|
|
|
|
|
})
|
|
|
|
|
.def("block", &ProgramDescBind::Block, py::return_value_policy::reference)
|
|
|
|
|
.def("num_blocks", &ProgramDescBind::Size);
|
|
|
|
|
.def("num_blocks", &ProgramDescBind::Size)
|
|
|
|
|
.def("serialize_to_string",
|
|
|
|
|
[](ProgramDescBind &program_desc) -> py::bytes {
|
|
|
|
|
const ProgramDesc *desc = program_desc.Proto();
|
|
|
|
|
PADDLE_ENFORCE(desc->IsInitialized(),
|
|
|
|
|
"ProgramDesc has not been initialized.");
|
|
|
|
|
std::string res;
|
|
|
|
|
PADDLE_ENFORCE(
|
|
|
|
|
desc->SerializeToString(&res),
|
|
|
|
|
"Serialize ProgramDesc Error. This could be a bug of Paddle.");
|
|
|
|
|
return res;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BindBlockDesc(py::module &m) {
|
|
|
|
@ -149,7 +160,17 @@ void BindBlockDesc(py::module &m) {
|
|
|
|
|
.def("all_vars", &BlockDescBind::AllVars,
|
|
|
|
|
py::return_value_policy::reference)
|
|
|
|
|
.def("all_ops", &BlockDescBind::AllOps,
|
|
|
|
|
py::return_value_policy::reference);
|
|
|
|
|
py::return_value_policy::reference)
|
|
|
|
|
.def("serialize_to_string", [](BlockDescBind &block_desc) -> py::bytes {
|
|
|
|
|
const BlockDesc *desc = block_desc.Proto();
|
|
|
|
|
PADDLE_ENFORCE(desc->IsInitialized(),
|
|
|
|
|
"BlockDesc has not been initialized.");
|
|
|
|
|
std::string res;
|
|
|
|
|
PADDLE_ENFORCE(
|
|
|
|
|
desc->SerializeToString(&res),
|
|
|
|
|
"Serialize BlockDesc Error. This could be a bug of Paddle.");
|
|
|
|
|
return res;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BindVarDsec(py::module &m) {
|
|
|
|
@ -177,7 +198,17 @@ void BindVarDsec(py::module &m) {
|
|
|
|
|
.def("lod_level", &VarDescBind::GetLodLevel)
|
|
|
|
|
.def("set_lod_level", &VarDescBind::SetLoDLevel)
|
|
|
|
|
.def("type", &VarDescBind::GetType)
|
|
|
|
|
.def("set_type", &VarDescBind::SetType);
|
|
|
|
|
.def("set_type", &VarDescBind::SetType)
|
|
|
|
|
.def("serialize_to_string", [](VarDescBind &var_desc) -> py::bytes {
|
|
|
|
|
const VarDesc *desc = var_desc.Proto();
|
|
|
|
|
PADDLE_ENFORCE(desc->IsInitialized(),
|
|
|
|
|
"VarDesc has not been initialized.");
|
|
|
|
|
std::string res;
|
|
|
|
|
PADDLE_ENFORCE(
|
|
|
|
|
desc->SerializeToString(&res),
|
|
|
|
|
"Serialize VarDesc Error. This could be a bug of Paddle.");
|
|
|
|
|
return res;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
py::enum_<VarDesc::VarType>(var_desc, "VarType", "")
|
|
|
|
|
.value("LOD_TENSOR", VarDesc::LOD_TENSOR)
|
|
|
|
@ -213,7 +244,17 @@ void BindOpDesc(py::module &m) {
|
|
|
|
|
.def("set_block_attr", &OpDescBind::SetBlockAttr)
|
|
|
|
|
.def("block_attr", &OpDescBind::GetBlockAttr)
|
|
|
|
|
.def("check_attrs", &OpDescBind::CheckAttrs)
|
|
|
|
|
.def("infer_shape", &OpDescBind::InferShape);
|
|
|
|
|
.def("infer_shape", &OpDescBind::InferShape)
|
|
|
|
|
.def("serialize_to_string", [](OpDescBind &op_desc) -> py::bytes {
|
|
|
|
|
const OpDesc *desc = op_desc.Proto();
|
|
|
|
|
PADDLE_ENFORCE(desc->IsInitialized(),
|
|
|
|
|
"OpDesc has not been initialized.");
|
|
|
|
|
std::string res;
|
|
|
|
|
PADDLE_ENFORCE(
|
|
|
|
|
desc->SerializeToString(&res),
|
|
|
|
|
"Serialize OpDesc Error. This could be a bug of Paddle.");
|
|
|
|
|
return res;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace pybind
|
|
|
|
|