Skip to content

Need to flush the program desc to update the proto information #10059

@Xreki

Description

@Xreki

In Python api, there are many interfaces to modify the program and block, such as append_op,
insert_op, remove_op, delete_ops, etc. Corresponding C++ functions will be called to update the framework::BlockDescs in framework::ProgramDesc. In these implementations, a member variable need_update_ is set to true, which means the proto::BlockDesc is not consistant with the framework::BlockDesc, which means the need to update before using.

ProgramDesc prog_with_targets(origin);
for (const auto &t : targets) {
prog_with_targets.MutableBlock(t[0])->Op(t[1])->SetIsTarget(true);
}
proto::ProgramDesc pruned_desc;
Prune(*prog_with_targets.Proto(), &pruned_desc);
return new ProgramDesc(pruned_desc);

In above codes, ProgramDesc origin is used to define a new ProgramDesc. If the proto information of origin is not consistant with itself, following error may happen:

*** Aborted at 1524129285 (unix time) try "date -d @1524129285" if you are using GNU date ***
PC: @                0x0 (unknown)
*** SIGSEGV (@0x8) received by PID 28771 (TID 0x7f7dc7bae700) from PID 8; stack trace: ***
    @       0x318b20f500 (unknown)
    @     0x7f7d92eaf6c0 paddle::framework::proto::OpDesc::UnsafeMergeFrom()
    @     0x7f7d92eb081f paddle::framework::proto::BlockDesc::UnsafeMergeFrom()
    @     0x7f7d92eb0bdb paddle::framework::proto::ProgramDesc::UnsafeMergeFrom()
    @     0x7f7d90d83c86 paddle::framework::ProgramDesc::ProgramDesc()
    @     0x7f7d90cf94cb _ZZN8pybind1112cpp_function10initializeIZN6paddle6pybindL13pybind11_initEvEUlRKNS2_9framework11ProgramDescERKSt6vectorISt5arrayImLm2EESaISA_EEE37_PS5_IS7_SE_EINS_4nameENS_5scopeENS_7siblingEEEEvOT_PFT0_DpT1_EDpRKT2_ENUlRNS_6detail13function_callEE1_4_FUNESX_
    @     0x7f7d90d0e81a pybind11::cpp_function::dispatcher()
    @     0x7f7dc84ba649 PyEval_EvalFrameEx
    @     0x7f7dc84bc130 PyEval_EvalCodeEx
    @     0x7f7dc84ba4a1 PyEval_EvalFrameEx
    @     0x7f7dc84bc130 PyEval_EvalCodeEx
    @     0x7f7dc84ba4a1 PyEval_EvalFrameEx
    @     0x7f7dc84bac56 PyEval_EvalFrameEx
    @     0x7f7dc84bac56 PyEval_EvalFrameEx
    @     0x7f7dc84bc130 PyEval_EvalCodeEx
    @     0x7f7dc84bc242 PyEval_EvalCode
    @     0x7f7dc84d662c run_mod
    @     0x7f7dc84d6700 PyRun_FileExFlags
    @     0x7f7dc84d7c0c PyRun_SimpleFileExFlags
    @     0x7f7dc84e94cc Py_Main
    @     0x7f7dc7bd1185 __libc_start_main

Sometimes, after we change the program in Python codes, we need to call flush explicitly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    预测原名Inference,包含Capi预测问题等

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions