Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions paddle/fluid/framework/block_desc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ void BlockDesc::RemoveOp(size_t s, size_t e) {
if (ops_.begin() + s == ops_.end() || ops_.begin() + e == ops_.end()) {
return;
}
need_update_ = true;
ops_.erase(ops_.begin() + s, ops_.begin() + e);
}

Expand Down
6 changes: 5 additions & 1 deletion paddle/fluid/framework/program_desc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ BlockDesc *ProgramDesc::AppendBlock(const BlockDesc &parent) {
return blocks_.back().get();
}

proto::ProgramDesc *ProgramDesc::Proto() {
void ProgramDesc::Flush() {
for (auto &block : blocks_) {
block->Flush();
}
}

proto::ProgramDesc *ProgramDesc::Proto() {
Flush();
return &desc_;
}

Expand Down
2 changes: 2 additions & 0 deletions paddle/fluid/framework/program_desc.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class ProgramDesc {

size_t Size() const { return blocks_.size(); }

void Flush();

proto::ProgramDesc *Proto();

// The output variable of feed_op is referenced as feed_target.
Expand Down
1 change: 1 addition & 0 deletions paddle/fluid/pybind/protobuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void BindProgramDesc(pybind11::module *m) {
.def("block", &pd::ProgramDesc::MutableBlock,
pybind11::return_value_policy::reference)
.def("num_blocks", &pd::ProgramDesc::Size)
.def("flush", &pd::ProgramDesc::Flush)
.def("get_feed_target_names", &pd::ProgramDesc::GetFeedTargetNames)
.def("get_fetch_target_names", &pd::ProgramDesc::GetFetchTargetNames)
.def("serialize_to_string", SerializeMessage<pd::ProgramDesc>)
Expand Down
6 changes: 4 additions & 2 deletions python/paddle/fluid/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,20 @@ def save_inference_model(dirname,

if main_program is None:
main_program = default_main_program()
copy_program = main_program

if not os.path.isdir(dirname):
os.makedirs(dirname)

# Clear the is_target information and remove the existed feed and fetch op
global_block = main_program.global_block()
global_block = copy_program.global_block()
for i, op in enumerate(global_block.ops):
op.desc.set_is_target(False)
if op.type == "feed" or op.type == "fetch":
global_block.remove_op(i)
copy_program.desc.flush()

pruned_program = main_program.prune(targets=target_vars)
pruned_program = copy_program.prune(targets=target_vars)
inference_program = pruned_program.inference_optimize()
fetch_var_names = [v.name for v in target_vars]

Expand Down